Skip to content

insights: Add groupBy field for compute insights

Warren Gifford requested to merge insights/compute-api-groupby into main

Created by: CristinaBirkel

Closes https://github.com/sourcegraph/sourcegraph/issues/37864

Description

In order to quickly get compute insights out to customers and validate how useful they are, we'll add this functionality into our existing LineChartSearchInsight API and infer that it's a compute insight by the presence of the groupBy value. This PR adds this new field into the API so it can be used for both the create and update mutations, and can be read from the SearchInsightDataSeriesDefinition.

I made it a nullable field so that we can safely ignore it and only use it when necessary. And I went with a string instead of an enum because it's more lightweight for this type of quick change.

Test plan

Try creating a new LineChartSearchInsight with and without the new groupBy field in the series. Example with:

mutation {
    createLineChartSearchInsight (input: {
        options: {
            title: "new test insight"
        },
        dataSeries: [{
            query: "test function",
            options: {
                label: "test function",
                lineColor: "var(--oc-grape-7)"
        },
        repositoryScope: {
            repositories: []
        },
        timeScope: {
           stepInterval: {
                  unit: MONTH,
                  value: 1
            }
        },
        groupBy: "repo"
        }]
    })
    {
      view {
          id,
          dataSeriesDefinitions {
              ... on SearchInsightDataSeriesDefinition {
                  seriesId,
                  query,
                  repositoryScope {
                      repositories
                  }
                  timeScope {
                  ... on InsightIntervalTimeScope {
                          unit,
                          value
                      }
                  },
                  groupBy
              }
          }
    }
}

I also loaded up some insights pages and backfilled a new insight to check for regressions. This change does touch the core path for fetching insights (by modifying the sql queries in the store,) so regressions are a concern.

The last thing to check for is that the series matching is still working as expected. I tried creating the same series multiple times, and verifying that it matches as expected, (both when groupBy is missing, and when it's filled in.)

Merge request reports

Loading