Skip to content

Commit

Permalink
fix(3234): always allow parent event metadata to be merged during the…
Browse files Browse the repository at this point in the history
… build (#480)

* event and parentEvent meta should be mutually exclusive

* allow parent event meta to be the predecessor
  • Loading branch information
VonnyJap authored Nov 12, 2024
1 parent 164b76d commit 1caef0a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
23 changes: 12 additions & 11 deletions launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,17 +474,8 @@ func launch(api screwdriver.API, buildID int, rootDir, emitterPath, metaSpace, s
return err, "", ""
}

// Note: Event and parent event meta are mutually exclusive.
// The first build in the event for a restart case will use the parent event meta.
// On launcher exit, the build meta will be merged into the current event meta.

// merge event meta if available
if len(event.Meta) > 0 {
log.Printf("Fetching Event Meta JSON %v", event.ID)
if event.Meta != nil {
mergedMeta = deepMergeJSON(mergedMeta, event.Meta)
}
} else if event.ParentEventID != 0 {
// Always merge parent event meta if available
if event.ParentEventID != 0 {
log.Printf("Fetching Parent Event %d", event.ParentEventID)
parentEvent, err := api.EventFromID(event.ParentEventID)
if err != nil {
Expand All @@ -498,6 +489,16 @@ func launch(api screwdriver.API, buildID int, rootDir, emitterPath, metaSpace, s
metaLog = fmt.Sprintf(`Event(%v)`, parentEvent.ID)
}

// merge event meta if available
// the parent event's metadata should be overwritten if a conflict occurs
// meaning if the event has been updated with newer metadata from its associated builds.
if len(event.Meta) > 0 {
log.Printf("Fetching Event Meta JSON %v", event.ID)
if event.Meta != nil {
mergedMeta = deepMergeJSON(mergedMeta, event.Meta)
}
}

if len(parentBuildIDs) > 1 { // If has multiple parent build IDs, merge their metadata (join case)
// Get meta from all parent builds
for _, pbID := range parentBuildIDs {
Expand Down
34 changes: 25 additions & 9 deletions launch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2080,10 +2080,12 @@ func TestMetaWhenTriggeredFromPipelinesByANDLogicWithParentBuildMeta(t *testing.
"coverageKey": "%s",
"build_only": "build_value",
"event_only": "event_value",
"parent_event_only": "parent_event_value",
"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"
},
"event": {
"creator": "%s"
Expand All @@ -2094,7 +2096,9 @@ 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",
Expand All @@ -2120,7 +2124,8 @@ func TestMetaWhenTriggeredFromPipelinesByANDLogicWithParentBuildMeta(t *testing.
"inner_pipeline_only": "inner_pipeline_value",
"external_pipeline_only": "external_pipeline_value"
}
}
},
"parent_event_only": "parent_event_value"
}`, TestBuildID, TestJobID, TestPipelineID, TestEnvVars["SD_SONAR_PROJECT_KEY"], TestEventCreator["username"], InnerPipelineID, ExternalPipelineID)
assert.JSONEq(t, want, string(defaultMeta))

Expand Down Expand Up @@ -2521,15 +2526,20 @@ 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",
"event_only": "event_value",
"parent_event_only": "parent_event_value"
},
"parameters": {
"build_only": "build_value",
Expand All @@ -2542,7 +2552,9 @@ func TestMetaWhenTriggeredFromExternalPipelineByORLogicWithParentBuildMeta(t *te
"build_only": "build_value",
"event_only": "event_value"
}
}
},
"parent_event_only": "parent_event_value",
"build_and_event_and_parent_event": "parent_event_value"
}`, TestBuildID, TestJobID, TestPipelineID, TestEnvVars["SD_SONAR_PROJECT_KEY"], TestEventCreator["username"], ExternalPipelineID)
assert.JSONEq(t, want, string(defaultMeta))

Expand Down Expand Up @@ -2693,20 +2705,24 @@ func TestMetaWhenStartFromAnyJobWithParentEvent(t *testing.T) {
"coverageKey": "%s",
"build_only": "build_value",
"event_only": "event_value",
"build_and_event_and_parent_event": "event_value"
"build_and_event_and_parent_event": "event_value",
"parent_event_only": "parent_event_value"
},
"event": {
"creator": "%s"
},
"meta":{
"build_only": "build_value",
"event_only": "event_value",
"build_and_event_and_parent_event": "event_value"
"build_and_event_and_parent_event": "event_value",
"event_only": "event_value",
"parent_event_only": "parent_event_value"
},
"parameters":{
"build_only": "build_value",
"build_and_event_and_parent_event": "build_value"
}
},
"parent_event_only": "parent_event_value"
}`, TestBuildID, TestJobID, TestPipelineID, TestEnvVars["SD_SONAR_PROJECT_KEY"], TestEventCreator["username"])

assert.JSONEq(t, want, string(defaultMeta))
Expand Down

0 comments on commit 1caef0a

Please sign in to comment.