Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(3234): event and parentEvent meta should be mutually exclusive #478

Merged
merged 6 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,18 @@ func launch(api screwdriver.API, buildID int, rootDir, emitterPath, metaSpace, s
return err, "", ""
}

// Always merge parent event meta if it exists (Issue #3234)
if event.ParentEventID != 0 { // If has parent event, fetch meta from parent event
// Note: event and parent event meta are mutually exclusive
// the first event in the build chain for a restart case will use the parent event meta
// on launcher exit, the meta will be updated to the current event meta

// merge event meta if available
if len(event.Meta) > 0 { // If has meta, marshal it
log.Printf("Fetching Event Meta JSON %v", event.ID)
if event.Meta != nil {
mergedMeta = deepMergeJSON(mergedMeta, event.Meta)
}
} else if event.ParentEventID != 0 { // otherwise, fetch from parent event
// 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 All @@ -489,14 +499,6 @@ func launch(api screwdriver.API, buildID int, rootDir, emitterPath, metaSpace, s
metaLog = fmt.Sprintf(`Event(%v)`, parentEvent.ID)
}

// Always merge event meta
if len(event.Meta) > 0 { // If has meta, marshal it
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
22 changes: 4 additions & 18 deletions launch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,6 @@ func TestMetaWhenTriggeredFromPipelinesByANDLogicWithParentBuildMeta(t *testing.
"build_and_event_and_inner_pipeline": "inner_pipeline_value",
"build_and_event_and_external_pipeline": "external_pipeline_value",
"build_and_event_and_parent_event": "inner_pipeline_value",
"parent_event_only": "parent_event_value",
"event_and_parent_event": "event_value",
"build":{
"buildId": "%d",
Expand All @@ -2084,9 +2083,7 @@ 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_parent_event": "parent_event_value",
"parent_event_only": "parent_event_value"
"build_and_event_and_external_pipeline": "external_pipeline_value"
},
"event": {
"creator": "%s"
Expand All @@ -2097,9 +2094,7 @@ 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_parent_event": "parent_event_value",
"parent_event_only": "parent_event_value"
"build_and_event_and_external_pipeline": "external_pipeline_value"
},
"parameters": {
"build_only": "build_value",
Expand Down Expand Up @@ -2516,8 +2511,6 @@ 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 @@ -2528,19 +2521,15 @@ 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_parent_event": "parent_event_value",
"parent_event_only": "parent_event_value"
"build_and_event_and_external_pipeline": "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_parent_event": "parent_event_value",
"parent_event_only": "parent_event_value"
"build_and_event_and_external_pipeline": "event_value"
},
"parameters": {
"build_only": "build_value",
Expand Down Expand Up @@ -2693,7 +2682,6 @@ func TestMetaWhenStartFromAnyJobWithParentEvent(t *testing.T) {
want := fmt.Sprintf(`{
"build_only": "build_value",
"event_only": "event_value",
"parent_event_only": "parent_event_value",
"build_and_event_and_parent_event": "event_value",
"build":{
"buildId": "%d",
Expand All @@ -2705,7 +2693,6 @@ func TestMetaWhenStartFromAnyJobWithParentEvent(t *testing.T) {
"coverageKey": "%s",
"build_only": "build_value",
"event_only": "event_value",
"parent_event_only": "parent_event_value",
"build_and_event_and_parent_event": "event_value"
},
"event": {
Expand All @@ -2714,7 +2701,6 @@ func TestMetaWhenStartFromAnyJobWithParentEvent(t *testing.T) {
"meta":{
"build_only": "build_value",
"event_only": "event_value",
"parent_event_only": "parent_event_value",
"build_and_event_and_parent_event": "event_value"
},
"parameters":{
Expand Down