Skip to content

Commit

Permalink
[chore] use generated test harness for groupbyattrs processor (#34941)
Browse files Browse the repository at this point in the history
Like
#34940
but for the groupsbyattrs processor.

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
  • Loading branch information
codeboten authored Aug 30, 2024
1 parent 2d63c17 commit ea521f7
Show file tree
Hide file tree
Showing 2 changed files with 208 additions and 274 deletions.
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

0 comments on commit ea521f7

Please sign in to comment.