| 1 |
|
| 2 |
|
| 3 |
package metadatatest |
| 4 |
|
| 5 |
import ( |
| 6 |
"context" |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/require" |
| 10 |
"go.opentelemetry.io/otel/metric" |
| 11 |
"go.opentelemetry.io/otel/sdk/metric/metricdata" |
| 12 |
"go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest" |
| 13 |
|
| 14 |
"go.opentelemetry.io/collector/component/componenttest" |
| 15 |
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/metadata" |
| 16 |
) |
| 17 |
|
| 18 |
func TestSetupTelemetry(t *testing.T) { |
| 19 |
testTel := componenttest.NewTelemetry() |
| 20 |
tb, err := metadata.NewTelemetryBuilder(testTel.NewTelemetrySettings()) |
| 21 |
require.NoError(t, err) |
| 22 |
defer tb.Shutdown() |
| 23 |
require.NoError(t, tb.RegisterExporterQueueCapacityCallback(func(_ context.Context, observer metric.Int64Observer) error { |
| 24 |
observer.Observe(1) |
| 25 |
return nil |
| 26 |
})) |
| 27 |
require.NoError(t, tb.RegisterExporterQueueSizeCallback(func(_ context.Context, observer metric.Int64Observer) error { |
| 28 |
observer.Observe(1) |
| 29 |
return nil |
| 30 |
})) |
| 31 |
tb.ExporterEnqueueFailedLogRecords.Add(context.Background(), 1) |
| 32 |
tb.ExporterEnqueueFailedMetricPoints.Add(context.Background(), 1) |
| 33 |
tb.ExporterEnqueueFailedSpans.Add(context.Background(), 1) |
| 34 |
tb.ExporterQueueBatchSendSize.Record(context.Background(), 1) |
| 35 |
tb.ExporterQueueBatchSendSizeBytes.Record(context.Background(), 1) |
| 36 |
tb.ExporterSendFailedLogRecords.Add(context.Background(), 1) |
| 37 |
tb.ExporterSendFailedMetricPoints.Add(context.Background(), 1) |
| 38 |
tb.ExporterSendFailedSpans.Add(context.Background(), 1) |
| 39 |
tb.ExporterSentLogRecords.Add(context.Background(), 1) |
| 40 |
tb.ExporterSentMetricPoints.Add(context.Background(), 1) |
| 41 |
tb.ExporterSentSpans.Add(context.Background(), 1) |
| 42 |
AssertEqualExporterEnqueueFailedLogRecords(t, testTel, |
| 43 |
[]metricdata.DataPoint[int64]{{Value: 1}}, |
| 44 |
metricdatatest.IgnoreTimestamp()) |
| 45 |
AssertEqualExporterEnqueueFailedMetricPoints(t, testTel, |
| 46 |
[]metricdata.DataPoint[int64]{{Value: 1}}, |
| 47 |
metricdatatest.IgnoreTimestamp()) |
| 48 |
AssertEqualExporterEnqueueFailedSpans(t, testTel, |
| 49 |
[]metricdata.DataPoint[int64]{{Value: 1}}, |
| 50 |
metricdatatest.IgnoreTimestamp()) |
| 51 |
AssertEqualExporterQueueBatchSendSize(t, testTel, |
| 52 |
[]metricdata.HistogramDataPoint[int64]{{}}, metricdatatest.IgnoreValue(), |
| 53 |
metricdatatest.IgnoreTimestamp()) |
| 54 |
AssertEqualExporterQueueBatchSendSizeBytes(t, testTel, |
| 55 |
[]metricdata.HistogramDataPoint[int64]{{}}, metricdatatest.IgnoreValue(), |
| 56 |
metricdatatest.IgnoreTimestamp()) |
| 57 |
AssertEqualExporterQueueCapacity(t, testTel, |
| 58 |
[]metricdata.DataPoint[int64]{{Value: 1}}, |
| 59 |
metricdatatest.IgnoreTimestamp()) |
| 60 |
AssertEqualExporterQueueSize(t, testTel, |
| 61 |
[]metricdata.DataPoint[int64]{{Value: 1}}, |
| 62 |
metricdatatest.IgnoreTimestamp()) |
| 63 |
AssertEqualExporterSendFailedLogRecords(t, testTel, |
| 64 |
[]metricdata.DataPoint[int64]{{Value: 1}}, |
| 65 |
metricdatatest.IgnoreTimestamp()) |
| 66 |
AssertEqualExporterSendFailedMetricPoints(t, testTel, |
| 67 |
[]metricdata.DataPoint[int64]{{Value: 1}}, |
| 68 |
metricdatatest.IgnoreTimestamp()) |
| 69 |
AssertEqualExporterSendFailedSpans(t, testTel, |
| 70 |
[]metricdata.DataPoint[int64]{{Value: 1}}, |
| 71 |
metricdatatest.IgnoreTimestamp()) |
| 72 |
AssertEqualExporterSentLogRecords(t, testTel, |
| 73 |
[]metricdata.DataPoint[int64]{{Value: 1}}, |
| 74 |
metricdatatest.IgnoreTimestamp()) |
| 75 |
AssertEqualExporterSentMetricPoints(t, testTel, |
| 76 |
[]metricdata.DataPoint[int64]{{Value: 1}}, |
| 77 |
metricdatatest.IgnoreTimestamp()) |
| 78 |
AssertEqualExporterSentSpans(t, testTel, |
| 79 |
[]metricdata.DataPoint[int64]{{Value: 1}}, |
| 80 |
metricdatatest.IgnoreTimestamp()) |
| 81 |
|
| 82 |
require.NoError(t, testTel.Shutdown(context.Background())) |
| 83 |
} |