From dc5934f58456d95b0264665871c0c48e16ee6469 Mon Sep 17 00:00:00 2001 From: Mike Danese Date: Tue, 7 Jan 2020 08:48:25 -0800 Subject: [PATCH] token cache: make fetch_total a counter Downstreams assume process restarts when counters decrement. Currently, the "active" label is expected to decrement but the "ok" and "error" labels are intended to be handled as counters. This is unneccesary and hard to deal with. This changes consolidate "blocking" and "in_flight" tracking into a single guage, which allows fetch completion to be a pure counter. --- .../pkg/authentication/token/cache/stats.go | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/stats.go b/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/stats.go index 50f01395920..dbe745718e7 100644 --- a/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/stats.go +++ b/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/stats.go @@ -42,8 +42,8 @@ var ( }, []string{"status"}, ) - fetchCount = metrics.NewGaugeVec( - &metrics.GaugeOpts{ + fetchCount = metrics.NewCounterVec( + &metrics.CounterOpts{ Namespace: "authentication", Subsystem: "token_cache", Name: "fetch_total", @@ -51,13 +51,14 @@ var ( }, []string{"status"}, ) - blockCount = metrics.NewGauge( + activeFetchCount = metrics.NewGaugeVec( &metrics.GaugeOpts{ Namespace: "authentication", Subsystem: "token_cache", - Name: "block_count", + Name: "active_fetch_count", StabilityLevel: metrics.ALPHA, }, + []string{"status"}, ) ) @@ -66,7 +67,7 @@ func init() { requestLatency, requestCount, fetchCount, - blockCount, + activeFetchCount, ) } @@ -74,9 +75,11 @@ const ( hitTag = "hit" missTag = "miss" - fetchActiveTag = "active" fetchFailedTag = "error" fetchOkTag = "ok" + + fetchInFlightTag = "in_flight" + fetchBlockedTag = "blocked" ) type statsCollector struct{} @@ -101,12 +104,12 @@ func (statsCollector) authenticating() func(hit bool) { } func (statsCollector) blocking() func() { - blockCount.Inc() - return blockCount.Dec + activeFetchCount.WithLabelValues(fetchBlockedTag).Inc() + return activeFetchCount.WithLabelValues(fetchBlockedTag).Dec } func (statsCollector) fetching() func(ok bool) { - fetchCount.WithLabelValues(fetchActiveTag).Inc() + activeFetchCount.WithLabelValues(fetchInFlightTag).Inc() return func(ok bool) { var tag string if ok { @@ -115,6 +118,8 @@ func (statsCollector) fetching() func(ok bool) { tag = fetchFailedTag } - fetchCount.WithLabelValues(tag).Dec() + fetchCount.WithLabelValues(tag).Inc() + + activeFetchCount.WithLabelValues(fetchInFlightTag).Dec() } }