Enable Prometheus native histograms (#6524)

Add a NativeHistogramBucketFactor parameter to the use of
`NewHistogramVec` in order to enable use of Prometheus Native
Histograms.

This will store automatically computed sparse buckets in CoreDNS.
If a compatible Prometeus requests native histograms this data will
returned instead of the static buckets.

The default factor of 1.05 should provide high quality resolution data.

Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
Ben Kochie 2024-03-11 21:09:09 +01:00 committed by GitHub
parent a4cbd95795
commit 0d6e113f90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 55 additions and 42 deletions

View file

@ -26,6 +26,7 @@ var (
Subsystem: "grpc", Subsystem: "grpc",
Name: "request_duration_seconds", Name: "request_duration_seconds",
Buckets: plugin.TimeBuckets, Buckets: plugin.TimeBuckets,
NativeHistogramBucketFactor: plugin.NativeHistogramBucketFactor,
Help: "Histogram of the time each request took.", Help: "Histogram of the time each request took.",
}, []string{"to"}) }, []string{"to"})
) )

View file

@ -71,6 +71,7 @@ var (
Subsystem: "health", Subsystem: "health",
Name: "request_duration_seconds", Name: "request_duration_seconds",
Buckets: plugin.SlimTimeBuckets, Buckets: plugin.SlimTimeBuckets,
NativeHistogramBucketFactor: plugin.NativeHistogramBucketFactor,
Help: "Histogram of the time (in seconds) each request took.", Help: "Histogram of the time (in seconds) each request took.",
}) })
// HealthFailures is the metric used to count how many times the health request failed // HealthFailures is the metric used to count how many times the health request failed

View file

@ -21,6 +21,7 @@ var (
Name: "rest_client_request_duration_seconds", Name: "rest_client_request_duration_seconds",
Help: "Request latency in seconds. Broken down by verb and host.", Help: "Request latency in seconds. Broken down by verb and host.",
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
NativeHistogramBucketFactor: plugin.NativeHistogramBucketFactor,
}, },
[]string{"verb", "host"}, []string{"verb", "host"},
) )
@ -33,6 +34,7 @@ var (
Name: "rest_client_rate_limiter_duration_seconds", Name: "rest_client_rate_limiter_duration_seconds",
Help: "Client side rate limiter latency in seconds. Broken down by verb and host.", Help: "Client side rate limiter latency in seconds. Broken down by verb and host.",
Buckets: prometheus.DefBuckets, Buckets: prometheus.DefBuckets,
NativeHistogramBucketFactor: plugin.NativeHistogramBucketFactor,
}, },
[]string{"verb", "host"}, []string{"verb", "host"},
) )

View file

@ -30,6 +30,7 @@ var (
Name: "dns_programming_duration_seconds", Name: "dns_programming_duration_seconds",
// From 1 millisecond to ~17 minutes. // From 1 millisecond to ~17 minutes.
Buckets: prometheus.ExponentialBuckets(0.001, 2, 20), Buckets: prometheus.ExponentialBuckets(0.001, 2, 20),
NativeHistogramBucketFactor: plugin.NativeHistogramBucketFactor,
Help: "Histogram of the time (in seconds) it took to program a dns instance.", Help: "Histogram of the time (in seconds) it took to program a dns instance.",
}, []string{"service_kind"}) }, []string{"service_kind"})

View file

@ -21,6 +21,7 @@ var (
Subsystem: subsystem, Subsystem: subsystem,
Name: "request_duration_seconds", Name: "request_duration_seconds",
Buckets: plugin.TimeBuckets, Buckets: plugin.TimeBuckets,
NativeHistogramBucketFactor: plugin.NativeHistogramBucketFactor,
Help: "Histogram of the time (in seconds) each request took per zone.", Help: "Histogram of the time (in seconds) each request took per zone.",
}, []string{"server", "zone", "view"}) }, []string{"server", "zone", "view"})
@ -30,6 +31,7 @@ var (
Name: "request_size_bytes", Name: "request_size_bytes",
Help: "Size of the EDNS0 UDP buffer in bytes (64K for TCP) per zone and protocol.", Help: "Size of the EDNS0 UDP buffer in bytes (64K for TCP) per zone and protocol.",
Buckets: []float64{0, 100, 200, 300, 400, 511, 1023, 2047, 4095, 8291, 16e3, 32e3, 48e3, 64e3}, Buckets: []float64{0, 100, 200, 300, 400, 511, 1023, 2047, 4095, 8291, 16e3, 32e3, 48e3, 64e3},
NativeHistogramBucketFactor: plugin.NativeHistogramBucketFactor,
}, []string{"server", "zone", "view", "proto"}) }, []string{"server", "zone", "view", "proto"})
RequestDo = promauto.NewCounterVec(prometheus.CounterOpts{ RequestDo = promauto.NewCounterVec(prometheus.CounterOpts{
@ -45,6 +47,7 @@ var (
Name: "response_size_bytes", Name: "response_size_bytes",
Help: "Size of the returned response in bytes.", Help: "Size of the returned response in bytes.",
Buckets: []float64{0, 100, 200, 300, 400, 511, 1023, 2047, 4095, 8291, 16e3, 32e3, 48e3, 64e3}, Buckets: []float64{0, 100, 200, 300, 400, 511, 1023, 2047, 4095, 8291, 16e3, 32e3, 48e3, 64e3},
NativeHistogramBucketFactor: plugin.NativeHistogramBucketFactor,
}, []string{"server", "zone", "view", "proto"}) }, []string{"server", "zone", "view", "proto"})
ResponseRcode = promauto.NewCounterVec(prometheus.CounterOpts{ ResponseRcode = promauto.NewCounterVec(prometheus.CounterOpts{

View file

@ -14,6 +14,7 @@ var (
Subsystem: "proxy", Subsystem: "proxy",
Name: "request_duration_seconds", Name: "request_duration_seconds",
Buckets: plugin.TimeBuckets, Buckets: plugin.TimeBuckets,
NativeHistogramBucketFactor: plugin.NativeHistogramBucketFactor,
Help: "Histogram of the time each request took.", Help: "Histogram of the time each request took.",
}, []string{"proxy_name", "to", "rcode"}) }, []string{"proxy_name", "to", "rcode"})

View file

@ -108,5 +108,9 @@ var TimeBuckets = prometheus.ExponentialBuckets(0.00025, 2, 16) // from 0.25ms t
// SlimTimeBuckets is low cardinality set of duration buckets. // SlimTimeBuckets is low cardinality set of duration buckets.
var SlimTimeBuckets = prometheus.ExponentialBuckets(0.00025, 10, 5) // from 0.25ms to 2.5 seconds var SlimTimeBuckets = prometheus.ExponentialBuckets(0.00025, 10, 5) // from 0.25ms to 2.5 seconds
// NativeHistogramBucketFactor controls the resolution of Prometheus native histogram buckets.
// See: https://pkg.go.dev/github.com/prometheus/client_golang@v1.19.0/prometheus#section-readme
var NativeHistogramBucketFactor = 1.05
// ErrOnce is returned when a plugin doesn't support multiple setups per server. // ErrOnce is returned when a plugin doesn't support multiple setups per server.
var ErrOnce = errors.New("this plugin can only be used once per Server Block") var ErrOnce = errors.New("this plugin can only be used once per Server Block")