mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #36704 from fabxc/client-metrics2
Automatic merge from submit-queue Use Prometheus instrumentation conventions The `System` and `Subsystem` parameters are subject to removal. (x-ref: https://github.com/prometheus/client_golang/issues/240) All metrics should use base units, which is seconds in the duration case. Counters should always end in `_total` and metrics should avoid referring to potential label dimensions. Those should rather be mentioned in the documentation string. @kubernetes/sig-instrumentation Reference docs: https://prometheus.io/docs/practices/instrumentation/ https://prometheus.io/docs/practices/naming/ **Release note**: ``` Breaking change: Renamed REST client Prometheus metrics to follow the instrumentation conventions ("request_latency_microseconds" -> "rest_client_request_latency_seconds", "request_status_codes" -> "rest_client_requests_total"). Please update your alerting pipeline if you rely on them. ```
This commit is contained in:
commit
18ffc95308
@ -27,26 +27,22 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const restClientSubsystem = "rest_client"
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// requestLatency is a Prometheus Summary metric type partitioned by
|
// requestLatency is a Prometheus Summary metric type partitioned by
|
||||||
// "verb" and "url" labels. It is used for the rest client latency metrics.
|
// "verb" and "url" labels. It is used for the rest client latency metrics.
|
||||||
requestLatency = prometheus.NewSummaryVec(
|
requestLatency = prometheus.NewHistogramVec(
|
||||||
prometheus.SummaryOpts{
|
prometheus.HistogramOpts{
|
||||||
Subsystem: restClientSubsystem,
|
Name: "rest_client_request_latency_seconds",
|
||||||
Name: "request_latency_microseconds",
|
Help: "Request latency in seconds. Broken down by verb and URL.",
|
||||||
Help: "Request latency in microseconds. Broken down by verb and URL",
|
Buckets: prometheus.ExponentialBuckets(0.001, 2, 10),
|
||||||
MaxAge: time.Hour,
|
|
||||||
},
|
},
|
||||||
[]string{"verb", "url"},
|
[]string{"verb", "url"},
|
||||||
)
|
)
|
||||||
|
|
||||||
requestResult = prometheus.NewCounterVec(
|
requestResult = prometheus.NewCounterVec(
|
||||||
prometheus.CounterOpts{
|
prometheus.CounterOpts{
|
||||||
Subsystem: restClientSubsystem,
|
Name: "rest_client_requests_total",
|
||||||
Name: "request_status_codes",
|
Help: "Number of HTTP requests, partitioned by status code, method, and host.",
|
||||||
Help: "Number of http requests, partitioned by metadata",
|
|
||||||
},
|
},
|
||||||
[]string{"code", "method", "host"},
|
[]string{"code", "method", "host"},
|
||||||
)
|
)
|
||||||
@ -59,12 +55,11 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type latencyAdapter struct {
|
type latencyAdapter struct {
|
||||||
m *prometheus.SummaryVec
|
m *prometheus.HistogramVec
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *latencyAdapter) Observe(verb string, u url.URL, latency time.Duration) {
|
func (l *latencyAdapter) Observe(verb string, u url.URL, latency time.Duration) {
|
||||||
microseconds := float64(latency) / float64(time.Microsecond)
|
l.m.WithLabelValues(verb, u.String()).Observe(latency.Seconds())
|
||||||
l.m.WithLabelValues(verb, u.String()).Observe(microseconds)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type resultAdapter struct {
|
type resultAdapter struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user