Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] use generated test harness for groupbyattrs processor #34941

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 208 additions & 16 deletions processor/groupbyattrsprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/collector/processor/processortest"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
)

var (
Expand Down Expand Up @@ -270,8 +272,8 @@ func TestComplexAttributeGrouping(t *testing.T) {
inputMetrics := someComplexMetrics(tt.withResourceAttrIndex, tt.inputResourceCount, tt.inputInstrumentationLibraryCount, 2)
inputHistogramMetrics := someComplexHistogramMetrics(tt.withResourceAttrIndex, tt.inputResourceCount, tt.inputInstrumentationLibraryCount, 2, 2)

tel := setupTelemetry()
gap, err := createGroupByAttrsProcessor(tel.NewProcessorCreateSettings(), tt.groupByKeys)
tel := setupTestTelemetry()
gap, err := createGroupByAttrsProcessor(tel.NewSettings(), tt.groupByKeys)
require.NoError(t, err)

processedLogs, err := gap.processLogs(context.Background(), inputLogs)
Expand Down Expand Up @@ -371,23 +373,213 @@ func TestComplexAttributeGrouping(t *testing.T) {
}
}
}

expected := expectedMetrics{}
var want []metricdata.Metrics
if tt.shouldMoveCommonGroupedAttr {
expected.mDistLogGroups = int64(tt.outputResourceCount)
expected.mNumGroupedLogs = int64(tt.outputTotalRecordsCount)

expected.mDistMetricGroups = int64(tt.outputResourceCount)
expected.mNumGroupedMetrics = 4 * int64(tt.outputTotalRecordsCount)

expected.mDistSpanGroups = int64(tt.outputResourceCount)
expected.mNumGroupedSpans = int64(tt.outputTotalRecordsCount)
want = []metricdata.Metrics{
{
Name: "otelcol_processor_groupbyattrs_num_grouped_logs",
Description: "Number of logs that had attributes grouped",
Unit: "1",
Data: metricdata.Sum[int64]{
Temporality: metricdata.CumulativeTemporality,
IsMonotonic: true,
DataPoints: []metricdata.DataPoint[int64]{
{
Value: int64(tt.outputTotalRecordsCount),
},
},
},
},
{
Name: "otelcol_processor_groupbyattrs_num_grouped_metrics",
Description: "Number of metrics that had attributes grouped",
Unit: "1",
Data: metricdata.Sum[int64]{
Temporality: metricdata.CumulativeTemporality,
IsMonotonic: true,
DataPoints: []metricdata.DataPoint[int64]{
{
Value: 4 * int64(tt.outputTotalRecordsCount),
},
},
},
},
{
Name: "otelcol_processor_groupbyattrs_num_grouped_spans",
Description: "Number of spans that had attributes grouped",
Unit: "1",
Data: metricdata.Sum[int64]{
Temporality: metricdata.CumulativeTemporality,
IsMonotonic: true,
DataPoints: []metricdata.DataPoint[int64]{
{
Value: int64(tt.outputTotalRecordsCount),
},
},
},
},
{
Name: "otelcol_processor_groupbyattrs_log_groups",
Description: "Distribution of groups extracted for logs",
Unit: "1",
Data: metricdata.Histogram[int64]{
Temporality: metricdata.CumulativeTemporality,
DataPoints: []metricdata.HistogramDataPoint[int64]{
{
Attributes: *attribute.EmptySet(),
Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000},
BucketCounts: []uint64{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Count: 1,
Min: metricdata.NewExtrema(int64(tt.outputResourceCount)),
Max: metricdata.NewExtrema(int64(tt.outputResourceCount)),
Sum: int64(tt.outputResourceCount),
},
},
},
},
{
Name: "otelcol_processor_groupbyattrs_metric_groups",
Description: "Distribution of groups extracted for metrics",
Unit: "1",
Data: metricdata.Histogram[int64]{
Temporality: metricdata.CumulativeTemporality,
DataPoints: []metricdata.HistogramDataPoint[int64]{
{
Attributes: *attribute.EmptySet(),
Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000},
BucketCounts: []uint64{0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Count: 2,
Min: metricdata.NewExtrema(int64(tt.outputResourceCount)),
Max: metricdata.NewExtrema(int64(tt.outputResourceCount)),
Sum: 2 * int64(tt.outputResourceCount),
},
},
},
},
{
Name: "otelcol_processor_groupbyattrs_span_groups",
Description: "Distribution of groups extracted for spans",
Unit: "1",
Data: metricdata.Histogram[int64]{
Temporality: metricdata.CumulativeTemporality,
DataPoints: []metricdata.HistogramDataPoint[int64]{
{
Attributes: *attribute.EmptySet(),
Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000},
BucketCounts: []uint64{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Count: 1,
Min: metricdata.NewExtrema(int64(tt.outputResourceCount)),
Max: metricdata.NewExtrema(int64(tt.outputResourceCount)),
Sum: int64(tt.outputResourceCount),
},
},
},
},
}
} else {
expected.mNumNonGroupedLogs = int64(tt.outputTotalRecordsCount)
expected.mNumNonGroupedMetrics = 4 * int64(tt.outputTotalRecordsCount)
expected.mNumNonGroupedSpans = int64(tt.outputTotalRecordsCount)
want = []metricdata.Metrics{
{
Name: "otelcol_processor_groupbyattrs_num_non_grouped_logs",
Description: "Number of logs that did not have attributes grouped",
Unit: "1",
Data: metricdata.Sum[int64]{
Temporality: metricdata.CumulativeTemporality,
IsMonotonic: true,
DataPoints: []metricdata.DataPoint[int64]{
{
Value: int64(tt.outputTotalRecordsCount),
},
},
},
},
{
Name: "otelcol_processor_groupbyattrs_num_non_grouped_metrics",
Description: "Number of metrics that did not have attributes grouped",
Unit: "1",
Data: metricdata.Sum[int64]{
Temporality: metricdata.CumulativeTemporality,
IsMonotonic: true,
DataPoints: []metricdata.DataPoint[int64]{
{
Value: 4 * int64(tt.outputTotalRecordsCount),
},
},
},
},
{
Name: "otelcol_processor_groupbyattrs_num_non_grouped_spans",
Description: "Number of spans that did not have attributes grouped",
Unit: "1",
Data: metricdata.Sum[int64]{
Temporality: metricdata.CumulativeTemporality,
IsMonotonic: true,
DataPoints: []metricdata.DataPoint[int64]{
{
Value: int64(tt.outputTotalRecordsCount),
},
},
},
},
{
Name: "otelcol_processor_groupbyattrs_log_groups",
Description: "Distribution of groups extracted for logs",
Unit: "1",
Data: metricdata.Histogram[int64]{
Temporality: metricdata.CumulativeTemporality,
DataPoints: []metricdata.HistogramDataPoint[int64]{
{
Attributes: *attribute.EmptySet(),
Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000},
BucketCounts: []uint64{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Count: 1,
Min: metricdata.NewExtrema(int64(tt.outputResourceCount)),
Max: metricdata.NewExtrema(int64(tt.outputResourceCount)),
Sum: int64(tt.outputResourceCount),
},
},
},
},
{
Name: "otelcol_processor_groupbyattrs_metric_groups",
Description: "Distribution of groups extracted for metrics",
Unit: "1",
Data: metricdata.Histogram[int64]{
Temporality: metricdata.CumulativeTemporality,
DataPoints: []metricdata.HistogramDataPoint[int64]{
{
Attributes: *attribute.EmptySet(),
Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000},
BucketCounts: []uint64{0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Count: 2,
Min: metricdata.NewExtrema(int64(tt.outputResourceCount)),
Max: metricdata.NewExtrema(int64(tt.outputResourceCount)),
Sum: 2 * int64(tt.outputResourceCount),
},
},
},
},
{
Name: "otelcol_processor_groupbyattrs_span_groups",
Description: "Distribution of groups extracted for spans",
Unit: "1",
Data: metricdata.Histogram[int64]{
Temporality: metricdata.CumulativeTemporality,
DataPoints: []metricdata.HistogramDataPoint[int64]{
{
Attributes: *attribute.EmptySet(),
Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000},
BucketCounts: []uint64{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Count: 1,
Min: metricdata.NewExtrema(int64(tt.outputResourceCount)),
Max: metricdata.NewExtrema(int64(tt.outputResourceCount)),
Sum: int64(tt.outputResourceCount),
},
},
},
},
}
}
tel.assertMetrics(t, expected)
tel.assertMetrics(t, want)
})
}
}
Expand Down
Loading