summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCam Hutchison <camh@xdna.net>2020-07-20 08:55:10 +1000
committerGitHub <noreply@github.com>2020-07-20 08:55:10 +1000
commitd7677d6af5953e0506ac4c08f349c62b917a443a (patch)
treee10586fe998f8012453735d6513d5eeafcb51aca
parent3456e1d174b20575a070d717b1a617685acd6905 (diff)
downloadopencensus-go-d7677d6af5953e0506ac4c08f349c62b917a443a.tar.gz
Include const labels in `baseMetric.upsertEntry` (#1221)
-rw-r--r--metric/common.go1
-rw-r--r--metric/gauge_test.go23
2 files changed, 24 insertions, 0 deletions
diff --git a/metric/common.go b/metric/common.go
index bd6e771..42acaae 100644
--- a/metric/common.go
+++ b/metric/common.go
@@ -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
}
diff --git a/metric/gauge_test.go b/metric/gauge_test.go
index 9c4f269..57a6f03 100644
--- a/metric/gauge_test.go
+++ b/metric/gauge_test.go
@@ -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
}