Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Include const labels in baseMetric.upsertEntry (#1221)
Browse files Browse the repository at this point in the history
  • Loading branch information
camh- committed Jul 19, 2020
1 parent 3456e1d commit d7677d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions metric/common.go
Expand Up @@ -133,6 +133,7 @@ func (bm *baseMetric) entryForValues(labelVals []metricdata.LabelValue, newEntry
}

func (bm *baseMetric) upsertEntry(labelVals []metricdata.LabelValue, newEntry func() baseEntry) error {
labelVals = append(bm.constLabelValues, labelVals...)
if len(labelVals) != len(bm.keys) {
return errKeyValueMismatch
}
Expand Down
23 changes: 23 additions & 0 deletions metric/gauge_test.go
Expand Up @@ -465,6 +465,29 @@ func TestInt64DerivedGaugeEntry_Update(t *testing.T) {
}
}

func TestInt64DerivedGaugeEntry_UpsertConstLabels(t *testing.T) {
r := NewRegistry()
q := &queueInt64{3}
g, _ := r.AddInt64DerivedGauge("g",
WithConstLabel(map[metricdata.LabelKey]metricdata.LabelValue{
{Key: "const"}: metricdata.NewLabelValue("same"),
}))
err := g.UpsertEntry(q.ToInt64)
if err != nil {
t.Errorf("want: nil, got: %v", err)
}
ms := r.Read()
if got, want := ms[0].TimeSeries[0].Points[0].Value.(int64), int64(3); got != want {
t.Errorf("value = %v, want %v", got, want)
}
if got, want := ms[0].Descriptor.LabelKeys[0].Key, "const"; got != want {
t.Errorf("label key = %v, want %v", got, want)
}
if got, want := ms[0].TimeSeries[0].LabelValues[0].Value, "same"; got != want {
t.Errorf("label value = %v, want %v", got, want)
}
}

type queueFloat64 struct {
size float64
}
Expand Down

0 comments on commit d7677d6

Please sign in to comment.