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

Extract grouping ID based on configurations #1242

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 14 additions & 1 deletion pkg/updater/resultstore/resultstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
77 changes: 77 additions & 0 deletions pkg/updater/resultstore/resultstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: &timestamppb.Timestamp{
Seconds: 1234,
},
},
},
},
want: "test-val-1",
},
bryan-lou marked this conversation as resolved.
Show resolved Hide resolved
{
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: &timestamppb.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.
Expand Down