mirror of
https://github.com/hashicorp/vault.git
synced 2025-11-21 02:31:11 +01:00
* Token gauge metrics implementation. * Enable gauges only when interval is nonzero. * Added count by TTL * Yandle "in restore mode" error specifically. * Refactored initialization code for gauge collection processes. * Fixed for multiple namespaces. * Ability to disable individual gauges with environment variable. * changelog++
40 lines
751 B
Go
40 lines
751 B
Go
package metricsutil
|
|
|
|
import (
|
|
"sort"
|
|
"time"
|
|
)
|
|
|
|
var bucketBoundaries = []struct {
|
|
Value time.Duration
|
|
Label string
|
|
}{
|
|
{1 * time.Minute, "1m"},
|
|
{10 * time.Minute, "10m"},
|
|
{20 * time.Minute, "20m"},
|
|
{1 * time.Hour, "1h"},
|
|
{2 * time.Hour, "2h"},
|
|
{24 * time.Hour, "1d"},
|
|
{2 * 24 * time.Hour, "2d"},
|
|
{7 * 24 * time.Hour, "7d"},
|
|
{30 * 24 * time.Hour, "30d"},
|
|
}
|
|
|
|
const OverflowBucket = "+Inf"
|
|
|
|
// TTLBucket computes the label to apply for a token TTL.
|
|
func TTLBucket(ttl time.Duration) string {
|
|
upperBound := sort.Search(
|
|
len(bucketBoundaries),
|
|
func(i int) bool {
|
|
return ttl <= bucketBoundaries[i].Value
|
|
},
|
|
)
|
|
if upperBound >= len(bucketBoundaries) {
|
|
return OverflowBucket
|
|
} else {
|
|
return bucketBoundaries[upperBound].Label
|
|
}
|
|
|
|
}
|