Skip to content

Commit 8db2480

Browse files
committed
fix(metrics): avoid duplicate buckets in Mid1To16k
1 parent ff6550e commit 8db2480

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

common/metrics/histograms.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ var (
6060

6161
// Mid1To16k is a histogram for small counters, like "how many replication tasks did we receive".
6262
//
63-
// This targets 1 to ~10k with some buffer, and ends just below 64k.
64-
// Do not rely on this for values which can ever reach 64k, make a new histogram.
65-
Mid1To16k = IntSubsettableHistogram(makeSubsettableHistogram(2, 1, 16384, 64))
63+
// This targets single-digits through ~10k with some buffer, and ends well below 1M.
64+
//
65+
// Note: we intentionally start at 8 (not 1). Starting at 1 causes duplicate bucket boundaries
66+
// due to float->duration truncation, which Prometheus rejects.
67+
Mid1To16k = IntSubsettableHistogram(makeSubsettableHistogram(2, 8, 16384, 64))
6668
)
6769

6870
// SubsettableHistogram is a duration-based histogram that can be subset to a lower scale

common/metrics/histograms_test.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,8 @@ func TestHistogramValues(t *testing.T) {
130130
`)
131131
})
132132
t.Run("mid_to_16k_ints", func(t *testing.T) {
133-
// note: this histogram has some duplicates.
134-
//
135-
// this wastes a bit of memory, but Tally will choose the same index each
136-
// time for a specific value, so it does not cause extra non-zero series
137-
// to be stored or emitted.
138-
//
139-
// if this turns out to be expensive in Prometheus / etc, it's easy
140-
// enough to start the histogram at 8, and dual-emit a non-exponential
141-
// histogram for lower values.
142133
checkHistogram(t, Mid1To16k, `
143134
[0]
144-
[1 1 1 1]
145-
[2 2 2 3]
146-
[4 4 5 6]
147135
[8 9 11 13]
148136
[16 19 22 26]
149137
[32 38 45 53]
@@ -157,7 +145,10 @@ func TestHistogramValues(t *testing.T) {
157145
[8192 9741 11585 13777]
158146
[16384 19483 23170 27554]
159147
[32768 38967 46340 55108]
160-
[65536]
148+
[65536 77935 92681 110217]
149+
[131072 155871 185363 220435]
150+
[262144 311743 370727 440871]
151+
[524288]
161152
`)
162153
})
163154
}

0 commit comments

Comments
 (0)