Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
fix: Sending error logs to all registered jes instances in uniform (#334
Browse files Browse the repository at this point in the history
)

Signed-off-by: Raphael Ludwig <raphael.ludwig@dynatrace.com>
  • Loading branch information
Raffy23 authored Jul 25, 2022
1 parent 8a9bcbd commit 17ee4e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
27 changes: 13 additions & 14 deletions pkg/keptn/errorlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,27 @@ func (els *ErrorLogSender) SendErrorLogEvent(initialCloudEvent *cloudevents.Even
return fmt.Errorf("error retrieving uniform registrations: %w", err)
}

var integrationID string
sendEvent := false
for _, registration := range registrations {
if registration.Name == els.integrationName {
if integrationID != "" {
return fmt.Errorf("found multiple uniform registrations with name %s", els.integrationName)
errorCloudEvent, err := createErrorLogCloudEvent(registration.ID, initialCloudEvent, applicationError)
if err != nil {
log.Printf("unable to create error log cloudevent %+v: %+v", initialCloudEvent, err)
continue
}
integrationID = registration.ID
}
}

if integrationID == "" {
return fmt.Errorf("no registration found with name %s", els.integrationName)
err = els.ceSender.SendCloudEvent(errorCloudEvent)
if err == nil {
sendEvent = true
}
}
}

errorCloudEvent, err := createErrorLogCloudEvent(integrationID, initialCloudEvent, applicationError)
if err != nil {
return fmt.Errorf("unable to create error log cloudevent: %w", err)
if sendEvent {
return nil
}

els.ceSender.SendCloudEvent(errorCloudEvent)

return nil
return fmt.Errorf("no registration found with name %s", els.integrationName)
}

func createErrorLogCloudEvent(
Expand Down
8 changes: 5 additions & 3 deletions pkg/keptn/errorlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@ func TestErrorWhenMultipleMatchingRegistrationReturned(t *testing.T) {
).Times(1)

mockCloudEventSender := fake.NewMockCloudEventSender(ctrl)
mockCloudEventSender.EXPECT().SendCloudEvent(gomock.Any()).Times(2).Return(nil)

sut := NewErrorLogSender("foobar", uniformClient, mockCloudEventSender)

newEvent := cloudevents.NewEvent()
err := sut.SendErrorLogEvent(&newEvent, errors.New("some error"))
newEvent.SetExtension("shkeptncontext", "034579438ufj-958340958")

assert.Error(t, err)
assert.ErrorContains(t, err, "found multiple uniform registrations with name foobar")
err := sut.SendErrorLogEvent(&newEvent, errors.New("some error"))
assert.NoError(t, err)
}

func TestSendErrorLogHappyPath(t *testing.T) {
Expand Down

0 comments on commit 17ee4e2

Please sign in to comment.