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

Commit d7677d6

Browse files
authored
Include const labels in baseMetric.upsertEntry (#1221)
1 parent 3456e1d commit d7677d6

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

metric/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func (bm *baseMetric) entryForValues(labelVals []metricdata.LabelValue, newEntry
133133
}
134134

135135
func (bm *baseMetric) upsertEntry(labelVals []metricdata.LabelValue, newEntry func() baseEntry) error {
136+
labelVals = append(bm.constLabelValues, labelVals...)
136137
if len(labelVals) != len(bm.keys) {
137138
return errKeyValueMismatch
138139
}

metric/gauge_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,29 @@ func TestInt64DerivedGaugeEntry_Update(t *testing.T) {
465465
}
466466
}
467467

468+
func TestInt64DerivedGaugeEntry_UpsertConstLabels(t *testing.T) {
469+
r := NewRegistry()
470+
q := &queueInt64{3}
471+
g, _ := r.AddInt64DerivedGauge("g",
472+
WithConstLabel(map[metricdata.LabelKey]metricdata.LabelValue{
473+
{Key: "const"}: metricdata.NewLabelValue("same"),
474+
}))
475+
err := g.UpsertEntry(q.ToInt64)
476+
if err != nil {
477+
t.Errorf("want: nil, got: %v", err)
478+
}
479+
ms := r.Read()
480+
if got, want := ms[0].TimeSeries[0].Points[0].Value.(int64), int64(3); got != want {
481+
t.Errorf("value = %v, want %v", got, want)
482+
}
483+
if got, want := ms[0].Descriptor.LabelKeys[0].Key, "const"; got != want {
484+
t.Errorf("label key = %v, want %v", got, want)
485+
}
486+
if got, want := ms[0].TimeSeries[0].LabelValues[0].Value, "same"; got != want {
487+
t.Errorf("label value = %v, want %v", got, want)
488+
}
489+
}
490+
468491
type queueFloat64 struct {
469492
size float64
470493
}

0 commit comments

Comments
 (0)