Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed support for unordered input of exemplars. #1100

Merged
merged 1 commit into from Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions prometheus/metric.go
Expand Up @@ -192,8 +192,6 @@ func (m *withExemplarsMetric) Write(pb *dto.Metric) error {
Exemplar: e,
}
pb.Histogram.Bucket = append(pb.Histogram.Bucket, b)
break
// 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.
}
}
default:
Expand Down
16 changes: 8 additions & 8 deletions prometheus/metric_test.go
Expand Up @@ -47,18 +47,19 @@ func TestWithExemplarsMetric(t *testing.T) {
h := MustNewConstHistogram(
NewDesc("http_request_duration_seconds", "A histogram of the HTTP request durations.", nil, nil),
4711, 403.34,
// Four buckets, but we expect five as the +Inf bucket will be created if we see value outside of those buckets.
map[float64]uint64{25: 121, 50: 2403, 100: 3221, 200: 4233},
)

m := &withExemplarsMetric{Metric: h, exemplars: []*dto.Exemplar{
{Value: proto.Float64(24.0)},
{Value: proto.Float64(25.1)},
{Value: proto.Float64(2000.0)}, // Unordered exemplars.
{Value: proto.Float64(500.0)},
{Value: proto.Float64(42.0)},
{Value: proto.Float64(89.0)},
{Value: proto.Float64(100.0)},
{Value: proto.Float64(157.0)},
{Value: proto.Float64(500.0)},
{Value: proto.Float64(2000.0)},
{Value: proto.Float64(100.0)},
{Value: proto.Float64(89.0)},
{Value: proto.Float64(24.0)},
{Value: proto.Float64(25.1)},
}}
metric := dto.Metric{}
if err := m.Write(&metric); err != nil {
Expand All @@ -68,8 +69,7 @@ func TestWithExemplarsMetric(t *testing.T) {
t.Errorf("want %v, got %v", want, got)
}

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