Files
threshold/internal/ratelimit/metrics.go
T
Timothy Messier 3c2bed92b0 feat(ratelimit): Expose metrics on quota usage
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.
2023-12-04 16:24:04 +00:00

44 lines
1.1 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package ratelimit
import (
"github.com/hashicorp/boundary/globals"
"github.com/prometheus/client_golang/prometheus"
)
const (
subsystem = "controller_api_ratelimiter"
)
var (
rateLimitQuotaStorageCapacity prometheus.Gauge = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: globals.MetricNamespace,
Subsystem: subsystem,
Name: "quota_storage_capacity",
Help: "Guague of the number if quotas that can be stored by the rate limiter",
},
)
rateLimitQuotaUsage prometheus.Gauge = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: globals.MetricNamespace,
Subsystem: subsystem,
Name: "quota_storage_usage",
Help: "Guague of the number if quotas that are currently being stored by the rate limiter",
},
)
)
// InitializeMetrics initializes the metrics for visibility into the rate limiter.
func InitializeMetrics(r prometheus.Registerer) {
if r == nil {
return
}
r.MustRegister(
rateLimitQuotaStorageCapacity,
rateLimitQuotaUsage,
)
}