diff --git a/pkg/processing/save.go b/pkg/processing/save.go index 30e1350..ffc40dc 100644 --- a/pkg/processing/save.go +++ b/pkg/processing/save.go @@ -239,23 +239,8 @@ func (act SaveActor) saveTargetCompletion(ctx context.Context, targetCompletion Save(ctx) } -func (act SaveActor) saveTargetPair(ctx context.Context, targetPair summary.TargetPair, label string) (*ent.TargetPair, error) { - configuration := targetPair.Configuration - completion := targetPair.Completion - - targetConfiguration, err := act.saveTargetConfiguration(ctx, configuration) - if err != nil { - return nil, err - } - - targetCompletion, err := act.saveTargetCompletion(ctx, completion) - if err != nil { - return nil, err - } - +func (act SaveActor) saveTargetPair(ctx context.Context, targetPair summary.TargetPair, label string, enrich bool) (*ent.TargetPair, error) { create := act.db.TargetPair.Create(). - SetCompletion(targetCompletion). - SetConfiguration(targetConfiguration). SetLabel(label). SetDurationInMs(targetPair.DurationInMs). SetSuccess(targetPair.Success). @@ -267,16 +252,35 @@ func (act SaveActor) saveTargetPair(ctx context.Context, targetPair summary.Targ create = create.SetAbortReason(reason) } + if enrich { + configuration := targetPair.Configuration + completion := targetPair.Completion + + targetConfiguration, err := act.saveTargetConfiguration(ctx, configuration) + if err != nil { + return nil, err + } + + targetCompletion, err := act.saveTargetCompletion(ctx, completion) + if err != nil { + return nil, err + } + create.SetCompletion(targetCompletion).SetConfiguration(targetConfiguration) + } + return create.Save(ctx) } // TODO: is there a more effiient way to do bulk updates instead of sequentially adding everything to the database one object at a time? // ironically, MapBulkCreate doesn't work for the map(string)TargetPair. Its expecting an int index, not a label. func (act SaveActor) saveTargets(ctx context.Context, summary *summary.Summary) ([]*ent.TargetPair, error) { + if summary.SkipTargetData { + return []*ent.TargetPair{}, nil + } var result []*ent.TargetPair = make([]*ent.TargetPair, len(summary.Targets)) i := 0 for label, pair := range summary.Targets { - targetPair, err := act.saveTargetPair(ctx, pair, label) + targetPair, err := act.saveTargetPair(ctx, pair, label, summary.EnrichTargetData) if err != nil { return nil, err } @@ -375,33 +379,37 @@ func (act SaveActor) saveTestResults(ctx context.Context, testResults []summary. }).Save(ctx) } -func (act SaveActor) saveTestCollection(ctx context.Context, testCollection summary.TestsCollection, label string) (*ent.TestCollection, error) { - testSummary, err := act.saveTestSummary(ctx, testCollection.TestSummary, label) - if err != nil { - return nil, err - } - testResults, err := act.saveTestResults(ctx, testCollection.TestResults) - if err != nil { - return nil, err - } - return act.db.TestCollection.Create(). +func (act SaveActor) saveTestCollection(ctx context.Context, testCollection summary.TestsCollection, label string, encrich bool) (*ent.TestCollection, error) { + create := act.db.TestCollection.Create(). SetLabel(label). - SetTestSummary(testSummary). - AddTestResults(testResults...). SetOverallStatus(testcollection.OverallStatus(testCollection.OverallStatus.String())). SetStrategy(testCollection.Strategy). SetCachedLocally(testCollection.CachedLocally). SetCachedRemotely(testCollection.CachedRemotely). SetDurationMs(testCollection.DurationMs). - SetFirstSeen((testCollection.FirstSeen)). - Save(ctx) + SetFirstSeen((testCollection.FirstSeen)) + + if encrich { + + testSummary, err := act.saveTestSummary(ctx, testCollection.TestSummary, label) + if err != nil { + return nil, err + } + testResults, err := act.saveTestResults(ctx, testCollection.TestResults) + if err != nil { + return nil, err + } + create.SetTestSummary(testSummary).AddTestResults(testResults...) + } + + return create.Save(ctx) } func (act SaveActor) saveTests(ctx context.Context, summary *summary.Summary) ([]*ent.TestCollection, error) { var result []*ent.TestCollection = make([]*ent.TestCollection, len(summary.Tests)) i := 0 for label, collection := range summary.Tests { - testCollection, err := act.saveTestCollection(ctx, collection, label) + testCollection, err := act.saveTestCollection(ctx, collection, label, summary.EnrichTargetData) if err != nil { return nil, err } diff --git a/pkg/summary/summarizer.go b/pkg/summary/summarizer.go index 0df2536..2a1f257 100644 --- a/pkg/summary/summarizer.go +++ b/pkg/summary/summarizer.go @@ -184,10 +184,11 @@ func (s Summarizer) handleBuildConfiguration(configuration *bes.Configuration) { // handleTargetConfigured func (s Summarizer) handleTargetConfigured(target *bes.TargetConfigured, label string, timestamp time.Time) { if len(label) == 0 { - panic("missing a target label for target configured event!") + slog.Warn("missing a target label for target configured event!") + return } if target == nil { - slog.Debug(fmt.Sprintf("missing target for label %s on targetConfigured", label)) + slog.Warn(fmt.Sprintf("missing target for label %s on targetConfigured", label)) return } @@ -213,18 +214,21 @@ func (s Summarizer) handleTargetConfigured(target *bes.TargetConfigured, label s // handleTargetCompleted func (s Summarizer) handleTargetCompleted(target *bes.TargetComplete, label string, aborted *bes.Aborted, timestamp time.Time) { if len(label) == 0 { - panic("label is empty for a target completed event") + slog.Error("label is empty for a target completed event") + return } if s.summary.Targets == nil { - panic(fmt.Sprintf("target completed event received before any target configured messages for label %s,", label)) + slog.Warn(fmt.Sprintf("target completed event received before any target configured messages for label %s,", label)) + return } var targetPair TargetPair targetPair, ok := s.summary.Targets[label] if !ok { - panic(fmt.Sprintf("target completed event received for label %s before target configured message received", label)) + slog.Warn(fmt.Sprintf("target completed event received for label %s before target configured message received", label)) + return } var targetCompletion TargetComplete @@ -359,17 +363,20 @@ func processExecutionInfo(testResult *bes.TestResult) ExecutionInfo { // handleTestSummary func (s Summarizer) handleTestSummary(testSummary *bes.TestSummary, label string) { if len(label) == 0 { - panic("missing label on handleTestSummary event") + slog.Error("missing label on handleTestSummary event") + return } if testSummary == nil { - panic(fmt.Sprintf("missing test summary object for handleTestSummary event for label %s", label)) + slog.Warn("missing test summary object for handleTestSummary event for label %s", label, nil) + return } testCollection, ok := s.summary.Tests[label] if !ok { - panic(fmt.Sprintf("received a test summary event but never first saw a test result for label %s", label)) + slog.Warn("received a test summary event but never first saw a test result for label %s", label, nil) + return } tSummary := testCollection.TestSummary @@ -787,6 +794,20 @@ func (s Summarizer) handleStructuredCommandLine(structuredCommandLine *bescore.C s.summary.BuildURL = s.summary.InvocationSummary.EnvVars["BUILD_URL"] s.summary.BuildUUID = uuid.NewSHA1(uuid.NameSpaceURL, []byte(s.summary.BuildURL)) + // Set SkipTargetData + if skipTargetSaveEnvVarVal, ok := s.summary.EnvVars["BB_PORTAL_SKIP_SAVE_TARGETS"]; ok { + if skipTargetSaveEnvVarVal == "TRUE" { + s.summary.SkipTargetData = true + } + } + + // Set EnrichTargetData + if enrichTargetDataVal, ok := s.summary.EnvVars["BB_PORTAL_ENRICH_TARGET_DATA"]; ok { + if enrichTargetDataVal == "TRUE" { + s.summary.EnrichTargetData = true + } + } + return nil } diff --git a/pkg/summary/summary.go b/pkg/summary/summary.go index b327eea..8035792 100644 --- a/pkg/summary/summary.go +++ b/pkg/summary/summary.go @@ -189,6 +189,8 @@ type Summary struct { PlatformName string ProfileName string ConfigrationMnemonic string + SkipTargetData bool + EnrichTargetData bool } // Metrics holds Build metrics details diff --git a/pkg/summary/testdata/snapshots/nextjs_build.bep.ndjson.golden.json b/pkg/summary/testdata/snapshots/nextjs_build.bep.ndjson.golden.json index b0433e7..f53617d 100644 --- a/pkg/summary/testdata/snapshots/nextjs_build.bep.ndjson.golden.json +++ b/pkg/summary/testdata/snapshots/nextjs_build.bep.ndjson.golden.json @@ -254,7 +254,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.579117733Z" + "FirstSeen": "2024-10-18T18:21:46.723807658Z" }, "//next.js:build_smoke_test": { "TestSummary": { @@ -315,7 +315,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.578731697Z" + "FirstSeen": "2024-10-18T18:21:46.723426532Z" }, "//next.js:build_test": { "TestSummary": { @@ -376,7 +376,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.578686265Z" + "FirstSeen": "2024-10-18T18:21:46.72338211Z" }, "//react-webpack:build_smoke_test": { "TestSummary": { @@ -437,7 +437,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.575992687Z" + "FirstSeen": "2024-10-18T18:21:46.721110312Z" }, "//react/src:lint": { "TestSummary": { @@ -498,7 +498,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.575237584Z" + "FirstSeen": "2024-10-18T18:21:46.720344848Z" }, "//react/src:src_typecheck_test": { "TestSummary": { @@ -559,7 +559,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.573621233Z" + "FirstSeen": "2024-10-18T18:21:46.718683677Z" }, "//react/src:test": { "TestSummary": { @@ -620,7 +620,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.575515986Z" + "FirstSeen": "2024-10-18T18:21:46.720660573Z" }, "//react/src:test_lib_typecheck_test": { "TestSummary": { @@ -681,7 +681,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.574122685Z" + "FirstSeen": "2024-10-18T18:21:46.719258972Z" }, "//react:build_smoke_test": { "TestSummary": { @@ -742,7 +742,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.57446967Z" + "FirstSeen": "2024-10-18T18:21:46.719595516Z" }, "//vue:build_test": { "TestSummary": { @@ -803,7 +803,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.574615247Z" + "FirstSeen": "2024-10-18T18:21:46.719726672Z" }, "//vue:type-check": { "TestSummary": { @@ -864,7 +864,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.575000133Z" + "FirstSeen": "2024-10-18T18:21:46.720041905Z" } }, "Targets": { @@ -3023,6 +3023,8 @@ "CPU": "darwin_arm64", "PlatformName": "darwin_arm64", "ProfileName": "command.profile.gz", - "ConfigrationMnemonic": "darwin_arm64-fastbuild" + "ConfigrationMnemonic": "darwin_arm64-fastbuild", + "SkipTargetData": false, + "EnrichTargetData": false } } \ No newline at end of file diff --git a/pkg/summary/testdata/snapshots/nextjs_build_fail.bep.ndjson.golden.json b/pkg/summary/testdata/snapshots/nextjs_build_fail.bep.ndjson.golden.json index ef92ded..7966eda 100644 --- a/pkg/summary/testdata/snapshots/nextjs_build_fail.bep.ndjson.golden.json +++ b/pkg/summary/testdata/snapshots/nextjs_build_fail.bep.ndjson.golden.json @@ -301,7 +301,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.655487441Z" + "FirstSeen": "2024-10-18T18:21:46.80365425Z" }, "//react/src:lint": { "TestSummary": { @@ -362,7 +362,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.654707647Z" + "FirstSeen": "2024-10-18T18:21:46.802806794Z" }, "//react/src:src_typecheck_test": { "TestSummary": { @@ -423,7 +423,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.653280255Z" + "FirstSeen": "2024-10-18T18:21:46.801494027Z" }, "//react/src:test": { "TestSummary": { @@ -484,7 +484,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.654892565Z" + "FirstSeen": "2024-10-18T18:21:46.803017763Z" }, "//react/src:test_lib_typecheck_test": { "TestSummary": { @@ -545,7 +545,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.653517645Z" + "FirstSeen": "2024-10-18T18:21:46.801751308Z" }, "//react:build_smoke_test": { "TestSummary": { @@ -606,7 +606,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.653763947Z" + "FirstSeen": "2024-10-18T18:21:46.801938256Z" }, "//vue:build_test": { "TestSummary": { @@ -667,7 +667,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.654131702Z" + "FirstSeen": "2024-10-18T18:21:46.802300732Z" }, "//vue:type-check": { "TestSummary": { @@ -728,7 +728,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.654384523Z" + "FirstSeen": "2024-10-18T18:21:46.802518022Z" } }, "Targets": { @@ -2868,6 +2868,8 @@ "CPU": "darwin_arm64", "PlatformName": "darwin_arm64", "ProfileName": "command.profile.gz", - "ConfigrationMnemonic": "darwin_arm64-fastbuild" + "ConfigrationMnemonic": "darwin_arm64-fastbuild", + "SkipTargetData": false, + "EnrichTargetData": false } } \ No newline at end of file diff --git a/pkg/summary/testdata/snapshots/nextjs_error_progress.bep.ndjson.golden.json b/pkg/summary/testdata/snapshots/nextjs_error_progress.bep.ndjson.golden.json index 85c9c13..678d5a9 100644 --- a/pkg/summary/testdata/snapshots/nextjs_error_progress.bep.ndjson.golden.json +++ b/pkg/summary/testdata/snapshots/nextjs_error_progress.bep.ndjson.golden.json @@ -1053,6 +1053,8 @@ "CPU": "darwin_arm64", "PlatformName": "darwin_arm64", "ProfileName": "command.profile.gz", - "ConfigrationMnemonic": "darwin_arm64-fastbuild" + "ConfigrationMnemonic": "darwin_arm64-fastbuild", + "SkipTargetData": false, + "EnrichTargetData": false } } \ No newline at end of file diff --git a/pkg/summary/testdata/snapshots/nextjs_test.bep.ndjson.golden.json b/pkg/summary/testdata/snapshots/nextjs_test.bep.ndjson.golden.json index 94aff8e..a1f3745 100644 --- a/pkg/summary/testdata/snapshots/nextjs_test.bep.ndjson.golden.json +++ b/pkg/summary/testdata/snapshots/nextjs_test.bep.ndjson.golden.json @@ -295,7 +295,7 @@ "CachedLocally": false, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.79980903Z" + "FirstSeen": "2024-10-18T18:21:46.925446191Z" }, "//next.js:build_smoke_test": { "TestSummary": { @@ -356,7 +356,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.796408671Z" + "FirstSeen": "2024-10-18T18:21:46.921871047Z" }, "//next.js:build_test": { "TestSummary": { @@ -417,7 +417,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.797348962Z" + "FirstSeen": "2024-10-18T18:21:46.923039038Z" }, "//react-webpack:build_smoke_test": { "TestSummary": { @@ -478,7 +478,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.79754056Z" + "FirstSeen": "2024-10-18T18:21:46.923269978Z" }, "//react/src:lint": { "TestSummary": { @@ -539,7 +539,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.798837177Z" + "FirstSeen": "2024-10-18T18:21:46.924480479Z" }, "//react/src:src_typecheck_test": { "TestSummary": { @@ -600,7 +600,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.796676013Z" + "FirstSeen": "2024-10-18T18:21:46.922283765Z" }, "//react/src:test": { "TestSummary": { @@ -661,7 +661,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.798601257Z" + "FirstSeen": "2024-10-18T18:21:46.924284091Z" }, "//react/src:test_lib_typecheck_test": { "TestSummary": { @@ -722,7 +722,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.797164244Z" + "FirstSeen": "2024-10-18T18:21:46.922836959Z" }, "//react:build_smoke_test": { "TestSummary": { @@ -783,7 +783,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.797812403Z" + "FirstSeen": "2024-10-18T18:21:46.923505928Z" }, "//vue:build_test": { "TestSummary": { @@ -844,7 +844,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.797956609Z" + "FirstSeen": "2024-10-18T18:21:46.923647154Z" }, "//vue:type-check": { "TestSummary": { @@ -905,7 +905,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.798160038Z" + "FirstSeen": "2024-10-18T18:21:46.92379656Z" } }, "Targets": { @@ -3064,6 +3064,8 @@ "CPU": "darwin_arm64", "PlatformName": "darwin_arm64", "ProfileName": "command.profile.gz", - "ConfigrationMnemonic": "darwin_arm64-fastbuild" + "ConfigrationMnemonic": "darwin_arm64-fastbuild", + "SkipTargetData": false, + "EnrichTargetData": false } } \ No newline at end of file diff --git a/pkg/summary/testdata/snapshots/nextjs_test_fail.bep.ndjson.golden.json b/pkg/summary/testdata/snapshots/nextjs_test_fail.bep.ndjson.golden.json index e73918d..e9faa0b 100644 --- a/pkg/summary/testdata/snapshots/nextjs_test_fail.bep.ndjson.golden.json +++ b/pkg/summary/testdata/snapshots/nextjs_test_fail.bep.ndjson.golden.json @@ -385,7 +385,7 @@ "CachedLocally": false, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.891310919Z" + "FirstSeen": "2024-10-18T18:21:47.015888481Z" }, "//next.js:build_smoke_test": { "TestSummary": { @@ -446,7 +446,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.890823078Z" + "FirstSeen": "2024-10-18T18:21:47.01541405Z" }, "//next.js:build_test": { "TestSummary": { @@ -507,7 +507,7 @@ "CachedLocally": true, "CachedRemotely": false, "DurationMs": 0, - "FirstSeen": "2024-10-10T18:40:35.890768125Z" + "FirstSeen": "2024-10-18T18:21:47.015363618Z" } }, "Targets": { @@ -1199,6 +1199,8 @@ "CPU": "darwin_arm64", "PlatformName": "darwin_arm64", "ProfileName": "command.profile.gz", - "ConfigrationMnemonic": "darwin_arm64-fastbuild" + "ConfigrationMnemonic": "darwin_arm64-fastbuild", + "SkipTargetData": false, + "EnrichTargetData": false } } \ No newline at end of file