Skip to content

Commit

Permalink
One small change.
Browse files Browse the repository at this point in the history
  • Loading branch information
beautifulentropy committed Aug 22, 2023
1 parent 4b8ae98 commit ba348be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions ratelimits/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ type limit struct {
// precomputed to avoid doing the same calculation on every request.
burstOffset int64

// isOverridden is true if this limit is an override limit, false if it is a
// isOverride is true if this limit is an override limit, false if it is a
// default limit.
isOverridden bool
isOverride bool
}

func precomputeLimit(l limit) limit {
Expand Down Expand Up @@ -135,7 +135,7 @@ func loadAndParseOverrideLimits(path string) (limits, error) {
fqdnSet := core.HashNames(domains)
id = fmt.Sprintf("%s:%s", regId, fqdnSet)
}
v.isOverridden = true
v.isOverride = true
parsed[bucketKey(name, id)] = precomputeLimit(v)
}
return parsed, nil
Expand Down
5 changes: 3 additions & 2 deletions ratelimits/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ func (l *Limiter) Spend(ctx context.Context, name Name, id string, cost int64) (

d := maybeSpend(l.clk, limit, tat, cost)

if limit.isOverridden {
// Calculate the proportion of the override limit used.
if limit.isOverride {
// Calculate the current utilization of the override limit for the
// specified client id.
utilization := float64(limit.Burst-d.Remaining) / float64(limit.Burst)
l.overrideUsageGauge.WithLabelValues(nameToString[name], id).Set(utilization)
}
Expand Down

0 comments on commit ba348be

Please sign in to comment.