-
Notifications
You must be signed in to change notification settings - Fork 94
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
backend: replace ratelimiter with x/time/rate. #3155
base: master
Are you sure you want to change the base?
Conversation
@benma I made a mess on the other PR trying to merge master into it. I opened a new one with the same diff. I managed to test these changes also on the |
f6692ae
to
d6b1e28
Compare
@benma friendly ping on this 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.
tested and seems to work, but left a few comments
go.mod
Outdated
@@ -22,6 +22,7 @@ require ( | |||
golang.org/x/crypto v0.32.0 | |||
golang.org/x/mobile v0.0.0-20240716161057-1ad2df20a8b6 | |||
golang.org/x/net v0.34.0 | |||
golang.org/x/time v0.5.0 |
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.
why v0.5.0? v0.10.0 is available also (even v0.11.0 is, but that seems to require Go 1.23).
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.
Yeah I'm not sure, I think it was auto-added. Will change it
backend/rates/gecko.go
Outdated
// to one of the supported exchange rates providers. | ||
func apiRateLimit(baseURL string) time.Duration { | ||
func apiRateLimit(baseURL string) float64 { |
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.
make the return type rate.Limit
for clarity? then the callsite does not need to convert either.
backend/rates/rates.go
Outdated
// To stay within acceptable rate limits defined by CoinGeckoRateLimit, callers can | ||
// use util/ratelimit package. | ||
// use https://pkg.go.dev/golang.org/x/time/rate package. |
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.
remove this part? users don't have to do anything, rate limiting is includd in the RatesUpdater
@@ -275,36 +276,42 @@ func (updater *RateUpdater) updateLast(ctx context.Context) { | |||
} | |||
|
|||
var geckoRates map[string]map[string]float64 | |||
callErr := updater.geckoLimiter.Call(ctx, "updateLast", func() error { | |||
ctx, cancel := context.WithTimeout(ctx, 10*time.Second) |
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.
you missed this line below in your http request, which should time out.
backend/rates/rates.go
Outdated
if callErr != nil { | ||
updater.log.WithError(callErr).Errorf("updateLast") | ||
if err := updater.geckoLimiter.Wait(ctx); err != nil { | ||
updater.log.WithError(err).Error("could not wait for rate limiter") |
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.
please prefix all msgs with updateLast:
like it used to be before, so the error is more easily identified in the logs.
// Etherscan rate limits to one request per 0.2 seconds. | ||
var CallInterval = 260 * time.Millisecond | ||
var CallsPerSec = 3.8 |
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.
can unexport this, it's only used locally.
Removes the ratelimiter package and replaces its usages with x/time/rate.
Removes the ratelimiter package and replaces its
usages with x/time/rate.