Log pipeline update errors using progress logger (#338)

## Changes
Logs error message for all exceptions

## Tests
Manually and using unit tests
This commit is contained in:
shreyas-goenka 2023-04-18 15:00:34 +02:00 committed by GitHub
parent 59eee11989
commit d0872b45e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -13,7 +13,6 @@ type ProgressEvent pipelines.PipelineEvent
func (event *ProgressEvent) String() string {
result := strings.Builder{}
result.WriteString(event.Timestamp + " ")
// Print event type with some padding to make output more pretty
@ -22,6 +21,12 @@ func (event *ProgressEvent) String() string {
result.WriteString(event.Level.String() + " ")
result.WriteString(fmt.Sprintf(`"%s"`, event.Message))
// construct error string
if event.Error != nil {
for _, exception := range event.Error.Exceptions {
result.WriteString(fmt.Sprintf("\n%s", exception.Message))
}
}
return result.String()
}

View File

@ -19,7 +19,7 @@ func NewPipelineUpdateUrlEvent(host, updateId, pipelineId string) *PipelineUpdat
}
func (event *PipelineUpdateUrlEvent) String() string {
return fmt.Sprintf("The pipeline update can be found at %s\n", event.Url)
return fmt.Sprintf("Update URL: %s\n", event.Url)
}
func (event *PipelineUpdateUrlEvent) IsInplaceSupported() bool {

View File

@ -34,3 +34,24 @@ func TestUpdateProgressEventToString(t *testing.T) {
}
assert.Equal(t, `2023-03-27T23:30:36.122Z update_progress ERROR "my_message"`, event.String())
}
func TestUpdateErrorEventToString(t *testing.T) {
event := ProgressEvent{
EventType: "update_progress",
Message: "failed to update pipeline",
Level: pipelines.EventLevelError,
Origin: &pipelines.Origin{
FlowName: "my_flow",
PipelineName: "my_pipeline",
},
Timestamp: "2023-03-27T23:30:36.122Z",
Error: &pipelines.ErrorDetail{
Exceptions: []pipelines.SerializedException{
{
Message: "parsing error",
},
},
},
}
assert.Equal(t, "2023-03-27T23:30:36.122Z update_progress ERROR \"failed to update pipeline\"\nparsing error", event.String())
}