mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Instrument transformer.go with latency metrics.
This commit is contained in:
parent
04a6613fb5
commit
bfcb3cd91f
@ -23,16 +23,16 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
valueSubsystem = "value"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
TransformerOperationalLatencies = prometheus.NewSummaryVec(
|
transformerLatencies = prometheus.NewHistogramVec(
|
||||||
prometheus.SummaryOpts{
|
prometheus.HistogramOpts{
|
||||||
Subsystem: valueSubsystem,
|
Namespace: "apiserver",
|
||||||
Name: "apiserver_storage_transformation_latency_microseconds",
|
Subsystem: "storage",
|
||||||
Help: "Latency in microseconds of value transformation operations.",
|
Name: "transformation_latencies_microseconds",
|
||||||
|
Help: "Latencies in microseconds 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(5, 2, 14),
|
||||||
},
|
},
|
||||||
[]string{"transformation_type"},
|
[]string{"transformation_type"},
|
||||||
)
|
)
|
||||||
@ -42,14 +42,16 @@ var registerMetrics sync.Once
|
|||||||
|
|
||||||
func RegisterMetrics() {
|
func RegisterMetrics() {
|
||||||
registerMetrics.Do(func() {
|
registerMetrics.Do(func() {
|
||||||
prometheus.MustRegister(TransformerOperationalLatencies)
|
prometheus.MustRegister(transformerLatencies)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func RecordTransformation(transformationType string, start time.Time) {
|
func RecordTransformation(transformationType string, start time.Time) {
|
||||||
TransformerOperationalLatencies.WithLabelValues(transformationType).Observe(float64(sinceInMicroseconds(start)))
|
since := sinceInMicroseconds(start)
|
||||||
|
transformerLatencies.WithLabelValues(transformationType).Observe(float64(since))
|
||||||
}
|
}
|
||||||
|
|
||||||
func sinceInMicroseconds(start time.Time) time.Duration {
|
func sinceInMicroseconds(start time.Time) int64 {
|
||||||
return time.Since(start) / time.Microsecond
|
elapsedNanoseconds := time.Since(start).Nanoseconds()
|
||||||
|
return elapsedNanoseconds / int64(time.Microsecond)
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ const (
|
|||||||
encryptionConfigFileName = "encryption.conf"
|
encryptionConfigFileName = "encryption.conf"
|
||||||
testNamespace = "secret-encryption-test"
|
testNamespace = "secret-encryption-test"
|
||||||
testSecret = "test-secret"
|
testSecret = "test-secret"
|
||||||
latencySummaryMetricsFamily = "value_apiserver_storage_transformation_latency_microseconds"
|
latencySummaryMetricsFamily = "apiserver_storage_transformation_latencies_microseconds"
|
||||||
)
|
)
|
||||||
|
|
||||||
type unSealSecret func(cipherText []byte, ctx value.Context, config encryptionconfig.ProviderConfig) ([]byte, error)
|
type unSealSecret func(cipherText []byte, ctx value.Context, config encryptionconfig.ProviderConfig) ([]byte, error)
|
||||||
@ -248,7 +248,6 @@ func (e *transformTest) printMetrics() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
metricsOfInterest := []string{latencySummaryMetricsFamily}
|
metricsOfInterest := []string{latencySummaryMetricsFamily}
|
||||||
|
|
||||||
for _, mf := range metrics {
|
for _, mf := range metrics {
|
||||||
if contains(metricsOfInterest, *mf.Name) {
|
if contains(metricsOfInterest, *mf.Name) {
|
||||||
for _, metric := range mf.GetMetric() {
|
for _, metric := range mf.GetMetric() {
|
||||||
|
Loading…
Reference in New Issue
Block a user