From 5e1db781d12338e7bb6a420f8b7ff1d5012546e5 Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Tue, 25 Oct 2022 10:03:02 +0800 Subject: [PATCH] improve test coverage Signed-off-by: Ziqi Zhao --- exporters/prometheus/exporter_test.go | 25 ++++++++++++++++--- .../without_scope_and_target_info.txt | 3 +++ .../testdata/without_scope_info.txt | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 exporters/prometheus/testdata/without_scope_and_target_info.txt diff --git a/exporters/prometheus/exporter_test.go b/exporters/prometheus/exporter_test.go index 003fd6dfcea..bdd449db632 100644 --- a/exporters/prometheus/exporter_test.go +++ b/exporters/prometheus/exporter_test.go @@ -230,14 +230,33 @@ func TestPrometheusExporter(t *testing.T) { attribute.Key("A").String("B"), attribute.Key("C").String("D"), } - gauge, err := meter.SyncFloat64().UpDownCounter( + gauge, err := meter.SyncInt64().UpDownCounter( "bar", instrument.WithDescription("a fun little gauge"), instrument.WithUnit(unit.Dimensionless), ) require.NoError(t, err) - gauge.Add(ctx, 1.0, attrs...) - gauge.Add(ctx, -.25, attrs...) + gauge.Add(ctx, 2, attrs...) + gauge.Add(ctx, -1, attrs...) + }, + }, + { + name: "without scope_info and target_info", + options: []Option{WithoutScopeInfo(), WithoutTargetInfo()}, + expectedFile: "testdata/without_scope_and_target_info.txt", + recordMetrics: func(ctx context.Context, meter otelmetric.Meter) { + attrs := []attribute.KeyValue{ + attribute.Key("A").String("B"), + attribute.Key("C").String("D"), + } + counter, err := meter.SyncInt64().Counter( + "bar", + instrument.WithDescription("a fun little counter"), + instrument.WithUnit(unit.Bytes), + ) + require.NoError(t, err) + counter.Add(ctx, 2, attrs...) + counter.Add(ctx, 1, attrs...) }, }, } diff --git a/exporters/prometheus/testdata/without_scope_and_target_info.txt b/exporters/prometheus/testdata/without_scope_and_target_info.txt new file mode 100644 index 00000000000..9a551fd8ef2 --- /dev/null +++ b/exporters/prometheus/testdata/without_scope_and_target_info.txt @@ -0,0 +1,3 @@ +# HELP bar_bytes_total a fun little counter +# TYPE bar_bytes_total counter +bar_bytes_total{A="B",C="D"} 3 diff --git a/exporters/prometheus/testdata/without_scope_info.txt b/exporters/prometheus/testdata/without_scope_info.txt index cd75e5a6507..445743ac9a7 100644 --- a/exporters/prometheus/testdata/without_scope_info.txt +++ b/exporters/prometheus/testdata/without_scope_info.txt @@ -1,6 +1,6 @@ # HELP bar_ratio a fun little gauge # TYPE bar_ratio gauge -bar_ratio{A="B",C="D"} .75 +bar_ratio{A="B",C="D"} 1 # HELP target_info Target metadata # TYPE target_info gauge target_info{service_name="prometheus_test",telemetry_sdk_language="go",telemetry_sdk_name="opentelemetry",telemetry_sdk_version="latest"} 1