This provides two prometheus metrics to monitor the rate limiter: boundary_controller_api_ratelimiter_quota_storage_capacity: This is a gague that shows the total number of quotas that can be stored at a given moment by the rate limiter. boundary_controller_api_ratelimiter_quota_storage_usage: This is a gague that shows the number of quotas currently being stored by the limiter. If this becomes equal to the capacity, requests that would result in a new quota being created will get limited and receive a 429 status code.
17 lines
427 B
Go
17 lines
427 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package ratelimit
|
|
|
|
import "github.com/hashicorp/go-rate"
|
|
|
|
// NewLimiter creates a rate.Limiter.
|
|
func NewLimiter(limits []*rate.Limit, maxEntries int) (*rate.Limiter, error) {
|
|
return rate.NewLimiter(
|
|
limits,
|
|
maxEntries,
|
|
rate.WithQuotaStorageUsageMetric(rateLimitQuotaUsage),
|
|
rate.WithQuotaStorageCapacityMetric(rateLimitQuotaStorageCapacity),
|
|
)
|
|
}
|