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

graphqlbackend: add permissionsSyncJobs query#44387

Merged
bobheadxi merged 14 commits intomainfrom
11-14-graphqlbackend_add_permissionsSyncJobs_endpoint
Nov 16, 2022
Merged

graphqlbackend: add permissionsSyncJobs query#44387
bobheadxi merged 14 commits intomainfrom
11-14-graphqlbackend_add_permissionsSyncJobs_endpoint

Conversation

@bobheadxi
Copy link
Member

@bobheadxi bobheadxi commented Nov 14, 2022

Adds a new permissionsSyncJobs that returns the most recent outcomes of permissions sync jobs, with per-provider details included. This will be used to validate permissions syncing is starting correctly and the desired providers are being involved and in a healthy state.

We don't implement pagination since the endpoint is intended as a stream of recent events and retention is low (see https://github.com/sourcegraph/sourcegraph/pull/44258), but the endpoint schema is set up so that it can be extended to support pagination in the future.

Closes https://github.com/sourcegraph/customer/issues/1534
Stacked on https://github.com/sourcegraph/sourcegraph/pull/44258

Test plan

Add a GitHub code host with "authorization": {}, and add a private repo to the list

Wait a few minutes

image

Remove the token:

image

Get by ID:

image

@cla-bot cla-bot bot added the cla-signed label Nov 14, 2022
@bobheadxi
Copy link
Member Author

@sg-e2e-regression-test-bob
Copy link

sg-e2e-regression-test-bob commented Nov 14, 2022

Bundle size report 📦

Initial size Total size Async size Modules
0.01% (+0.26 kb) 0.00% (+0.51 kb) 0.00% (+0.25 kb) 0.00% (0)

Look at the Statoscope report for a full comparison between the commits 08153cc and d2e4f01 or learn more.

Open explanation
  • Initial size is the size of the initial bundle (the one that is loaded when you open the page)
  • Total size is the size of the initial bundle + all the async loaded chunks
  • Async size is the size of all the async loaded chunks
  • Modules is the number of modules in the initial bundle

@bobheadxi bobheadxi force-pushed the 11-14-graphqlbackend_add_permissionsSyncJobs_endpoint branch from 6b0db24 to eeb2359 Compare November 15, 2022 00:07
@bobheadxi bobheadxi force-pushed the 11-10-PermsSyncer_track_recent_job_states_in_redis branch from ba45511 to 3cde488 Compare November 15, 2022 16:43
@bobheadxi bobheadxi force-pushed the 11-14-graphqlbackend_add_permissionsSyncJobs_endpoint branch from eeb2359 to 013067d Compare November 15, 2022 16:43
@bobheadxi bobheadxi force-pushed the 11-10-PermsSyncer_track_recent_job_states_in_redis branch from 3cde488 to fa813d6 Compare November 15, 2022 16:45
@bobheadxi bobheadxi force-pushed the 11-14-graphqlbackend_add_permissionsSyncJobs_endpoint branch from 013067d to fd4c405 Compare November 15, 2022 16:45
Comment on lines 149 to 153
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have a standard way to do pagination. Based on PageInfo type defined in graphql (IIRC). Which in turn is based on cursor pagination, not offset and limit.

I think we can reuse it instead of introducing custom code. The convention is then to ask for

first: Int
after: String
Where first is basically the limit as you use it. And after is the cursor that points to the item after which want to get the next page worth of items. You can see it in action on org members here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I copied this from another endpoint here. That said, I currently don't intend for this endpoint to be paginated - it should only ever return the X most recent runs, older runs will expire and should not be paginated for

Copy link
Member Author

@bobheadxi bobheadxi Nov 16, 2022

Choose a reason for hiding this comment

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

For now I'm opting to not implement pagination here, since the endpoint and data are not designed to return enough data to warrant pagination at the moment. I've updated various docstrings, and also made the data retention a more aggressive 5m by default (https://github.com/sourcegraph/sourcegraph/pull/44258)

Copy link
Member Author

Choose a reason for hiding this comment

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

I did rename count to first, however, so the parameters can one day be extended to paginate if needed!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can consider splitting all of these resolvers into their own file. They seem to be completely separate from responsibility point of view.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I will keep these in the same file for now - they are both very thin adapters for the GraphQL interfaces, and it seems the general practice is to keep them together (e.g. the bitbucket endpoint resolver)

@bobheadxi bobheadxi force-pushed the 11-10-PermsSyncer_track_recent_job_states_in_redis branch from fa813d6 to f78b88d Compare November 15, 2022 17:46
@bobheadxi bobheadxi force-pushed the 11-14-graphqlbackend_add_permissionsSyncJobs_endpoint branch 2 times, most recently from 1d82a35 to b4cba34 Compare November 15, 2022 17:48
@bobheadxi bobheadxi force-pushed the 11-10-PermsSyncer_track_recent_job_states_in_redis branch from 5169b47 to 17edfe2 Compare November 15, 2022 18:07
@bobheadxi bobheadxi force-pushed the 11-14-graphqlbackend_add_permissionsSyncJobs_endpoint branch 5 times, most recently from e2287c5 to f6e62b8 Compare November 15, 2022 23:40
@bobheadxi bobheadxi force-pushed the 11-10-PermsSyncer_track_recent_job_states_in_redis branch from 57cdeed to 244d49a Compare November 15, 2022 23:42
@bobheadxi bobheadxi force-pushed the 11-14-graphqlbackend_add_permissionsSyncJobs_endpoint branch 5 times, most recently from 1465a70 to 480e5ec Compare November 16, 2022 00:32
@bobheadxi bobheadxi force-pushed the 11-10-PermsSyncer_track_recent_job_states_in_redis branch from 5eaae52 to edeecce Compare November 16, 2022 00:32
@bobheadxi bobheadxi force-pushed the 11-14-graphqlbackend_add_permissionsSyncJobs_endpoint branch 2 times, most recently from 567ede0 to f030783 Compare November 16, 2022 00:42
@bobheadxi bobheadxi force-pushed the 11-14-graphqlbackend_add_permissionsSyncJobs_endpoint branch 2 times, most recently from 3b69175 to 0e21a6c Compare November 16, 2022 16:44
@bobheadxi bobheadxi requested a review from eseliger November 16, 2022 16:46
Copy link
Member

@eseliger eseliger left a comment

Choose a reason for hiding this comment

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

lgtm, pending implementing the remaining comments (not sure if review was re-requested intentionally yet?)

Copy link
Member

Choose a reason for hiding this comment

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

yeah I think that's ok, if we want to avoid confusion we might want to rename it to something else if we got anything better, but not strictly required.

Copy link
Member

@eseliger eseliger left a comment

Choose a reason for hiding this comment

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

LGTM, pending one last thing for Node

Copy link
Member

Choose a reason for hiding this comment

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

This resolver should have a method called NodeResolvers

Should be called like that: https://sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/cmd/frontend/graphqlbackend/graphqlbackend.go?L366 for the authz resolver in the same method
For that, add to the interface type this signature https://sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/cmd/frontend/graphqlbackend/batches.go?L302
Finally, the NodeResolvers method should return a mapping from Kind to a resolver func.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Looks good!

@bobheadxi bobheadxi force-pushed the 11-14-graphqlbackend_add_permissionsSyncJobs_endpoint branch from 3541b9b to a37cf74 Compare November 16, 2022 17:18
Base automatically changed from 11-10-PermsSyncer_track_recent_job_states_in_redis to main November 16, 2022 18:11
@bobheadxi bobheadxi force-pushed the 11-14-graphqlbackend_add_permissionsSyncJobs_endpoint branch from 1687dfe to ba0c0db Compare November 16, 2022 18:11
@bobheadxi bobheadxi dismissed mrnugget’s stale review November 16, 2022 19:43

Changes to make query align with pagination/Node paradigms made and reviewed by Erik

@bobheadxi bobheadxi merged commit 923a15a into main Nov 16, 2022
@bobheadxi bobheadxi deleted the 11-14-graphqlbackend_add_permissionsSyncJobs_endpoint branch November 16, 2022 19:44
type recordsReader struct {
// readOnlyCache is a replaceable abstraction over rcache.Cache.
readOnlyCache interface {
ListKeys(ctx context.Context) ([]string, error)
Copy link
Member

Choose a reason for hiding this comment

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

@bobheadxi sorry to revive an old PR. But I've been reviewing our use of redis and noticed this use of ListKeys. FYI this operation has the complexity of listing all keys on the redis instance, not just those associated with the named cache. It will only return the relevant keys, but redis doesn't have a way to do this otherwise.

How many keys do you expect us to get? From looking around, it seems like this would be better suited using rcache.FIFOList. WDYT?
Instead of this

Copy link
Member Author

Choose a reason for hiding this comment

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

The FIFOList wasn't available at the time, but I did spot it in other PRs - I can make the switch here :) Will open a PR tomorrow!

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.

9 participants