Skip to content

Commit 3faf3ba

Browse files
authored
Fixed support for unordered input of exemplars. (#1100)
Signed-off-by: bwplotka <[email protected]>
1 parent 44ce5e1 commit 3faf3ba

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

prometheus/metric.go

-2
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ func (m *withExemplarsMetric) Write(pb *dto.Metric) error {
192192
Exemplar: e,
193193
}
194194
pb.Histogram.Bucket = append(pb.Histogram.Bucket, b)
195-
break
196-
// Terminating the loop after creating the +Inf bucket and adding one exemplar, if there are other exemplars in the +Inf bucket range they will be ignored.
197195
}
198196
}
199197
default:

prometheus/metric_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,19 @@ func TestWithExemplarsMetric(t *testing.T) {
4747
h := MustNewConstHistogram(
4848
NewDesc("http_request_duration_seconds", "A histogram of the HTTP request durations.", nil, nil),
4949
4711, 403.34,
50+
// Four buckets, but we expect five as the +Inf bucket will be created if we see value outside of those buckets.
5051
map[float64]uint64{25: 121, 50: 2403, 100: 3221, 200: 4233},
5152
)
5253

5354
m := &withExemplarsMetric{Metric: h, exemplars: []*dto.Exemplar{
54-
{Value: proto.Float64(24.0)},
55-
{Value: proto.Float64(25.1)},
55+
{Value: proto.Float64(2000.0)}, // Unordered exemplars.
56+
{Value: proto.Float64(500.0)},
5657
{Value: proto.Float64(42.0)},
57-
{Value: proto.Float64(89.0)},
58-
{Value: proto.Float64(100.0)},
5958
{Value: proto.Float64(157.0)},
60-
{Value: proto.Float64(500.0)},
61-
{Value: proto.Float64(2000.0)},
59+
{Value: proto.Float64(100.0)},
60+
{Value: proto.Float64(89.0)},
61+
{Value: proto.Float64(24.0)},
62+
{Value: proto.Float64(25.1)},
6263
}}
6364
metric := dto.Metric{}
6465
if err := m.Write(&metric); err != nil {
@@ -68,8 +69,7 @@ func TestWithExemplarsMetric(t *testing.T) {
6869
t.Errorf("want %v, got %v", want, got)
6970
}
7071

71-
// When there are more exemplars than there are buckets, a +Inf bucket will be created and the last exemplar value will be added.
72-
expectedExemplarVals := []float64{24.0, 42.0, 100.0, 157.0, 500.0}
72+
expectedExemplarVals := []float64{24.0, 25.1, 89.0, 157.0, 500.0}
7373
for i, b := range metric.GetHistogram().Bucket {
7474
if b.Exemplar == nil {
7575
t.Errorf("Expected exemplar for bucket %v, got nil", i)

0 commit comments

Comments
 (0)