Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

insights: update gql to allow control over number of series samples#46284

Merged
leonore merged 15 commits into
mainfrom
insights/control-samples-shown
Jan 12, 2023
Merged

insights: update gql to allow control over number of series samples#46284
leonore merged 15 commits into
mainfrom
insights/control-samples-shown

Conversation

@leonore

@leonore leonore commented Jan 10, 2023

Copy link
Copy Markdown
Contributor

closes https://github.com/sourcegraph/sourcegraph/issues/45750

open https://github.com/sourcegraph/sourcegraph/issues/46283 as follow up, frontend changes still need to be done

Test plan

Added unit tests
Manually tested:

query GetInsightView($id: ID, $filters: InsightViewFiltersInput, $seriesDisplayOptions: SeriesDisplayOptionsInput) {
  insightViews(
    id: $id
    filters: $filters
    seriesDisplayOptions: $seriesDisplayOptions
  ) {
    nodes {
      ...InsightDataNode
      __typename
    }
    __typename
  }
}

fragment InsightDataNode on InsightView {
  id
  dataSeries {
    ...InsightDataSeries
    __typename
  }
  __typename
}

fragment InsightDataSeries on InsightsSeries {
  seriesId
  label
  points {
    dateTime
    value
    diffQuery
    __typename
  }
  __typename
}

variables

{"id":"aW5zaWdodF92aWV3OiIySjA3YTE4bGZTZEZzenYxOXp4QjhrZWQ5RVki","filters":{"includeRepoRegex":"","excludeRepoRegex":"","searchContexts":[""]},"seriesDisplayOptions":{"limit":20,"sortOptions":{"direction":"DESC","mode":"RESULT_COUNT"}, "numSamples": 1}}

result

{
  "data": {
    "insightViews": {
      "nodes": [
        {
          "id": "aW5zaWdodF92aWV3OiIySjA3YTE4bGZTZEZzenYxOXp4QjhrZWQ5RVki",
          "dataSeries": [
            {
              "seriesId": "2J07a7NrF1cNQjEGfFF8XU2ygmR",
              "label": "I hate",
              "points": [
                {
                  "dateTime": "2023-01-10T13:44:42Z",
                  "value": 2,
                  "diffQuery": "repo:leonore before:2023-01-10T13:44:42Z type:diff I hate",
                  "__typename": "InsightDataPoint"
                }
              ],
              "__typename": "InsightsSeries"
            }
          ],
          "__typename": "InsightView"
        }
      ],
      "__typename": "InsightViewConnection"
    }
  }
}

@leonore leonore requested a review from a team January 10, 2023 14:54
@cla-bot cla-bot Bot added the cla-signed label Jan 10, 2023
@sourcegraph-bot

sourcegraph-bot commented Jan 10, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff fc2652e...ca0ef93.

Notify File(s)
@sourcegraph/code-insights-backend cmd/frontend/graphqlbackend/insights.go
enterprise/internal/insights/background/retention/worker.go
enterprise/internal/insights/background/retention/worker_test.go
enterprise/internal/insights/resolvers/insight_series_resolver.go
enterprise/internal/insights/resolvers/insight_view_resolvers.go
enterprise/internal/insights/scheduler/backfill_state_new_handler_test.go
enterprise/internal/insights/store/mocks_temp.go
enterprise/internal/insights/store/store.go
enterprise/internal/insights/store/store_test.go
enterprise/internal/insights/types/types.go

@chwarwick chwarwick left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the plan to persist this value in the future? I think there 2 potential impacts from this.

  • hourly/daily/weekly insights could start showing fewer points by default - I think this is ok
  • Monthly insights start showing more points - I also think this is ok

I do think we should remove it from the resolver if it is just returning user input.

Comment thread enterprise/internal/insights/store/store.go
"""
Max number of samples to return for all the series on the view.
"""
numSamples: Int

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels wrong to include this is the options of the series if this isn't persisted and is just returning whatever was sent in the input options.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does allow us to "soft validate" by replacing invalid (too big) values with a max. I'm not strongly opinionated either way though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove it until I work on this issue if you'd rather: https://github.com/sourcegraph/sourcegraph/issues/46283

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaving this in, added soft-validation (max 90 samples). that issue linked will take care on allowing to actually set a default number of samples (which will need frontend work to actually work...)

@leonore

leonore commented Jan 10, 2023

Copy link
Copy Markdown
Contributor Author

Is the plan to persist this value in the future? I think there 2 potential impacts from this.

yes that is the plan (https://github.com/sourcegraph/sourcegraph/issues/46283)

it's just a lot of boilerplate to implement that functionality, so I didn't want to detract from the actual logic being implemented here

@leonore leonore merged commit 692910a into main Jan 12, 2023
@leonore leonore deleted the insights/control-samples-shown branch January 12, 2023 15:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

insights: allow user controlled sample count

4 participants