fix: rate limit GitLab requests when fetching tokens #3126
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why does this PR exist?
Originally flagged by members of the community, where the plugin would intermittently fail to fetch all the tokens from their GitLab repository.
Specifically, the calls to the
/projects/*/repository/files/*/raw
endpoint in GitLab, which is used by the plugin when read()ing from the repository.We use the
@gitbeaker/rest
library as a wrapper to interact with GitLab, in this case, the equivalent of calling the above endpoint is whenthis.gitLabClient.RepositoryFiles.showRaw(...)
is invoked. This library offers a rateLimit configuration to be passed to the client.Gathering data
Cloning the user's repository, there were around ~140 requests in .56s (equating to 250 rps) to the
.../raw
endpoint. GitLab's documentation states that "the rate limit on raw endpoints defaults to 300 requests per minute", the same as 5 rps.What does this pull request do?
Adds a
rateLimit
configuration to the GitLab client when it's instantiated:'/projects/*/repository/files/*/raw': 4
(4 rps = 250 requests per minute)The time that it took to wait for all raw files to be fetched below were calculated by using the native time method, 5 runs locally, like so:
1.5s
1.9s
Testing this change
🤔 If someone can test before and after this change, for safety of not slowing down other users too much.