From c37f485678458f6784b44179b83d84b2df419039 Mon Sep 17 00:00:00 2001 From: Eric Hsueh <39718333+erichsueh3@users.noreply.github.com> Date: Mon, 10 Jan 2022 15:22:31 -0800 Subject: [PATCH] added Float64 CounterObserver and UDCounterObserver tests (#2487) Co-authored-by: Anthony Mirabella --- exporters/prometheus/prometheus_test.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/exporters/prometheus/prometheus_test.go b/exporters/prometheus/prometheus_test.go index 907db0db4..b05d92321 100644 --- a/exporters/prometheus/prometheus_test.go +++ b/exporters/prometheus/prometheus_test.go @@ -124,11 +124,11 @@ func TestPrometheusExporter(t *testing.T) { expected = append(expected, expectCounter("counter", `counter{A="B",C="D",R="V"} 15.3`)) - _ = metric.Must(meter).NewInt64GaugeObserver("intobserver", func(_ context.Context, result metric.Int64ObserverResult) { + _ = metric.Must(meter).NewInt64GaugeObserver("intgaugeobserver", func(_ context.Context, result metric.Int64ObserverResult) { result.Observe(1, labels...) }) - expected = append(expected, expectGauge("intobserver", `intobserver{A="B",C="D",R="V"} 1`)) + expected = append(expected, expectGauge("intgaugeobserver", `intgaugeobserver{A="B",C="D",R="V"} 1`)) histogram.Record(ctx, -0.6, labels...) histogram.Record(ctx, -0.4, labels...) @@ -148,6 +148,18 @@ func TestPrometheusExporter(t *testing.T) { expected = append(expected, expectGauge("updowncounter", `updowncounter{A="B",C="D",R="V"} 6.8`)) + _ = metric.Must(meter).NewFloat64CounterObserver("floatcounterobserver", func(_ context.Context, result metric.Float64ObserverResult) { + result.Observe(7.7, labels...) + }) + + expected = append(expected, expectCounter("floatcounterobserver", `floatcounterobserver{A="B",C="D",R="V"} 7.7`)) + + _ = metric.Must(meter).NewFloat64UpDownCounterObserver("floatupdowncounterobserver", func(_ context.Context, result metric.Float64ObserverResult) { + result.Observe(-7.7, labels...) + }) + + expected = append(expected, expectGauge("floatupdowncounterobserver", `floatupdowncounterobserver{A="B",C="D",R="V"} -7.7`)) + compareExport(t, exporter, expected) compareExport(t, exporter, expected) }