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. Kubernetes-commit: dc5934f58456d95b0264665871c0c48e16ee6469
This commit is contained in:
parent
77e48ebcf0
commit
5b8058738a
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue