From eec22460ed9d04107c17e536434fe322ca3d3118 Mon Sep 17 00:00:00 2001 From: Bryan Lou Date: Tue, 25 Jul 2023 19:15:27 +0000 Subject: [PATCH] Extract grouping ID based on configs --- pkg/updater/resultstore/resultstore.go | 15 +++- pkg/updater/resultstore/resultstore_test.go | 77 +++++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/pkg/updater/resultstore/resultstore.go b/pkg/updater/resultstore/resultstore.go index a9a70f75..fdeb0ec8 100644 --- a/pkg/updater/resultstore/resultstore.go +++ b/pkg/updater/resultstore/resultstore.go @@ -70,6 +70,20 @@ type processedResult struct { TargetResults map[string][]*singleActionResult } +// extractGroupID extracts grouping ID for a results based on the testgroup grouping configuration +// Returns an empty string for no config or incorrect config +func extractGroupID(tg *configpb.TestGroup, result *processedResult) string { + switch { + // P - build info + case result == nil: + return "" + case tg.GetPrimaryGrouping() == configpb.TestGroup_PRIMARY_GROUPING_BUILD: + return identifyBuild(tg, result) + default: + return result.InvocationProto.GetId().GetInvocationId() + } +} + // ResultStoreColumnReader fetches results since last update from ResultStore and translates them into columns. func ResultStoreColumnReader(client *DownloadClient, reprocess time.Duration) updater.ColumnReader { return func(ctx context.Context, log logrus.FieldLogger, tg *configpb.TestGroup, oldCols []updater.InflatedColumn, defaultStop time.Time, receivers chan<- updater.InflatedColumn) error { @@ -97,7 +111,6 @@ func ResultStoreColumnReader(client *DownloadClient, reprocess time.Duration) up }) for _, pr := range processedResults { - // TODO: Make group ID something other than start time. inflatedCol := processGroup(tg, pr) receivers <- *inflatedCol } diff --git a/pkg/updater/resultstore/resultstore_test.go b/pkg/updater/resultstore/resultstore_test.go index f9ffc4f2..1162b8ce 100644 --- a/pkg/updater/resultstore/resultstore_test.go +++ b/pkg/updater/resultstore/resultstore_test.go @@ -93,6 +93,83 @@ func timeMustText(t time.Time) string { return string(s) } +func TestExtractGroupID(t *testing.T) { + cases := []struct { + name string + tg *configpb.TestGroup + pr *processedResult + want string + }{ + { + name: "nil", + }, + { + name: "primary grouping BUILD by override config value", + tg: &configpb.TestGroup{ + DaysOfResults: 7, + BuildOverrideConfigurationValue: "test-key-1", + PrimaryGrouping: configpb.TestGroup_PRIMARY_GROUPING_BUILD, + }, + pr: &processedResult{ + InvocationProto: &resultstore.Invocation{ + Id: &resultstore.Invocation_Id{ + InvocationId: "id-1", + }, + Properties: []*resultstore.Property{ + { + Key: "test-key-1", + Value: "test-val-1", + }, + }, + Name: invocationName("id-1"), + Timing: &resultstore.Timing{ + StartTime: ×tamppb.Timestamp{ + Seconds: 1234, + }, + }, + }, + }, + want: "test-val-1", + }, + { + name: "fallback grouping BUILD resort to default", + tg: &configpb.TestGroup{ + DaysOfResults: 7, + BuildOverrideConfigurationValue: "test-key-1", + FallbackGrouping: configpb.TestGroup_FALLBACK_GROUPING_BUILD, + }, + pr: &processedResult{ + InvocationProto: &resultstore.Invocation{ + Id: &resultstore.Invocation_Id{ + InvocationId: "id-1", + }, + Properties: []*resultstore.Property{ + { + Key: "test-key-1", + Value: "test-val-1", + }, + }, + Name: invocationName("id-1"), + Timing: &resultstore.Timing{ + StartTime: ×tamppb.Timestamp{ + Seconds: 1234, + }, + }, + }, + }, + want: "id-1", + }, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + got := extractGroupID(tc.tg, tc.pr) + if diff := cmp.Diff(tc.want, got); diff != "" { + t.Errorf("extractGroupID() differed (-want, +got): %s", diff) + } + }) + } +} + func TestResultStoreColumnReader(t *testing.T) { // We already have functions testing 'stop' logic. // Scope this test to whether the column reader fetches and returns ascending results.