Skip to content

Commit

Permalink
disable ratelimiter on SpendUsage
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Dec 5, 2023
1 parent 1ffe10b commit b4cb876
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 8 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,14 @@ func (c *Client) SpendQuota(ctx context.Context, quota *proto.AccessQuota, compu

// check rate limit
if !middleware.IsSkipRateLimit(ctx) {
result, err := c.rateLimiter.RateLimit(ctx, key, int(computeUnits), RateLimit{Rate: cfg.RateLimit, Period: time.Minute})
if err != nil {
return false, err
}
if result.Allowed == 0 {
return false, proto.ErrLimitExceeded
}
// NOTE: c.rateLimiter.RateLimit is broken, so going to omit it.
// result, err := c.rateLimiter.RateLimit(ctx, key, int(computeUnits), RateLimit{Rate: cfg.RateLimit, Period: time.Minute})
// if err != nil {
// return false, fmt.Errorf("spendQuota rate limit error: %w", err)
// }
// if result.Allowed == 0 {
// return false, fmt.Errorf("spendQuota: %w", proto.ErrLimitExceeded)
// }
}

for i := time.Duration(0); i < 3; i++ {
Expand Down
1 change: 1 addition & 0 deletions ratelimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type redisRateLimit struct {
client *redis_rate.Limiter
}

// NOTE: this method is broken, so going to skip it entirely for now.
func (r *redisRateLimit) RateLimit(ctx context.Context, key string, computeUnits int, l RateLimit) (*RateLimitResult, error) {
res, err := r.client.AllowN(ctx, key, redis_rate.Limit{Rate: int(l.Rate), Period: l.Period, Burst: int(l.Rate)}, computeUnits)
if err != nil {
Expand Down

0 comments on commit b4cb876

Please sign in to comment.