From c0a9aeb2b85b550b1f464c373cc7821958ca7f7a Mon Sep 17 00:00:00 2001 From: Edoardo Tenani <526307+endorama@users.noreply.github.com> Date: Fri, 22 Dec 2023 15:34:29 +0100 Subject: [PATCH] add test for OTLP metrics partial success response (#12276) --- systemtest/otlp_test.go | 54 ++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/systemtest/otlp_test.go b/systemtest/otlp_test.go index 71033c7c802..069614d2095 100644 --- a/systemtest/otlp_test.go +++ b/systemtest/otlp_test.go @@ -194,7 +194,14 @@ func TestOTLPGRPCMetrics(t *testing.T) { int64Histogram.Record(context.Background(), 123) int64Histogram.Record(context.Background(), 1024) int64Histogram.Record(context.Background(), 20000) - }) + }, sdkmetric.NewView( + sdkmetric.Instrument{Name: "*histogram"}, + sdkmetric.Stream{ + Aggregation: sdkmetric.AggregationExplicitBucketHistogram{ + Boundaries: []float64{0, 1, 100, 1000, 10000}, + }, + }, + )) require.NoError(t, err) // opentelemetry-go does not support sending Summary metrics, @@ -225,6 +232,39 @@ func TestOTLPGRPCMetrics(t *testing.T) { assert.True(t, gjson.GetBytes(doc.RawSource, "beats_stats.metrics.apm-server.otlp.grpc.metrics.consumer").Exists()) } +func TestOTLPGRPCMetrics_partialSuccess(t *testing.T) { + systemtest.CleanupElasticsearch(t) + srv := apmservertest.NewUnstartedServerTB(t) + srv.Config.Monitoring = newFastMonitoringConfig() + err := srv.Start() + require.NoError(t, err) + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + err = sendOTLPMetrics(t, ctx, srv, func(meter metric.Meter) { + float64Counter, err := meter.Float64Counter("counter") + require.NoError(t, err) + float64Counter.Add(context.Background(), 1) + + int64Histogram, err := meter.Int64Histogram("histogram") + require.NoError(t, err) + int64Histogram.Record(context.Background(), 1) + int64Histogram.Record(context.Background(), 123) + int64Histogram.Record(context.Background(), 1024) + int64Histogram.Record(context.Background(), 20000) + }, sdkmetric.NewView( + sdkmetric.Instrument{Name: "*histogram"}, + sdkmetric.Stream{ + Aggregation: sdkmetric.AggregationBase2ExponentialHistogram{ + MaxSize: 5, + MaxScale: -10, + }, + }, + )) + + require.ErrorContains(t, err, "OTLP partial success:") +} + func TestOTLPGRPCLogs(t *testing.T) { systemtest.CleanupElasticsearch(t) srv := apmservertest.NewServerTB(t) @@ -594,22 +634,14 @@ func sendOTLPMetrics( ctx context.Context, srv *apmservertest.Server, recordMetrics func(metric.Meter), + mv sdkmetric.View, ) error { exporter := newOTLPMetricExporter(t, srv) meterProvider := sdkmetric.NewMeterProvider( sdkmetric.WithReader( sdkmetric.NewPeriodicReader(exporter, sdkmetric.WithInterval(time.Minute)), ), - sdkmetric.WithView( - sdkmetric.NewView( - sdkmetric.Instrument{Name: "*histogram"}, - sdkmetric.Stream{ - Aggregation: sdkmetric.AggregationExplicitBucketHistogram{ - Boundaries: []float64{0, 1, 100, 1000, 10000}, - }, - }, - ), - ), + sdkmetric.WithView(mv), ) meter := meterProvider.Meter("test-meter")