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

Add exemplar support for const histogram #986

Merged
merged 7 commits into from
Mar 17, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed linting warnings
reduce repetition in constHistogram w/ exemplar

Signed-off-by: William Perron <[email protected]>
  • Loading branch information
wperron committed Mar 7, 2022
commit ad6f1f6fdb92f4abafcd52cf8d9ba94f77cd3451
25 changes: 12 additions & 13 deletions prometheus/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,14 +678,15 @@ func NewConstHistogramWithExemplar(
if err := validateLabelValues(labelValues, len(desc.variableLabels)); err != nil {
return nil, err
}
return &constHistogram{
desc: desc,
count: count,
sum: sum,
buckets: buckets,
exemplars: exemplars,
labelPairs: MakeLabelPairs(desc, labelValues),
}, nil

h, err := NewConstHistogram(desc, count, sum, buckets, labelValues...)
if err != nil {
return nil, err
}

h.(*constHistogram).exemplars = exemplars

return h, nil
}

// MustNewConstHistogram is a version of NewConstHistogram that panics where
Expand All @@ -698,11 +699,9 @@ func MustNewConstHistogramWithExemplar(
exemplars []*dto.Exemplar,
labelValues ...string,
) Metric {
m, err := NewConstHistogramWithExemplar(desc, count, sum, buckets, exemplars, labelValues...)
if err != nil {
panic(err)
}
return m
h := MustNewConstHistogram(desc, count, sum, buckets, labelValues...)
h.(*constHistogram).exemplars = exemplars
return h
}

type buckSort []*dto.Bucket
Expand Down
12 changes: 6 additions & 6 deletions prometheus/histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,24 +424,24 @@ func TestHistogramExemplar(t *testing.T) {
}
expectedExemplars := []*dto.Exemplar{
nil,
&dto.Exemplar{
{
Label: []*dto.LabelPair{
&dto.LabelPair{Name: proto.String("id"), Value: proto.String("2")},
{Name: proto.String("id"), Value: proto.String("2")},
},
Value: proto.Float64(1.6),
Timestamp: ts,
},
nil,
&dto.Exemplar{
{
Label: []*dto.LabelPair{
&dto.LabelPair{Name: proto.String("id"), Value: proto.String("3")},
{Name: proto.String("id"), Value: proto.String("3")},
},
Value: proto.Float64(4),
Timestamp: ts,
},
&dto.Exemplar{
{
Label: []*dto.LabelPair{
&dto.LabelPair{Name: proto.String("id"), Value: proto.String("4")},
{Name: proto.String("id"), Value: proto.String("4")},
},
Value: proto.Float64(4.5),
Timestamp: ts,
Expand Down