From 6ff0b51fec5ded9b1c97bf915dd914e596d7176b Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Tue, 11 Jun 2024 15:12:14 +0200 Subject: [PATCH] fix(metrics): more duration histogram buckets (#142) * fix(metrics): more duration histogram buckets Closes #135 * fix: use the same buckets as boxo Co-authored-by: Daniel Norman <1992255+2color@users.noreply.github.com> --------- Co-authored-by: Daniel Norman <1992255+2color@users.noreply.github.com> --- CHANGELOG.md | 10 +++------- metrics.go | 5 ++++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d8dd88..7944f01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,16 +11,12 @@ The following emojis are used to highlight certain changes: * 🛠 - BREAKING CHANGE. Action is required if you use this functionality. * ✨ - Noteworthy change to be aware of. -## [Unreleased] - -### Added - -### Changed - -### Removed +## [v1.3.1] ### Fixed +- Added more buckets to the duration histogram metric to allow for tracking operations that take longer than 1 minute. + ### Security ## [v1.3.0] diff --git a/metrics.go b/metrics.go index bc34eac..45f47ab 100644 --- a/metrics.go +++ b/metrics.go @@ -19,6 +19,9 @@ func registerVersionMetric(version string) { m.Set(1) } +// Duration histograms use fixed definition here, as we don't want to break existing buckets if we need to add more. +var defaultDurationHistogramBuckets = []float64{0.05, 0.1, 0.25, 0.5, 1, 2, 5, 10, 30, 60, 120, 240, 480, 960, 1920} + // withHTTPMetrics collects metrics around HTTP request/response count, duration, and size // per specific handler. Allows us to track them separately for /ipns and /ipfs. func withHTTPMetrics(handler http.Handler, handlerName string) http.Handler { @@ -26,7 +29,7 @@ func withHTTPMetrics(handler http.Handler, handlerName string) http.Handler { opts := prometheus.HistogramOpts{ Namespace: "ipfs", Subsystem: "http", - Buckets: []float64{0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 30, 60}, + Buckets: defaultDurationHistogramBuckets, ConstLabels: prometheus.Labels{"handler": handlerName}, }