Skip to content

Commit

Permalink
fixed linting warnings
Browse files Browse the repository at this point in the history
reduce repetition in constHistogram w/ exemplar

Signed-off-by: William Perron <william.perron@shopify.com>
  • Loading branch information
wperron committed Feb 16, 2022
1 parent d9d40e2 commit 65e8cde
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 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
12 changes: 6 additions & 6 deletions prometheus/histogram_test.go
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

0 comments on commit 65e8cde

Please sign in to comment.