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

Fix CumulativeCount value of +Inf bucket created from exemplar #1148

Merged
merged 4 commits into from Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion prometheus/metric.go
Expand Up @@ -187,7 +187,7 @@ func (m *withExemplarsMetric) Write(pb *dto.Metric) error {
} else {
// The +Inf bucket should be explicitly added if there is an exemplar for it, similar to non-const histogram logic in https://github.com/prometheus/client_golang/blob/main/prometheus/histogram.go#L357-L365.
b := &dto.Bucket{
CumulativeCount: proto.Uint64(pb.Histogram.Bucket[len(pb.Histogram.GetBucket())-1].GetCumulativeCount()),
CumulativeCount: proto.Uint64(pb.Histogram.GetSampleCount()),
UpperBound: proto.Float64(math.Inf(1)),
Exemplar: e,
}
Expand Down
10 changes: 7 additions & 3 deletions prometheus/metric_test.go
Expand Up @@ -79,10 +79,14 @@ func TestWithExemplarsMetric(t *testing.T) {
}
}

infBucket := metric.GetHistogram().Bucket[len(metric.GetHistogram().Bucket)-1].GetUpperBound()
infBucket := metric.GetHistogram().Bucket[len(metric.GetHistogram().Bucket)-1]

if infBucket != math.Inf(1) {
t.Errorf("want %v, got %v", math.Inf(1), infBucket)
if upperBound := infBucket.GetUpperBound(); upperBound != math.Inf(1) {
t.Errorf("want %v, got %v", math.Inf(1), upperBound)
}

if cumulativeCount := infBucket.GetCumulativeCount(); cumulativeCount != 4711 {
t.Errorf("want %v, got %v", 4711, cumulativeCount)
balintzs marked this conversation as resolved.
Show resolved Hide resolved
}
})
}