Conversation
The Github client now is created with two layers on top of it: - The first one is a private LRU cache, using httpcache, that will check for stored requests/responses and will serve those if needed - The second layer is a rate limiter, using the rate package, that will allow to perform, with the default configuration, 10 requests per second
| github.com/gorilla/mux v1.7.4 | ||
| github.com/heroku/docker-registry-client v0.0.0-20190909225348-afc9e1acc3d5 | ||
| github.com/jarcoal/httpmock v1.0.5 | ||
| github.com/m4ns0ur/httpcache v0.0.0-20200426190423-1040e2e8823f |
There was a problem hiding this comment.
We need this fork/fix until is merged in master
We need a new method that allows as to pass the limiter in order to test it and also can be used to create a different client with different rate limiting policy
agnivade
left a comment
There was a problem hiding this comment.
Amazing piece of work! Just some small comments to take care of.
metanerd
left a comment
There was a problem hiding this comment.
Smart testing and awesome work! Thank you so much @ethervoid ! This will resolve a ton of issues we are having currently! I added some minor suggestions/nits which you can also just ignore/dismiss.
server/github_test.go
Outdated
| body := &github.Reference{Object: &github.GitObject{}} | ||
| err := json.Unmarshal([]byte(testGetRefReturn), &body) | ||
| require.NoError(t, err) | ||
| resp, err := httpmock.NewJsonResponse(200, body) |
There was a problem hiding this comment.
My IDE says resp could be nil.
There was a problem hiding this comment.
Since there are 2 needed responses in this test series, IMO it would improve readability by naming them resp1 and resp2 to make the scheme more obvious. Or put in the name which kind of response it should be. I know golang wants short variable names, but personally, I find it more readable that way, instead of having to read the comment. This is just a suggestion/nit. I leave it up to you.
There was a problem hiding this comment.
Can these tests be run in parallel?
There was a problem hiding this comment.
In this case, resp is not possible to be nil because we're providing the elements, so no need to check for nil here.
Changing literal 200 for http.StatusOK is a great suggestion and I've included it. Thank you!
Can these tests be run in parallel?
Could be done but given the time spent by these tests, we don't need now to execute them in parallel
server/github_test.go
Outdated
| body := &github.Reference{Object: &github.GitObject{}} | ||
| err := json.Unmarshal([]byte(testGetRefReturn), &body) | ||
| require.NoError(t, err) | ||
| resp, err := httpmock.NewJsonResponse(200, body) |
There was a problem hiding this comment.
Is there a convention? http.StatusOK or 200? So that I know for my future code.
agnivade
left a comment
There was a problem hiding this comment.
Nice. So demo next week? ;)
Co-authored-by: Agniva De Sarker <[email protected]>
|
@agnivade hahaha yeah sure :D |
|
@ethervoid - Something caught my eye. Any reason the default is set to 10? From what I seeing here https://github.com/google/go-github#rate-limiting, it should be around 1.3. Perhaps then we need to split out the rate with the burst and have 2 separate flags? The word @metanerd - Just heads up that the |
|
@agnivade Yes but is being used to provided limit and burst token at the same time. With 10 you get 10 requests/second and 10 burst tokens. We shouldn't limit to the 5000 requests because our rate consumption is not linear so we will be dropping or making requests wait for nothing. And also, taking into account we have the cache as the first layer we shouldn't be reaching the limit. In summary, I rather prefer to have a broader limit and see what happens that put a very tight one |
|
Ah that makes sense. So the current prod setting is 50. Do you suggest it to be 10 then? |
|
@agnivade yes. 10 should be more than enough to work perfectly fine without making a bottleneck |
|
Great. @metanerd - over to you. Please change https://github.com/mattermost/platform-private/blob/375ffed89d8a416604378b2d4512ddc91210028a/mattermod/config-mattermod.json#L8 to 10 and let's deploy. |
|
@agnivade done |
Summary
The Github client now is created with two layers on top of it:
check for stored requests/responses and will serve those if needed
allow performing, with the default configuration, 10 requests per
second
Ticket Link
https://mattermost.atlassian.net/browse/MM-26385