mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-04 09:43:23 +02:00
Add resources in the Prom tests
This commit is contained in:
parent
196d7740bd
commit
7172b30492
@ -25,6 +25,8 @@ import (
|
||||
"go.opentelemetry.io/otel/api/kv"
|
||||
"go.opentelemetry.io/otel/api/metric"
|
||||
"go.opentelemetry.io/otel/exporters/metric/prometheus"
|
||||
"go.opentelemetry.io/otel/sdk/metric/controller/pull"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
)
|
||||
|
||||
// This test demonstrates that it is relatively difficult to setup a
|
||||
@ -32,11 +34,14 @@ import (
|
||||
//
|
||||
// 1. The default boundaries are difficult to pass, should be []float instead of []metric.Number
|
||||
//
|
||||
// TODO: Address this issue; add Resources to the test.
|
||||
// TODO: Address this issue.
|
||||
|
||||
func ExampleNewExportPipeline() {
|
||||
// Create a meter
|
||||
exporter, err := prometheus.NewExportPipeline(prometheus.Config{})
|
||||
exporter, err := prometheus.NewExportPipeline(
|
||||
prometheus.Config{},
|
||||
pull.WithResource(resource.New(kv.String("R", "V"))),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -73,10 +78,10 @@ func ExampleNewExportPipeline() {
|
||||
// Output:
|
||||
// # HELP a_counter Counts things
|
||||
// # TYPE a_counter counter
|
||||
// a_counter{key="value"} 100
|
||||
// a_counter{R="V",key="value"} 100
|
||||
// # HELP a_valuerecorder Records values
|
||||
// # TYPE a_valuerecorder histogram
|
||||
// a_valuerecorder_bucket{key="value",le="+Inf"} 1
|
||||
// a_valuerecorder_sum{key="value"} 100
|
||||
// a_valuerecorder_count{key="value"} 1
|
||||
// a_valuerecorder_bucket{R="V",key="value",le="+Inf"} 1
|
||||
// a_valuerecorder_sum{R="V",key="value"} 100
|
||||
// a_valuerecorder_count{R="V",key="value"} 1
|
||||
}
|
||||
|
@ -30,12 +30,13 @@ import (
|
||||
"go.opentelemetry.io/otel/api/metric"
|
||||
"go.opentelemetry.io/otel/exporters/metric/prometheus"
|
||||
"go.opentelemetry.io/otel/sdk/metric/controller/pull"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
)
|
||||
|
||||
func TestPrometheusExporter(t *testing.T) {
|
||||
exporter, err := prometheus.NewExportPipeline(prometheus.Config{
|
||||
DefaultHistogramBoundaries: []metric.Number{metric.NewFloat64Number(-0.5), metric.NewFloat64Number(1)},
|
||||
})
|
||||
}, pull.WithResource(resource.New(kv.String("R", "V"))))
|
||||
require.NoError(t, err)
|
||||
|
||||
meter := exporter.Provider().Meter("test")
|
||||
@ -54,18 +55,18 @@ func TestPrometheusExporter(t *testing.T) {
|
||||
counter.Add(ctx, 10, labels...)
|
||||
counter.Add(ctx, 5.3, labels...)
|
||||
|
||||
expected = append(expected, `counter{A="B",C="D"} 15.3`)
|
||||
expected = append(expected, `counter{A="B",C="D",R="V"} 15.3`)
|
||||
|
||||
valuerecorder.Record(ctx, -0.6, labels...)
|
||||
valuerecorder.Record(ctx, -0.4, labels...)
|
||||
valuerecorder.Record(ctx, 0.6, labels...)
|
||||
valuerecorder.Record(ctx, 20, labels...)
|
||||
|
||||
expected = append(expected, `valuerecorder_bucket{A="B",C="D",le="+Inf"} 4`)
|
||||
expected = append(expected, `valuerecorder_bucket{A="B",C="D",le="-0.5"} 1`)
|
||||
expected = append(expected, `valuerecorder_bucket{A="B",C="D",le="1"} 3`)
|
||||
expected = append(expected, `valuerecorder_count{A="B",C="D"} 4`)
|
||||
expected = append(expected, `valuerecorder_sum{A="B",C="D"} 19.6`)
|
||||
expected = append(expected, `valuerecorder_bucket{A="B",C="D",R="V",le="+Inf"} 4`)
|
||||
expected = append(expected, `valuerecorder_bucket{A="B",C="D",R="V",le="-0.5"} 1`)
|
||||
expected = append(expected, `valuerecorder_bucket{A="B",C="D",R="V",le="1"} 3`)
|
||||
expected = append(expected, `valuerecorder_count{A="B",C="D",R="V"} 4`)
|
||||
expected = append(expected, `valuerecorder_sum{A="B",C="D",R="V"} 19.6`)
|
||||
|
||||
compareExport(t, exporter, expected)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user