From 9855151ef63dea05cf9c82462a3c41d089d28217 Mon Sep 17 00:00:00 2001 From: Sebastian Rabenhorst <4246554+rabenhorst@users.noreply.github.com> Date: Wed, 3 May 2023 11:37:51 +0200 Subject: [PATCH] Replace summary in extprom metrics with histogram (#6327) * Replaced summary in extprom metrics with histogram Signed-off-by: Sebastian Rabenhorst * Added changelog Signed-off-by: Sebastian Rabenhorst * Removed unused parameters from NewInstrumentationMiddleware Signed-off-by: Sebastian Rabenhorst * Reverted NewInstrumentationMiddleware Signed-off-by: Sebastian Rabenhorst --------- Signed-off-by: Sebastian Rabenhorst --- CHANGELOG.md | 1 + pkg/extprom/http/metrics.go | 44 +++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce3b8d53c7..a08c755f21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re - [#6303](https://github.com/thanos-io/thanos/pull/6303) Store: added and start using streamed snappy encoding for postings list instead of block based one. This leads to constant memory usage during decompression. This approximately halves memory usage when decompressing a postings list in index cache. - [#6071](https://github.com/thanos-io/thanos/pull/6071) Query Frontend: *breaking :warning:* Add experimental native histogram support for which we updated and aligned with the [Prometheus common](https://github.com/prometheus/common) model, which is used for caching so a cache reset required. - [#6163](https://github.com/thanos-io/thanos/pull/6163) Receiver: changed max backoff from 30s to 5s for forwarding requests. Can be configured with `--receive-forward-max-backoff`. +- [#6327](https://github.com/thanos-io/thanos/pull/6327) *: *breaking :warning:* Use histograms instead of summaries for instrumented handlers. ### Removed diff --git a/pkg/extprom/http/metrics.go b/pkg/extprom/http/metrics.go index ef6269cefd..cff5d8640e 100644 --- a/pkg/extprom/http/metrics.go +++ b/pkg/extprom/http/metrics.go @@ -10,31 +10,40 @@ import ( type defaultMetrics struct { requestDuration *prometheus.HistogramVec - requestSize *prometheus.SummaryVec + requestSize *prometheus.HistogramVec requestsTotal *prometheus.CounterVec - responseSize *prometheus.SummaryVec + responseSize *prometheus.HistogramVec inflightHTTPRequests *prometheus.GaugeVec } -func newDefaultMetrics(reg prometheus.Registerer, buckets []float64, extraLabels []string) *defaultMetrics { - if buckets == nil { - buckets = []float64{0.001, 0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120, 240, 360, 720} +func newDefaultMetrics(reg prometheus.Registerer, durationBuckets []float64, extraLabels []string) *defaultMetrics { + if durationBuckets == nil { + durationBuckets = []float64{0.001, 0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120, 240, 360, 720} } + bytesBuckets := prometheus.ExponentialBuckets(64, 2, 10) + bucketFactor := 1.1 + maxBuckets := uint32(100) + return &defaultMetrics{ requestDuration: promauto.With(reg).NewHistogramVec( prometheus.HistogramOpts{ - Name: "http_request_duration_seconds", - Help: "Tracks the latencies for HTTP requests.", - Buckets: buckets, + Name: "http_request_duration_seconds", + Help: "Tracks the latencies for HTTP requests.", + Buckets: durationBuckets, + NativeHistogramBucketFactor: bucketFactor, + NativeHistogramMaxBucketNumber: maxBuckets, }, append([]string{"code", "handler", "method"}, extraLabels...), ), - requestSize: promauto.With(reg).NewSummaryVec( - prometheus.SummaryOpts{ - Name: "http_request_size_bytes", - Help: "Tracks the size of HTTP requests.", + requestSize: promauto.With(reg).NewHistogramVec( + prometheus.HistogramOpts{ + Name: "http_request_size_bytes", + Help: "Tracks the size of HTTP requests.", + Buckets: bytesBuckets, + NativeHistogramBucketFactor: bucketFactor, + NativeHistogramMaxBucketNumber: maxBuckets, }, append([]string{"code", "handler", "method"}, extraLabels...), ), @@ -47,10 +56,13 @@ func newDefaultMetrics(reg prometheus.Registerer, buckets []float64, extraLabels append([]string{"code", "handler", "method"}, extraLabels...), ), - responseSize: promauto.With(reg).NewSummaryVec( - prometheus.SummaryOpts{ - Name: "http_response_size_bytes", - Help: "Tracks the size of HTTP responses.", + responseSize: promauto.With(reg).NewHistogramVec( + prometheus.HistogramOpts{ + Name: "http_response_size_bytes", + Help: "Tracks the size of HTTP responses.", + Buckets: bytesBuckets, + NativeHistogramBucketFactor: bucketFactor, + NativeHistogramMaxBucketNumber: maxBuckets, }, append([]string{"code", "handler", "method"}, extraLabels...), ),