Skip to content

Commit

Permalink
Update bucket default bounds (#3222)
Browse files Browse the repository at this point in the history
* update bucket default bounds to match the specification

* add changelog entry

* test custom boundaries with valid histogram

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
dmathieu and MrAlias committed Oct 4, 2022
1 parent 3b657f7 commit 697d245
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Flush pending measurements with the `PeriodicReader` in the `go.opentelemetry.io/otel/sdk/metric` when `ForceFlush` or `Shutdown` are called. (#3220)
- Upgrade `golang.org/x/sys/unix` from `v0.0.0-20210423185535-09eb48e85fd7` to `v0.0.0-20220919091848-fb04ddd9f9c8`.
This addresses [GO-2022-0493](https://pkg.go.dev/vuln/GO-2022-0493). (#3235)
- Update histogram default bounds to match the requirements of the latest specification. (#3222)

## [0.32.1] Metric SDK (Alpha) - 2022-09-22

Expand Down
19 changes: 16 additions & 3 deletions exporters/prometheus/exporter_test.go
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
30 changes: 15 additions & 15 deletions exporters/prometheus/testdata/histogram.txt
@@ -1,15 +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="1000"} 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
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
8 changes: 4 additions & 4 deletions sdk/metric/meter_test.go
Expand Up @@ -333,8 +333,8 @@ func TestMeterCreatesInstruments(t *testing.T) {
{
Attributes: attribute.Set{},
Count: 1,
Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 1000},
BucketCounts: []uint64{0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000},
BucketCounts: []uint64{0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Min: &seven,
Max: &seven,
Sum: 7.0,
Expand Down Expand Up @@ -397,8 +397,8 @@ func TestMeterCreatesInstruments(t *testing.T) {
{
Attributes: attribute.Set{},
Count: 1,
Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 1000},
BucketCounts: []uint64{0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000},
BucketCounts: []uint64{0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Min: &seven,
Max: &seven,
Sum: 7.0,
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/reader.go
Expand Up @@ -166,7 +166,7 @@ func DefaultAggregationSelector(ik view.InstrumentKind) aggregation.Aggregation
return aggregation.LastValue{}
case view.SyncHistogram:
return aggregation.ExplicitBucketHistogram{
Boundaries: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 1000},
Boundaries: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000},
NoMinMax: false,
}
}
Expand Down

0 comments on commit 697d245

Please sign in to comment.