Skip to content

Commit

Permalink
test custom boundaries with valid histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Sep 29, 2022
1 parent b3fa7d4 commit bccaa84
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
19 changes: 16 additions & 3 deletions exporters/prometheus/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
otelmetric "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregation"
"go.opentelemetry.io/otel/sdk/metric/view"
)

func TestPrometheusExporter(t *testing.T) {
Expand Down Expand Up @@ -74,7 +76,7 @@ func TestPrometheusExporter(t *testing.T) {
attribute.Key("A").String("B"),
attribute.Key("C").String("D"),
}
histogram, err := meter.SyncFloat64().Histogram("baz", instrument.WithDescription("a very nice histogram"))
histogram, err := meter.SyncFloat64().Histogram("histogram_baz", instrument.WithDescription("a very nice histogram"))
require.NoError(t, err)
histogram.Record(ctx, 23, attrs...)
histogram.Record(ctx, 7, attrs...)
Expand Down Expand Up @@ -137,11 +139,22 @@ func TestPrometheusExporter(t *testing.T) {
ctx := context.Background()

exporter := New()
provider := metric.NewMeterProvider(metric.WithReader(exporter))

customBucketsView, err := view.New(
view.MatchInstrumentName("histogram_*"),
view.WithSetAggregation(aggregation.ExplicitBucketHistogram{
Boundaries: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 1000},
}),
)
require.NoError(t, err)
defaultView, err := view.New(view.MatchInstrumentName("*"))
require.NoError(t, err)

provider := metric.NewMeterProvider(metric.WithReader(exporter, customBucketsView, defaultView))
meter := provider.Meter("testmeter")

registry := prometheus.NewRegistry()
err := registry.Register(exporter.Collector)
err = registry.Register(exporter.Collector)
require.NoError(t, err)

tc.recordMetrics(ctx, meter)
Expand Down
35 changes: 15 additions & 20 deletions exporters/prometheus/testdata/histogram.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
# HELP baz a very nice histogram
# TYPE baz histogram
baz_bucket{A="B",C="D",le="0"} 0
baz_bucket{A="B",C="D",le="5"} 0
baz_bucket{A="B",C="D",le="10"} 1
baz_bucket{A="B",C="D",le="25"} 1
baz_bucket{A="B",C="D",le="50"} 0
baz_bucket{A="B",C="D",le="75"} 0
baz_bucket{A="B",C="D",le="100"} 0
baz_bucket{A="B",C="D",le="250"} 2
baz_bucket{A="B",C="D",le="500"} 0
baz_bucket{A="B",C="D",le="750"} 0
baz_bucket{A="B",C="D",le="1000"} 0
baz_bucket{A="B",C="D",le="2500"} 0
baz_bucket{A="B",C="D",le="5000"} 0
baz_bucket{A="B",C="D",le="7500"} 0
baz_bucket{A="B",C="D",le="10000"} 0
baz_bucket{A="B",C="D",le="+Inf"} 4
baz_sum{A="B",C="D"} 236
baz_count{A="B",C="D"} 4
# HELP histogram_baz a very nice histogram
# TYPE histogram_baz histogram
histogram_baz_bucket{A="B",C="D",le="0"} 0
histogram_baz_bucket{A="B",C="D",le="5"} 0
histogram_baz_bucket{A="B",C="D",le="10"} 1
histogram_baz_bucket{A="B",C="D",le="25"} 1
histogram_baz_bucket{A="B",C="D",le="50"} 0
histogram_baz_bucket{A="B",C="D",le="75"} 0
histogram_baz_bucket{A="B",C="D",le="100"} 0
histogram_baz_bucket{A="B",C="D",le="250"} 2
histogram_baz_bucket{A="B",C="D",le="500"} 0
histogram_baz_bucket{A="B",C="D",le="1000"} 0
histogram_baz_bucket{A="B",C="D",le="+Inf"} 4
histogram_baz_sum{A="B",C="D"} 236
histogram_baz_count{A="B",C="D"} 4
5 changes: 5 additions & 0 deletions exporters/prometheus/testdata/sanitized_names.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ invalid_hist_name_bucket{A="B",C="D",le="75"} 0
invalid_hist_name_bucket{A="B",C="D",le="100"} 0
invalid_hist_name_bucket{A="B",C="D",le="250"} 0
invalid_hist_name_bucket{A="B",C="D",le="500"} 0
invalid_hist_name_bucket{A="B",C="D",le="750"} 0
invalid_hist_name_bucket{A="B",C="D",le="1000"} 0
invalid_hist_name_bucket{A="B",C="D",le="2500"} 0
invalid_hist_name_bucket{A="B",C="D",le="5000"} 0
invalid_hist_name_bucket{A="B",C="D",le="7500"} 0
invalid_hist_name_bucket{A="B",C="D",le="10000"} 0
invalid_hist_name_bucket{A="B",C="D",le="+Inf"} 1
invalid_hist_name_sum{A="B",C="D"} 23
invalid_hist_name_count{A="B",C="D"} 1

0 comments on commit bccaa84

Please sign in to comment.