Skip to content

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
  • Loading branch information
fatsheep9146 committed Oct 25, 2022
1 parent 1de3ce2 commit 5e1db78
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
25 changes: 22 additions & 3 deletions exporters/prometheus/exporter_test.go
Expand Up @@ -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...)
},
},
}
Expand Down
@@ -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
2 changes: 1 addition & 1 deletion 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

0 comments on commit 5e1db78

Please sign in to comment.