Skip to content

Commit

Permalink
fix(3234): Always merge parent event meta last (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyi authored Oct 30, 2024
1 parent 8e928b6 commit a875f1a
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 10 deletions.
5 changes: 4 additions & 1 deletion launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,10 @@ func launch(api screwdriver.API, buildID int, rootDir, emitterPath, metaSpace, s
}

metaLog = fmt.Sprintf(`Build(%v)`, parentBuildIDs[0])
} else if event.ParentEventID != 0 { // If has parent event, fetch meta from parent event
}

// Always merge parent event meta if it exists (Issue #3234)
if event.ParentEventID != 0 { // If has parent event, fetch meta from parent event
log.Printf("Fetching Parent Event %d", event.ParentEventID)
parentEvent, err := api.EventFromID(event.ParentEventID)
if err != nil {
Expand Down
109 changes: 100 additions & 9 deletions launch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,9 @@ func TestFetchParentBuildMetaWriteError(t *testing.T) {
}
return screwdriver.Pipeline(FakePipeline{ID: pipelineID, ScmURI: TestScmURI, ScmRepo: TestScmRepo}), nil
}
api.eventFromID = func(eventID int) (screwdriver.Event, error) {
return screwdriver.Event(FakeEvent{ID: TestEventID}), nil
}
writeFile = func(path string, data []byte, perm os.FileMode) (err error) {
return fmt.Errorf("Testing writing parent build meta")
}
Expand Down Expand Up @@ -1804,6 +1807,7 @@ func TestMetaWhenTriggeredFromPipelinesByANDLogicWithParentBuildMeta(t *testing.
"build_only": "build_value", // Remain
"build_and_event_and_inner_pipeline": "build_value", // Remain
"build_and_event_and_external_pipeline": "build_value", // Remain
"build_and_event_and_parent_event": "build_value", // Remain
},
"meta": map[string]interface{}{
"summary": map[string]string{ // This should be deleted
Expand Down Expand Up @@ -1890,6 +1894,38 @@ func TestMetaWhenTriggeredFromPipelinesByANDLogicWithParentBuildMeta(t *testing.
},
}

parentEventMeta := map[string]interface{}{
"parent_event_only": "parent_event_value", // Remain
"build_and_event_and_parent_event": "parent_event_value", // Remain
"parameters": map[string]string{
"parent_event_only": "parent_event_value", // This should be deleted
"build_and_event_and_parent_event": "parent_event_value", // Overwrote by build
},
"meta": map[string]interface{}{
"summary": map[string]string{ // This should be deleted
"parent_event_only": "parent_event_value",
"build_and_event_and_parent_event": "parent_event_value",
},
"parent_event_only": "parent_event_value", // Remain
"build_and_event_and_parent_event": "parent_event_value", // Remain
},
"build": map[string]interface{}{
"buildId": "parent_event_value", // Overwrote by default value
"jobId": "parent_event_value", // Overwrote by default value
"eventId": "parent_event_value", // Overwrote by default value
"pipelineId": "parent_event_value", // Overwrote by default value
"sha": "parent_event_value", // Overwrote by default value
"jobName": "parent_event_value", // Overwrote by default value
"coverageKey": "parent_event_value", // Overwrote by default value
"parent_event_only": "parent_event_value", // Remain
"build_and_event_and_parent_event": "parent_event_value", // Remain
"warning": "parent_event_value", // Removed from merged meta
},
"event": map[string]interface{}{
"creator": "parent_event_value", // Overwrote by default value
},
}

innerParentBuildMeta := map[string]interface{}{
"inner_pipeline_only": "inner_pipeline_value", // Remain
"build_and_event_and_inner_pipeline": "inner_pipeline_value", // Remain
Expand Down Expand Up @@ -2001,6 +2037,11 @@ func TestMetaWhenTriggeredFromPipelinesByANDLogicWithParentBuildMeta(t *testing.
return screwdriver.Job(FakeJob{ID: jobID, PipelineID: InnerPipelineID, Name: "main"}), nil
}
api.eventFromID = func(eventID int) (screwdriver.Event, error) {
if eventID == TestParentEventID {
// parent event
return screwdriver.Event(FakeEvent{ID: TestParentEventID, Meta: parentEventMeta}), nil
}

return screwdriver.Event(FakeEvent{ID: TestEventID, ParentEventID: TestParentEventID, Meta: eventFromIDMeta, Creator: TestEventCreator}), nil
}
api.pipelineFromID = func(pipelineID int) (screwdriver.Pipeline, error) {
Expand All @@ -2024,6 +2065,8 @@ func TestMetaWhenTriggeredFromPipelinesByANDLogicWithParentBuildMeta(t *testing.
"inner_pipeline_only": "inner_pipeline_value",
"build_and_event_and_inner_pipeline": "inner_pipeline_value",
"build_and_event_and_external_pipeline": "external_pipeline_value",
"build_and_event_and_parent_event": "parent_event_value",
"parent_event_only": "parent_event_value",
"build":{
"buildId": "%d",
"jobId": "%d",
Expand All @@ -2037,7 +2080,9 @@ func TestMetaWhenTriggeredFromPipelinesByANDLogicWithParentBuildMeta(t *testing.
"inner_pipeline_only": "inner_pipeline_value",
"external_pipeline_only": "external_pipeline_value",
"build_and_event_and_inner_pipeline": "inner_pipeline_value",
"build_and_event_and_external_pipeline": "external_pipeline_value"
"build_and_event_and_external_pipeline": "external_pipeline_value",
"build_and_event_and_parent_event": "parent_event_value",
"parent_event_only": "parent_event_value"
},
"event": {
"creator": "%s"
Expand All @@ -2048,12 +2093,15 @@ func TestMetaWhenTriggeredFromPipelinesByANDLogicWithParentBuildMeta(t *testing.
"external_pipeline_only": "external_pipeline_value",
"inner_pipeline_only": "inner_pipeline_value",
"build_and_event_and_inner_pipeline": "inner_pipeline_value",
"build_and_event_and_external_pipeline": "external_pipeline_value"
"build_and_event_and_external_pipeline": "external_pipeline_value",
"build_and_event_and_parent_event": "parent_event_value",
"parent_event_only": "parent_event_value"
},
"parameters": {
"build_only": "build_value",
"build_and_event_and_inner_pipeline": "build_value",
"build_and_event_and_external_pipeline": "build_value"
"build_and_event_and_external_pipeline": "build_value",
"build_and_event_and_parent_event": "build_value"
},
"sd": {
"build_only": "build_value",
Expand Down Expand Up @@ -2226,7 +2274,7 @@ func TestMetaWhenTriggeredFromInnerPipelineByORLogicWithParentBuildMeta(t *testi
"build_only": "build_value",
"event_only": "event_value",
"inner_pipeline_only": "inner_pipeline_value",
"build_and_event_and_inner_pipeline": "inner_pipeline_value",
"build_and_event_and_inner_pipeline": "event_value",
"build":{
"buildId": "%d",
"jobId": "%d",
Expand All @@ -2238,7 +2286,7 @@ func TestMetaWhenTriggeredFromInnerPipelineByORLogicWithParentBuildMeta(t *testi
"build_only": "build_value",
"event_only": "event_value",
"inner_pipeline_only": "inner_pipeline_value",
"build_and_event_and_inner_pipeline": "inner_pipeline_value"
"build_and_event_and_inner_pipeline": "event_value"
},
"event": {
"creator": "%s"
Expand All @@ -2247,7 +2295,7 @@ func TestMetaWhenTriggeredFromInnerPipelineByORLogicWithParentBuildMeta(t *testi
"build_only": "build_value",
"event_only": "event_value",
"inner_pipeline_only": "inner_pipeline_value",
"build_and_event_and_inner_pipeline": "inner_pipeline_value"
"build_and_event_and_inner_pipeline": "event_value"
},
"parameters": {
"build_only": "build_value",
Expand Down Expand Up @@ -2348,6 +2396,38 @@ func TestMetaWhenTriggeredFromExternalPipelineByORLogicWithParentBuildMeta(t *te
},
}

parentEventMeta := map[string]interface{}{
"parent_event_only": "parent_event_value", // Remain
"build_and_event_and_parent_event": "parent_event_value", // Remain
"parameters": map[string]string{
"parent_event_only": "parent_event_value", // This should be deleted
"build_and_event_and_parent_event": "parent_event_value", // Overwrote by build
},
"meta": map[string]interface{}{
"summary": map[string]string{ // This should be deleted
"parent_event_only": "parent_event_value",
"build_and_event_and_parent_event": "parent_event_value",
},
"parent_event_only": "parent_event_value", // Remain
"build_and_event_and_parent_event": "parent_event_value", // Remain
},
"build": map[string]interface{}{
"buildId": "parent_event_value", // Overwrote by default value
"jobId": "parent_event_value", // Overwrote by default value
"eventId": "parent_event_value", // Overwrote by default value
"pipelineId": "parent_event_value", // Overwrote by default value
"sha": "parent_event_value", // Overwrote by default value
"jobName": "parent_event_value", // Overwrote by default value
"coverageKey": "parent_event_value", // Overwrote by default value
"parent_event_only": "parent_event_value", // Remain
"build_and_event_and_parent_event": "parent_event_value", // Remain
"warning": "parent_event_value", // Removed from merged meta
},
"event": map[string]interface{}{
"creator": "parent_event_value", // Overwrote by default value
},
}

externalParentBuildMeta := map[string]interface{}{
"external_pipeline_only": "external_pipeline_value", // This should be deleted
"build_and_event_and_external_pipeline": "external_pipeline_value", // Overwrote by event
Expand Down Expand Up @@ -2407,6 +2487,11 @@ func TestMetaWhenTriggeredFromExternalPipelineByORLogicWithParentBuildMeta(t *te
return screwdriver.Job(FakeJob{ID: jobID, PipelineID: InnerPipelineID, Name: "main"}), nil
}
api.eventFromID = func(eventID int) (screwdriver.Event, error) {
if eventID == TestParentEventID {
// parent event
return screwdriver.Event(FakeEvent{ID: TestParentEventID, Meta: parentEventMeta}), nil
}

return screwdriver.Event(FakeEvent{ID: TestEventID, ParentEventID: TestParentEventID, Meta: eventFromIDMeta, Creator: TestEventCreator}), nil
}
api.pipelineFromID = func(pipelineID int) (screwdriver.Pipeline, error) {
Expand All @@ -2427,6 +2512,8 @@ func TestMetaWhenTriggeredFromExternalPipelineByORLogicWithParentBuildMeta(t *te
"build_only": "build_value",
"event_only": "event_value",
"build_and_event_and_external_pipeline": "event_value",
"build_and_event_and_parent_event": "parent_event_value",
"parent_event_only": "parent_event_value",
"build":{
"buildId": "%d",
"jobId": "%d",
Expand All @@ -2437,15 +2524,19 @@ func TestMetaWhenTriggeredFromExternalPipelineByORLogicWithParentBuildMeta(t *te
"coverageKey": "%s",
"build_only": "build_value",
"event_only": "event_value",
"build_and_event_and_external_pipeline": "event_value"
"build_and_event_and_external_pipeline": "event_value",
"build_and_event_and_parent_event": "parent_event_value",
"parent_event_only": "parent_event_value"
},
"event": {
"creator": "%s"
},
"meta": {
"build_only": "build_value",
"event_only": "event_value",
"build_and_event_and_external_pipeline": "event_value"
"build_and_event_and_external_pipeline": "event_value",
"build_and_event_and_parent_event": "parent_event_value",
"parent_event_only": "parent_event_value"
},
"parameters": {
"build_only": "build_value",
Expand Down Expand Up @@ -2580,7 +2671,7 @@ func TestMetaWhenStartFromAnyJobWithParentEvent(t *testing.T) {
api.eventFromID = func(eventID int) (screwdriver.Event, error) {
if eventID == TestParentEventID {
// parent event
return screwdriver.Event(FakeEvent{ID: TestEventID, Meta: parentEventMeta}), nil
return screwdriver.Event(FakeEvent{ID: TestParentEventID, Meta: parentEventMeta}), nil
}
return screwdriver.Event(FakeEvent{ID: TestEventID, ParentEventID: TestParentEventID, Meta: eventFromIDMeta, Creator: TestEventCreator}), nil
}
Expand Down

0 comments on commit a875f1a

Please sign in to comment.