-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code search: use code search api #2476
Conversation
const MyOctokit = Octokit.plugin(throttling); | ||
const auth = await credentials.getAccessToken(); | ||
|
||
const octokit = new MyOctokit({ | ||
auth, | ||
throttle: { | ||
onRateLimit: (retryAfter: number, options: any): boolean => { | ||
void showAndLogWarningMessage( | ||
`Request quota exhausted for request ${options.method} ${options.url}. Retrying after ${retryAfter} seconds!`, | ||
); | ||
|
||
return true; | ||
}, | ||
onSecondaryRateLimit: (_retryAfter: number, options: any): void => { | ||
void showAndLogWarningMessage( | ||
`SecondaryRateLimit detected for request ${options.method} ${options.url}`, | ||
); | ||
}, | ||
}, | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curiously I never hit the secondary Rate Limit during testing. However, the RateLimit was hit. Even though throttling was used the maximum entries in one list I ever got with one search was 901.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though throttling was used the maximum entries in one list I ever got with one search was 901.
Is this because of throttling, or because of duplicate repos in the search results? If you didn't hit the secondary rate limit then it means you should have results from all 10 pages, but it's just the total number of unique repositories was 901.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be this certain search query. I tested with some other queries and had different results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was told the search api returns different results when sending the same request multiple times, this doesn't seem to be true for me right now..
013a691
to
92c86bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some thoughts on wording of things, but I've tried this out and it worked for me.
I don't know too much about this throttling
plugin or how the github rate limit behaves, so I can't comment too much on that part right now. If you'd like a deeper review of that part just let me know.
I also found the progress reporting a bit confusing, but it seemed to work well enough in practice when I ran some searches.
const auth = await credentials.getAccessToken(); | ||
|
||
const octokit = new MyOctokit({ | ||
auth, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To copy more closely what we do at
return new Octokit.Octokit({ | |
auth: accessToken, | |
retry, | |
}); |
retry
plugin too. Or is that intentionally missed out? The idea of this plugin is that'll automatically retry requests in cases of a 500 error.
auth, | |
auth, | |
retry, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need the retry plugin here, as the throttle plugin is taking over retrying?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe they deal with different concerns. The retry
plugin will retry in response to 5xx errors. The throttle
plugin will retry in response to 429 (Too many requests) errors and understands GitHub's specific messages.
But seems that in the latest version of provideOctokitWithThrottling
the retry
plugin is included, so that all looks good to me.
}, | ||
onSecondaryRateLimit: (_retryAfter: number, options: any): void => { | ||
void showAndLogWarningMessage( | ||
`SecondaryRateLimit detected for request ${options.method} ${options.url}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`SecondaryRateLimit detected for request ${options.method} ${options.url}`, | |
`Request quota exceeded for request ${options.method} ${options.url}`., |
Just a suggestion to make this error fit with the other one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to distinguish between the two, so that users know what they are hitting specifically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree users should be able to distinguish and understand them. I was meaning more that we could make the language style more consistent between the two error messages. For example:
- In one we say "quota" and in the other we say "limit". Is there a technical different between these I'm not aware of, and will the user know what they mean?
- In one we use full sentences, and in the other we use CamelCase.
However, this is something that can easily be changed afterwards, if time is tight. So it's ok to defer this to a later PR if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took this from the documentation and it copies also a script we have somewhere else in the repo. However you're right with the CamelCase, that's just weird. I fixed the CC and adjusted the wording!
throttle: { | ||
onRateLimit: (retryAfter: number, options: any): boolean => { | ||
void showAndLogWarningMessage( | ||
`Request quota exhausted for request ${options.method} ${options.url}. Retrying after ${retryAfter} seconds!`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first time it retried after 42 seconds for me, after that 0. I don't know why it retries after 0 seconds, this behaviour comes from the plugin. I also found retries after 10, 20 or 7 seconds in the logs, but we would have to check the code of the plugin to find out more.
const MyOctokit = Octokit.plugin(throttling); | ||
const auth = await credentials.getAccessToken(); | ||
|
||
const octokit = new MyOctokit({ | ||
auth, | ||
throttle: { | ||
onRateLimit: (retryAfter: number, options: any): boolean => { | ||
void showAndLogWarningMessage( | ||
`Request quota exhausted for request ${options.method} ${options.url}. Retrying after ${retryAfter} seconds!`, | ||
); | ||
|
||
return true; | ||
}, | ||
onSecondaryRateLimit: (_retryAfter: number, options: any): void => { | ||
void showAndLogWarningMessage( | ||
`SecondaryRateLimit detected for request ${options.method} ${options.url}`, | ||
); | ||
}, | ||
}, | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though throttling was used the maximum entries in one list I ever got with one search was 901.
Is this because of throttling, or because of duplicate repos in the search results? If you didn't hit the secondary rate limit then it means you should have results from all 10 pages, but it's just the total number of unique repositories was 901.
@robertbrignull Reviewing this code I noticed that the gh-api-client file where the |
I think this refactoring makes sense - having the API client related code into one file inside Whether that refactoring is done in this PR or a separate one is something that I'll leave to you and @robertbrignull to decide though 😃 |
bbc6595
to
2ecec54
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, especially given that this is now behind a feature flag.
I did notice a couple of tiny bits we can improve regarding the cancellation token, but we can discuss those outside of this PR. I'll raise issues or discuss them with you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, especially given that this is now behind a feature flag.
I did notice a couple of tiny bits we can improve regarding the cancellation token, but we can discuss those outside of this PR. I'll raise issues or discuss them with you.
2ecec54
to
945594d
Compare
Instead of using repo search we want to use the code search api for this feature. Since the search api returns an error if two language parameters are added we made the entry of a language through the UI optional.
Items:
Checklist
ready-for-doc-review
label there.