Skip to content

Commit

Permalink
All provisioning calls are rate limited per config. Default is 5 requ…
Browse files Browse the repository at this point in the history
…ests/min per the docs
  • Loading branch information
momer committed May 3, 2024
1 parent e1312f6 commit 0f70ce6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bonsai/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@ type ClusterClient struct {
*Client
}

// Do performs an HTTP request against the API, with any required
// Cluster-specific configuration/limitations - for example, rate limiting.
func (c *ClusterClient) Do(ctx context.Context, req *http.Request) (*Response, error) {
// Allow non-provisioning Cluster endpoint requests to continue
if req.Method != http.MethodPost {
return c.Client.Do(ctx, req)
}

// Limit provision requests
err := c.rateLimiter.provisionLimiter.Wait(ctx)
if err != nil {
// Context canceled, timed-out, burst issue, or other rate limit issue;
// let the callers handle it.
return nil, fmt.Errorf("failed while awaiting execution per rate-limit: %w", err)
}
return c.Client.Do(ctx, req)
}

type ClusterAllOpts struct {
// Optional. A query string for filtering matching clusters.
// This currently works on name.
Expand Down

0 comments on commit 0f70ce6

Please sign in to comment.