-
Notifications
You must be signed in to change notification settings - Fork 116
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
feat(robot): handle ratelimiting with constant backoff #572
Conversation
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.
What about using https://pkg.go.dev/github.com/syself/hrobot-go#NewBasicAuthClientWithCustomHttpClient and implement the rate limiter and cache around the http.Client ?
internal/robot/cache.go
Outdated
@@ -21,7 +20,7 @@ type cacheRobotClient struct { | |||
serversByID map[int]*hrobotmodels.Server | |||
} | |||
|
|||
func NewClient(robotClient hrobot.RobotClient, cacheTimeout time.Duration) Client { | |||
func WithCache(cacheTimeout time.Duration, robotClient Client) Client { |
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.
func WithCache(cacheTimeout time.Duration, robotClient Client) Client { | |
func NewCachedClient(robotClient Client, cacheTimeout time.Duration) Client { |
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 put the client last on purpose. I found it pretty confusing to have the client first when nesting, as the argument RateLimitWaitTime
is not next to WithRateLimit
anymore. For comparison:
Client last (current version):
robotClient = robot.WithRateLimit(
robot.WithCache(
cfg.Robot.CacheTimeout,
c
),
cfg.Robot.RateLimitWaitTime,
)
Client first (your suggestion):
robotClient = robot.WithRateLimit(
cfg.Robot.RateLimitWaitTime,
robot.WithCache(
cfg.Robot.CacheTimeout,
c
),
)
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.
No strong opinion on my side, the naming confuses me only because I would not expect to have a new client when I call WithCache
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.
Yea, I updated the naming :) Just did not agree with the changed order of arguments in your suggested replacement. (Sorry, should have been more explicit.)
Add a constant backoff in case we are being rate limited by the Robot API. This is done through an opaque wrapping of the robot.Client interface, so callers do not need to do this manually.
76a0366
to
bdffd66
Compare
IMO both additional features are based on the business logic of the API, rather than the transport mechanism. For caching, we actually only use the list endpoint, and serve For Rate Limiting we would need to parse the response in our middleware once more to evaluate the error, and similarly fake out the http response if we decide not to make a proper request. Implement this on top of the |
🤖 I have created a release *beep* *boop* --- ## [1.19.0-rc.0](v1.18.0...v1.19.0-rc.0) (2023-12-01) ### Features * **chart:** add daemonset and node selector ([#537](#537)) ([a94384f](a94384f)) * **config:** stricter validation for settings `HCLOUD_LOAD_BALANCERS_ENABLED`, `HCLOUD_METRICS_ENABLED` & `HCLOUD_NETWORK_ROUTES_ENABLED` ([#546](#546)) ([335a2c9](335a2c9)) * **helm:** remove "v" prefix from chart version ([#565](#565)) ([f11aa0d](f11aa0d)), closes [#529](#529) * **load-balancer:** handle planned targets exceedings max targets ([#570](#570)) ([8bb131f](8bb131f)) * remove unused variable NODE_NAME ([#545](#545)) ([a659408](a659408)) * **robot:** handle ratelimiting with constant backoff ([#572](#572)) ([2ddc201](2ddc201)) * support for Robot servers ([#561](#561)) ([65dea11](65dea11)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
## [1.19.0](v1.18.0...v1.19.0) (2023-12-07) ### Features * **chart:** add daemonset and node selector ([#537](#537)) ([a94384f](a94384f)) * **config:** stricter validation for settings `HCLOUD_LOAD_BALANCERS_ENABLED`, `HCLOUD_METRICS_ENABLED` & `HCLOUD_NETWORK_ROUTES_ENABLED` ([#546](#546)) ([335a2c9](335a2c9)) * **helm:** remove "v" prefix from chart version ([#565](#565)) ([f11aa0d](f11aa0d)), closes [#529](#529) * **load-balancer:** handle planned targets exceedings max targets ([#570](#570)) ([8bb131f](8bb131f)) * remove unused variable NODE_NAME ([#545](#545)) ([a659408](a659408)) * **robot:** handle ratelimiting with constant backoff ([#572](#572)) ([2ddc201](2ddc201)) * support for Robot servers ([#561](#561)) ([65dea11](65dea11))
Add a constant backoff in case we are being rate limited by the Robot API.
This is done through an opaque wrapping of the
robot.Client
interface, so callers do not need to do this manually.