Skip to content

Commit 477f546

Browse files
authored
fix(metrics): exponential buckets for snapshot byte histograms (#2651)
The SDK's default explicit-bucket boundaries are `[0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000]` (tuned for ms). The per-snapshot byte histograms record values up to tens of GiB, so every observation falls into `+Inf` and `histogram_quantile()` returns no useful signal. Adds a `View` matching `orchestrator.sandbox.snapshot.*` histograms with unit `{By}` and routes them to `AggregationBase2ExponentialHistogram{MaxSize: 160, MaxScale: 20}` so buckets auto-scale across the recorded range. Affected: - `orchestrator.sandbox.snapshot.diff.bytes` - `orchestrator.sandbox.snapshot.total.bytes`
1 parent 4480f61 commit 477f546

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

packages/shared/pkg/telemetry/metrics.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ func NewMeterExporter(ctx context.Context, extraOption ...otlpmetricgrpc.Option)
5353
return metricExporter, nil
5454
}
5555

56+
// snapshotBytesView routes the per-snapshot byte histograms to a base-2
57+
// exponential aggregation. The SDK's default explicit buckets max out at
58+
// 10_000 (tuned for ms), which collapses byte values into +Inf and makes
59+
// percentile queries unusable for the 0–tens-of-GiB range these metrics
60+
// cover.
61+
var snapshotBytesView = sdkmetric.NewView(
62+
sdkmetric.Instrument{
63+
Kind: sdkmetric.InstrumentKindHistogram,
64+
Name: "orchestrator.sandbox.snapshot.*",
65+
Unit: "{By}",
66+
},
67+
sdkmetric.Stream{
68+
Aggregation: sdkmetric.AggregationBase2ExponentialHistogram{
69+
MaxSize: 160,
70+
MaxScale: 20,
71+
},
72+
},
73+
)
74+
5675
func NewMeterProvider(metricsExporter sdkmetric.Exporter, metricExportPeriod time.Duration, res *resource.Resource, extraOption ...sdkmetric.Option) (metric.MeterProvider, error) {
5776
opts := []sdkmetric.Option{
5877
sdkmetric.WithReader(
@@ -72,6 +91,7 @@ func NewMeterProvider(metricsExporter sdkmetric.Exporter, metricExportPeriod tim
7291
}
7392

7493
opts = append(opts, extraOption...)
94+
opts = append(opts, sdkmetric.WithView(snapshotBytesView))
7595

7696
return sdkmetric.NewMeterProvider(opts...), nil
7797
}

0 commit comments

Comments
 (0)