mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Change storage metrics to conform guideline
This commit is contained in:
parent
5252352ad8
commit
47938c3733
@ -25,37 +25,37 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
cacheHitCounterOpts = prometheus.CounterOpts{
|
cacheHitCounterOpts = prometheus.CounterOpts{
|
||||||
Name: "etcd_helper_cache_hit_count",
|
Name: "etcd_helper_cache_hit_total",
|
||||||
Help: "Counter of etcd helper cache hits.",
|
Help: "Counter of etcd helper cache hits.",
|
||||||
}
|
}
|
||||||
cacheHitCounter = prometheus.NewCounter(cacheHitCounterOpts)
|
cacheHitCounter = prometheus.NewCounter(cacheHitCounterOpts)
|
||||||
cacheMissCounterOpts = prometheus.CounterOpts{
|
cacheMissCounterOpts = prometheus.CounterOpts{
|
||||||
Name: "etcd_helper_cache_miss_count",
|
Name: "etcd_helper_cache_miss_total",
|
||||||
Help: "Counter of etcd helper cache miss.",
|
Help: "Counter of etcd helper cache miss.",
|
||||||
}
|
}
|
||||||
cacheMissCounter = prometheus.NewCounter(cacheMissCounterOpts)
|
cacheMissCounter = prometheus.NewCounter(cacheMissCounterOpts)
|
||||||
cacheEntryCounterOpts = prometheus.CounterOpts{
|
cacheEntryCounterOpts = prometheus.CounterOpts{
|
||||||
Name: "etcd_helper_cache_entry_count",
|
Name: "etcd_helper_cache_entry_total",
|
||||||
Help: "Counter of etcd helper cache entries. This can be different from etcd_helper_cache_miss_count " +
|
Help: "Counter of etcd helper cache entries. This can be different from etcd_helper_cache_miss_count " +
|
||||||
"because two concurrent threads can miss the cache and generate the same entry twice.",
|
"because two concurrent threads can miss the cache and generate the same entry twice.",
|
||||||
}
|
}
|
||||||
cacheEntryCounter = prometheus.NewCounter(cacheEntryCounterOpts)
|
cacheEntryCounter = prometheus.NewCounter(cacheEntryCounterOpts)
|
||||||
cacheGetLatency = prometheus.NewSummary(
|
cacheGetLatency = prometheus.NewSummary(
|
||||||
prometheus.SummaryOpts{
|
prometheus.SummaryOpts{
|
||||||
Name: "etcd_request_cache_get_latencies_summary",
|
Name: "etcd_request_cache_get_latency_seconds",
|
||||||
Help: "Latency in microseconds of getting an object from etcd cache",
|
Help: "Latency in seconds of getting an object from etcd cache",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
cacheAddLatency = prometheus.NewSummary(
|
cacheAddLatency = prometheus.NewSummary(
|
||||||
prometheus.SummaryOpts{
|
prometheus.SummaryOpts{
|
||||||
Name: "etcd_request_cache_add_latencies_summary",
|
Name: "etcd_request_cache_add_latency_seconds",
|
||||||
Help: "Latency in microseconds of adding an object to etcd cache",
|
Help: "Latency in seconds of adding an object to etcd cache",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
etcdRequestLatenciesSummary = prometheus.NewSummaryVec(
|
etcdRequestLatenciesSummary = prometheus.NewSummaryVec(
|
||||||
prometheus.SummaryOpts{
|
prometheus.SummaryOpts{
|
||||||
Name: "etcd_request_latencies_summary",
|
Name: "etcd_request_latency_seconds",
|
||||||
Help: "Etcd request latency summary in microseconds for each operation and object type.",
|
Help: "Etcd request latency summary in seconds for each operation and object type.",
|
||||||
},
|
},
|
||||||
[]string{"operation", "type"},
|
[]string{"operation", "type"},
|
||||||
)
|
)
|
||||||
@ -66,6 +66,42 @@ var (
|
|||||||
},
|
},
|
||||||
[]string{"resource"},
|
[]string{"resource"},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
deprecatedCacheHitCounterOpts = prometheus.CounterOpts{
|
||||||
|
Name: "etcd_helper_cache_hit_count",
|
||||||
|
Help: "Counter of etcd helper cache hits.",
|
||||||
|
}
|
||||||
|
deprecatedCacheHitCounter = prometheus.NewCounter(deprecatedCacheHitCounterOpts)
|
||||||
|
deprecatedCacheMissCounterOpts = prometheus.CounterOpts{
|
||||||
|
Name: "etcd_helper_cache_miss_count",
|
||||||
|
Help: "Counter of etcd helper cache miss.",
|
||||||
|
}
|
||||||
|
deprecatedCacheMissCounter = prometheus.NewCounter(deprecatedCacheMissCounterOpts)
|
||||||
|
deprecatedCacheEntryCounterOpts = prometheus.CounterOpts{
|
||||||
|
Name: "etcd_helper_cache_entry_count",
|
||||||
|
Help: "Counter of etcd helper cache entries. This can be different from etcd_helper_cache_miss_count " +
|
||||||
|
"because two concurrent threads can miss the cache and generate the same entry twice.",
|
||||||
|
}
|
||||||
|
deprecatedCacheEntryCounter = prometheus.NewCounter(deprecatedCacheEntryCounterOpts)
|
||||||
|
deprecatedCacheGetLatency = prometheus.NewSummary(
|
||||||
|
prometheus.SummaryOpts{
|
||||||
|
Name: "etcd_request_cache_get_latencies_summary",
|
||||||
|
Help: "Latency in microseconds of getting an object from etcd cache",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
deprecatedCacheAddLatency = prometheus.NewSummary(
|
||||||
|
prometheus.SummaryOpts{
|
||||||
|
Name: "etcd_request_cache_add_latencies_summary",
|
||||||
|
Help: "Latency in microseconds of adding an object to etcd cache",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
deprecatedEtcdRequestLatenciesSummary = prometheus.NewSummaryVec(
|
||||||
|
prometheus.SummaryOpts{
|
||||||
|
Name: "etcd_request_latencies_summary",
|
||||||
|
Help: "Etcd request latency summary in microseconds for each operation and object type.",
|
||||||
|
},
|
||||||
|
[]string{"operation", "type"},
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
var registerMetrics sync.Once
|
var registerMetrics sync.Once
|
||||||
@ -81,6 +117,14 @@ func Register() {
|
|||||||
prometheus.MustRegister(cacheGetLatency)
|
prometheus.MustRegister(cacheGetLatency)
|
||||||
prometheus.MustRegister(etcdRequestLatenciesSummary)
|
prometheus.MustRegister(etcdRequestLatenciesSummary)
|
||||||
prometheus.MustRegister(objectCounts)
|
prometheus.MustRegister(objectCounts)
|
||||||
|
|
||||||
|
// TODO(danielqsj): Remove the following metrics, they are deprecated
|
||||||
|
prometheus.MustRegister(deprecatedCacheHitCounter)
|
||||||
|
prometheus.MustRegister(deprecatedCacheMissCounter)
|
||||||
|
prometheus.MustRegister(deprecatedCacheEntryCounter)
|
||||||
|
prometheus.MustRegister(deprecatedCacheAddLatency)
|
||||||
|
prometheus.MustRegister(deprecatedCacheGetLatency)
|
||||||
|
prometheus.MustRegister(deprecatedEtcdRequestLatenciesSummary)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,27 +133,33 @@ func UpdateObjectCount(resourcePrefix string, count int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RecordEtcdRequestLatency(verb, resource string, startTime time.Time) {
|
func RecordEtcdRequestLatency(verb, resource string, startTime time.Time) {
|
||||||
etcdRequestLatenciesSummary.WithLabelValues(verb, resource).Observe(float64(time.Since(startTime) / time.Microsecond))
|
etcdRequestLatenciesSummary.WithLabelValues(verb, resource).Observe(sinceInSeconds(startTime))
|
||||||
|
deprecatedEtcdRequestLatenciesSummary.WithLabelValues(verb, resource).Observe(sinceInMicroseconds(startTime))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ObserveGetCache(startTime time.Time) {
|
func ObserveGetCache(startTime time.Time) {
|
||||||
cacheGetLatency.Observe(float64(time.Since(startTime) / time.Microsecond))
|
cacheGetLatency.Observe(sinceInSeconds(startTime))
|
||||||
|
deprecatedCacheGetLatency.Observe(sinceInMicroseconds(startTime))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ObserveAddCache(startTime time.Time) {
|
func ObserveAddCache(startTime time.Time) {
|
||||||
cacheAddLatency.Observe(float64(time.Since(startTime) / time.Microsecond))
|
cacheAddLatency.Observe(sinceInSeconds(startTime))
|
||||||
|
deprecatedCacheAddLatency.Observe(sinceInMicroseconds(startTime))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ObserveCacheHit() {
|
func ObserveCacheHit() {
|
||||||
cacheHitCounter.Inc()
|
cacheHitCounter.Inc()
|
||||||
|
deprecatedCacheHitCounter.Inc()
|
||||||
}
|
}
|
||||||
|
|
||||||
func ObserveCacheMiss() {
|
func ObserveCacheMiss() {
|
||||||
cacheMissCounter.Inc()
|
cacheMissCounter.Inc()
|
||||||
|
deprecatedCacheMissCounter.Inc()
|
||||||
}
|
}
|
||||||
|
|
||||||
func ObserveNewEntry() {
|
func ObserveNewEntry() {
|
||||||
cacheEntryCounter.Inc()
|
cacheEntryCounter.Inc()
|
||||||
|
deprecatedCacheEntryCounter.Inc()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Reset() {
|
func Reset() {
|
||||||
@ -119,4 +169,19 @@ func Reset() {
|
|||||||
// TODO: Reset cacheAddLatency.
|
// TODO: Reset cacheAddLatency.
|
||||||
// TODO: Reset cacheGetLatency.
|
// TODO: Reset cacheGetLatency.
|
||||||
etcdRequestLatenciesSummary.Reset()
|
etcdRequestLatenciesSummary.Reset()
|
||||||
|
|
||||||
|
deprecatedCacheHitCounter = prometheus.NewCounter(deprecatedCacheHitCounterOpts)
|
||||||
|
deprecatedCacheMissCounter = prometheus.NewCounter(deprecatedCacheMissCounterOpts)
|
||||||
|
deprecatedCacheEntryCounter = prometheus.NewCounter(deprecatedCacheEntryCounterOpts)
|
||||||
|
deprecatedEtcdRequestLatenciesSummary.Reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
// sinceInMicroseconds gets the time since the specified start in microseconds.
|
||||||
|
func sinceInMicroseconds(start time.Time) float64 {
|
||||||
|
return float64(time.Since(start).Nanoseconds() / time.Microsecond.Nanoseconds())
|
||||||
|
}
|
||||||
|
|
||||||
|
// sinceInSeconds gets the time since the specified start in seconds.
|
||||||
|
func sinceInSeconds(start time.Time) float64 {
|
||||||
|
return time.Since(start).Seconds()
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,18 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
transformerLatencies = prometheus.NewHistogramVec(
|
transformerLatencies = prometheus.NewHistogramVec(
|
||||||
|
prometheus.HistogramOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "transformation_latencies_seconds",
|
||||||
|
Help: "Latencies in seconds of value transformation operations.",
|
||||||
|
// In-process transformations (ex. AES CBC) complete on the order of 20 microseconds. However, when
|
||||||
|
// external KMS is involved latencies may climb into milliseconds.
|
||||||
|
Buckets: prometheus.ExponentialBuckets(5e-6, 2, 14),
|
||||||
|
},
|
||||||
|
[]string{"transformation_type"},
|
||||||
|
)
|
||||||
|
deprecatedTransformerLatencies = prometheus.NewHistogramVec(
|
||||||
prometheus.HistogramOpts{
|
prometheus.HistogramOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Subsystem: subsystem,
|
Subsystem: subsystem,
|
||||||
@ -61,6 +73,15 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
dataKeyGenerationLatencies = prometheus.NewHistogram(
|
dataKeyGenerationLatencies = prometheus.NewHistogram(
|
||||||
|
prometheus.HistogramOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "data_key_generation_latencies_seconds",
|
||||||
|
Help: "Latencies in seconds of data encryption key(DEK) generation operations.",
|
||||||
|
Buckets: prometheus.ExponentialBuckets(5e-6, 2, 14),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
deprecatedDataKeyGenerationLatencies = prometheus.NewHistogram(
|
||||||
prometheus.HistogramOpts{
|
prometheus.HistogramOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Subsystem: subsystem,
|
Subsystem: subsystem,
|
||||||
@ -84,9 +105,11 @@ var registerMetrics sync.Once
|
|||||||
func RegisterMetrics() {
|
func RegisterMetrics() {
|
||||||
registerMetrics.Do(func() {
|
registerMetrics.Do(func() {
|
||||||
prometheus.MustRegister(transformerLatencies)
|
prometheus.MustRegister(transformerLatencies)
|
||||||
|
prometheus.MustRegister(deprecatedTransformerLatencies)
|
||||||
prometheus.MustRegister(transformerFailuresTotal)
|
prometheus.MustRegister(transformerFailuresTotal)
|
||||||
prometheus.MustRegister(envelopeTransformationCacheMissTotal)
|
prometheus.MustRegister(envelopeTransformationCacheMissTotal)
|
||||||
prometheus.MustRegister(dataKeyGenerationLatencies)
|
prometheus.MustRegister(dataKeyGenerationLatencies)
|
||||||
|
prometheus.MustRegister(deprecatedDataKeyGenerationLatencies)
|
||||||
prometheus.MustRegister(dataKeyGenerationFailuresTotal)
|
prometheus.MustRegister(dataKeyGenerationFailuresTotal)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -98,8 +121,8 @@ func RecordTransformation(transformationType string, start time.Time, err error)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
since := sinceInMicroseconds(start)
|
transformerLatencies.WithLabelValues(transformationType).Observe(sinceInSeconds(start))
|
||||||
transformerLatencies.WithLabelValues(transformationType).Observe(float64(since))
|
deprecatedTransformerLatencies.WithLabelValues(transformationType).Observe(sinceInMicroseconds(start))
|
||||||
}
|
}
|
||||||
|
|
||||||
// RecordCacheMiss records a miss on Key Encryption Key(KEK) - call to KMS was required to decrypt KEK.
|
// RecordCacheMiss records a miss on Key Encryption Key(KEK) - call to KMS was required to decrypt KEK.
|
||||||
@ -114,11 +137,16 @@ func RecordDataKeyGeneration(start time.Time, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
since := sinceInMicroseconds(start)
|
dataKeyGenerationLatencies.Observe(sinceInSeconds(start))
|
||||||
dataKeyGenerationLatencies.Observe(float64(since))
|
deprecatedDataKeyGenerationLatencies.Observe(sinceInMicroseconds(start))
|
||||||
}
|
}
|
||||||
|
|
||||||
func sinceInMicroseconds(start time.Time) int64 {
|
// sinceInMicroseconds gets the time since the specified start in microseconds.
|
||||||
elapsedNanoseconds := time.Since(start).Nanoseconds()
|
func sinceInMicroseconds(start time.Time) float64 {
|
||||||
return elapsedNanoseconds / int64(time.Microsecond)
|
return float64(time.Since(start).Nanoseconds() / time.Microsecond.Nanoseconds())
|
||||||
|
}
|
||||||
|
|
||||||
|
// sinceInSeconds gets the time since the specified start in seconds.
|
||||||
|
func sinceInSeconds(start time.Time) float64 {
|
||||||
|
return time.Since(start).Seconds()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user