Skip to content

Commit

Permalink
[chore] Remove unnecessary views, already using the hint API for buck…
Browse files Browse the repository at this point in the history
…ets (#11301)

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Oct 1, 2024
1 parent e6ef444 commit e594862
Showing 1 changed file with 14 additions and 33 deletions.
47 changes: 14 additions & 33 deletions service/telemetry/internal/otelinit/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"go.opentelemetry.io/otel/sdk/resource"

"go.opentelemetry.io/collector/processor/processorhelper"
semconv "go.opentelemetry.io/collector/semconv/v1.18.0"
)

Expand Down Expand Up @@ -85,7 +84,7 @@ func InitMetricReader(ctx context.Context, reader config.MetricReader, asyncErro
func InitOpenTelemetry(res *resource.Resource, options []sdkmetric.Option, disableHighCardinality bool) (*sdkmetric.MeterProvider, error) {
opts := []sdkmetric.Option{
sdkmetric.WithResource(res),
sdkmetric.WithView(batchViews(disableHighCardinality)...),
sdkmetric.WithView(disableHighCardinalityViews(disableHighCardinality)...),
}

opts = append(opts, options...)
Expand Down Expand Up @@ -116,40 +115,22 @@ func InitPrometheusServer(registry *prometheus.Registry, address string, asyncEr
return server
}

func batchViews(disableHighCardinality bool) []sdkmetric.View {
views := []sdkmetric.View{
func disableHighCardinalityViews(disableHighCardinality bool) []sdkmetric.View {
if !disableHighCardinality {
return nil
}
return []sdkmetric.View{
sdkmetric.NewView(
sdkmetric.Instrument{Name: processorhelper.BuildCustomMetricName("batch", "batch_send_size")},
sdkmetric.Stream{Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
Boundaries: []float64{10, 25, 50, 75, 100, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 20000, 30000, 50000, 100000},
}},
),
sdkmetric.Instrument{Scope: instrumentation.Scope{Name: GRPCInstrumentation}},
sdkmetric.Stream{
AttributeFilter: cardinalityFilter(GRPCUnacceptableKeyValues...),
}),
sdkmetric.NewView(
sdkmetric.Instrument{Name: processorhelper.BuildCustomMetricName("batch", "batch_send_size_bytes")},
sdkmetric.Stream{Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
Boundaries: []float64{10, 25, 50, 75, 100, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 20000, 30000, 50000,
100_000, 200_000, 300_000, 400_000, 500_000, 600_000, 700_000, 800_000, 900_000,
1000_000, 2000_000, 3000_000, 4000_000, 5000_000, 6000_000, 7000_000, 8000_000, 9000_000},
}},
),
}
if disableHighCardinality {
views = append(views, sdkmetric.NewView(sdkmetric.Instrument{
Scope: instrumentation.Scope{
Name: GRPCInstrumentation,
},
}, sdkmetric.Stream{
AttributeFilter: cardinalityFilter(GRPCUnacceptableKeyValues...),
}))
views = append(views, sdkmetric.NewView(sdkmetric.Instrument{
Scope: instrumentation.Scope{
Name: HTTPInstrumentation,
},
}, sdkmetric.Stream{
AttributeFilter: cardinalityFilter(HTTPUnacceptableKeyValues...),
}))
sdkmetric.Instrument{Scope: instrumentation.Scope{Name: HTTPInstrumentation}},
sdkmetric.Stream{
AttributeFilter: cardinalityFilter(HTTPUnacceptableKeyValues...),
}),
}
return views
}

func cardinalityFilter(kvs ...attribute.KeyValue) attribute.Filter {
Expand Down

0 comments on commit e594862

Please sign in to comment.