Skip to content

Commit

Permalink
add test for OTLP metrics partial success response (#12276)
Browse files Browse the repository at this point in the history
  • Loading branch information
endorama authored Dec 22, 2023
1 parent 2907605 commit c0a9aeb
Showing 1 changed file with 43 additions and 11 deletions.
54 changes: 43 additions & 11 deletions systemtest/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit c0a9aeb

Please sign in to comment.