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

Conversation

@varsanojidan
Copy link
Contributor

@varsanojidan varsanojidan commented Aug 22, 2023

Closes: https://github.com/sourcegraph/sourcegraph/issues/55278
Add GraphQL mutation for configuring code host rate limits.

Test plan

Added a bunch of tests and also tested manually.

@cla-bot cla-bot bot added the cla-signed label Aug 22, 2023
@varsanojidan varsanojidan marked this pull request as ready for review August 22, 2023 23:00
"""
The time interval at which the gitQuota's worth of Git requests are replenished.
"""
gitReplenishmentIntervalSeconds: Int!
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made all of the rate limit configs required for the update because this will be used by a UI that would update all of the rate limits for a code host at the same time, and translates to one CodeHosts.Update db call regardless of how many of the code host's rate limits are actually getting updated. Additionally limits like apiQuota and apiReplenishmentIntervalSeconds are related and its better to make updating them more intentional.

Lmk if you think otherwise 😄.

@sourcegraph-bot
Copy link
Contributor

sourcegraph-bot commented Aug 22, 2023

📖 Storybook live preview

@varsanojidan varsanojidan requested a review from a team August 22, 2023 23:13
Copy link
Contributor

@indradhanush indradhanush left a comment

Choose a reason for hiding this comment

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

LGTM. Left a few minor comments.

Comment on lines 100 to 109
codeHost, err := r.db.CodeHosts().GetByID(ctx, codeHostID)
if err != nil {
return nil, err
}
codeHost.APIRateLimitQuota = &args.Input.APIQuota
codeHost.APIRateLimitIntervalSeconds = &args.Input.APIReplenishmentIntervalSeconds
codeHost.GitRateLimitQuota = &args.Input.GitQuota
codeHost.GitRateLimitIntervalSeconds = &args.Input.GitReplenishmentIntervalSeconds

err = r.db.CodeHosts().Update(ctx, codeHost)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be in a transaction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it initially and decided against it because since this is a full update of the codehost you wont end up in weird half-states, the worst would be if the codehost was deleted between the GetByID and Update, which would just make the update fail. But it is probably better to use a transaction here, i'll change it.

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.

Create GraphQL resolvers for modifying rate limit configurations

5 participants