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

Fix const labels with derived metrics #1221

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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