Skip to content

Commit

Permalink
reduce repetition in constHistogram w/ exemplars
Browse files Browse the repository at this point in the history
  • Loading branch information
wperron committed Feb 15, 2022
1 parent 9d1b757 commit 0edd2e5
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions prometheus/histogram.go
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

0 comments on commit 0edd2e5

Please sign in to comment.