From 9d5a3ab8512de3226b03648624884cdb2bc8b766 Mon Sep 17 00:00:00 2001 From: Dan Jaglowski Date: Wed, 30 Oct 2024 14:20:57 -0400 Subject: [PATCH] [chore] Refactor trace routing with ptraceutil --- .../internal/pmetricutil/metrics.go | 18 + .../internal/pmetricutil/metrics_test.go | 73 ++++ .../testdata/resource/move_all/from.yaml | 389 ++++++++++++++++++ .../resource/move_all/from_modified.yaml | 0 .../testdata/resource/move_all/to.yaml | 0 .../resource/move_all/to_modified.yaml | 389 ++++++++++++++++++ .../testdata/resource/move_none/from.yaml | 389 ++++++++++++++++++ .../resource/move_none/from_modified.yaml | 389 ++++++++++++++++++ .../testdata/resource/move_none/to.yaml | 1 + .../resource/move_none/to_modified.yaml | 1 + .../testdata/resource/move_one/from.yaml | 389 ++++++++++++++++++ .../resource/move_one/from_modified.yaml | 195 +++++++++ .../testdata/resource/move_one/to.yaml | 1 + .../resource/move_one/to_modified.yaml | 195 +++++++++ .../resource/move_to_preexisting/from.yaml | 389 ++++++++++++++++++ .../move_to_preexisting/from_modified.yaml | 195 +++++++++ .../resource/move_to_preexisting/to.yaml | 195 +++++++++ .../move_to_preexisting/to_modified.yaml | 389 ++++++++++++++++++ .../testdata/resource/move_all/from.yaml | 117 ++++++ .../resource/move_all/from_modified.yaml | 0 .../testdata/resource/move_all/to.yaml | 0 .../resource/move_all/to_modified.yaml | 117 ++++++ .../testdata/resource/move_none/from.yaml | 117 ++++++ .../resource/move_none/from_modified.yaml | 117 ++++++ .../testdata/resource/move_none/to.yaml | 1 + .../resource/move_none/to_modified.yaml | 1 + .../testdata/resource/move_one/from.yaml | 117 ++++++ .../resource/move_one/from_modified.yaml | 59 +++ .../testdata/resource/move_one/to.yaml | 1 + .../resource/move_one/to_modified.yaml | 59 +++ .../resource/move_to_preexisting/from.yaml | 117 ++++++ .../move_to_preexisting/from_modified.yaml | 59 +++ .../resource/move_to_preexisting/to.yaml | 59 +++ .../move_to_preexisting/to_modified.yaml | 117 ++++++ .../internal/ptraceutil/traces.go | 18 + .../internal/ptraceutil/traces_test.go | 73 ++++ connector/routingconnector/logs.go | 26 +- connector/routingconnector/metrics.go | 65 ++- connector/routingconnector/traces.go | 79 +++- 39 files changed, 4876 insertions(+), 40 deletions(-) create mode 100644 connector/routingconnector/internal/pmetricutil/metrics.go create mode 100644 connector/routingconnector/internal/pmetricutil/metrics_test.go create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_all/from.yaml create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_all/from_modified.yaml create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_all/to.yaml create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_all/to_modified.yaml create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/from.yaml create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/from_modified.yaml create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/to.yaml create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/to_modified.yaml create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/from.yaml create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/from_modified.yaml create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/to.yaml create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/to_modified.yaml create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/from.yaml create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/from_modified.yaml create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/to.yaml create mode 100644 connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/to_modified.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/from.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/from_modified.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/to.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/to_modified.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/from.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/from_modified.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/to.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/to_modified.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/from.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/from_modified.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/to.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/to_modified.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/from.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/from_modified.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/to.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/to_modified.yaml create mode 100644 connector/routingconnector/internal/ptraceutil/traces.go create mode 100644 connector/routingconnector/internal/ptraceutil/traces_test.go diff --git a/connector/routingconnector/internal/pmetricutil/metrics.go b/connector/routingconnector/internal/pmetricutil/metrics.go new file mode 100644 index 000000000000..1ca6d23b1ad7 --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/metrics.go @@ -0,0 +1,18 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package pmetricutil // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/routingconnector/internal/pmetricutil" + +import "go.opentelemetry.io/collector/pdata/pmetric" + +// MoveResourcesIf calls f sequentially for each ResourceSpans present in the first pmetric.Metrics. +// If f returns true, the element is removed from the first pmetric.Metrics and added to the second pmetric.Metrics. +func MoveResourcesIf(from, to pmetric.Metrics, f func(pmetric.ResourceMetrics) bool) { + from.ResourceMetrics().RemoveIf(func(rs pmetric.ResourceMetrics) bool { + if !f(rs) { + return false + } + rs.CopyTo(to.ResourceMetrics().AppendEmpty()) + return true + }) +} diff --git a/connector/routingconnector/internal/pmetricutil/metrics_test.go b/connector/routingconnector/internal/pmetricutil/metrics_test.go new file mode 100644 index 000000000000..3d7e62b0020a --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/metrics_test.go @@ -0,0 +1,73 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package pmetricutil_test + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/pdata/pmetric" + + "github.com/open-telemetry/opentelemetry-collector-contrib/connector/routingconnector/internal/pmetricutil" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" +) + +func TestMoveResourcesIf(t *testing.T) { + testCases := []struct { + name string + condition func(pmetric.ResourceMetrics) bool + }{ + { + name: "move_none", + condition: func(pmetric.ResourceMetrics) bool { + return false + }, + }, + { + name: "move_all", + condition: func(pmetric.ResourceMetrics) bool { + return true + }, + }, + { + name: "move_one", + condition: func(rl pmetric.ResourceMetrics) bool { + rname, ok := rl.Resource().Attributes().Get("resourceName") + return ok && rname.AsString() == "resourceA" + }, + }, + { + name: "move_to_preexisting", + condition: func(rl pmetric.ResourceMetrics) bool { + rname, ok := rl.Resource().Attributes().Get("resourceName") + return ok && rname.AsString() == "resourceB" + }, + }, + } + + for _, tt := range testCases { + t.Run(tt.name, func(t *testing.T) { + // Load up a fresh copy of the input for each test, since it may be modified in place. + from, err := golden.ReadMetrics(filepath.Join("testdata", "resource", tt.name, "from.yaml")) + require.NoError(t, err) + + to, err := golden.ReadMetrics(filepath.Join("testdata", "resource", tt.name, "to.yaml")) + require.NoError(t, err) + + fromModifed, err := golden.ReadMetrics(filepath.Join("testdata", "resource", tt.name, "from_modified.yaml")) + require.NoError(t, err) + + toModified, err := golden.ReadMetrics(filepath.Join("testdata", "resource", tt.name, "to_modified.yaml")) + require.NoError(t, err) + + pmetricutil.MoveResourcesIf(from, to, tt.condition) + + assert.NoError(t, pmetrictest.CompareMetrics(fromModifed, from), "from not modified as expected") + assert.NoError(t, pmetrictest.CompareMetrics(toModified, to), "to not as expected") + }) + } +} diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_all/from.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_all/from.yaml new file mode 100644 index 000000000000..68145249e0bd --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_all/from.yaml @@ -0,0 +1,389 @@ +resourceMetrics: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_all/from_modified.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_all/from_modified.yaml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_all/to.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_all/to.yaml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_all/to_modified.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_all/to_modified.yaml new file mode 100644 index 000000000000..68145249e0bd --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_all/to_modified.yaml @@ -0,0 +1,389 @@ +resourceMetrics: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/from.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/from.yaml new file mode 100644 index 000000000000..68145249e0bd --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/from.yaml @@ -0,0 +1,389 @@ +resourceMetrics: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/from_modified.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/from_modified.yaml new file mode 100644 index 000000000000..68145249e0bd --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/from_modified.yaml @@ -0,0 +1,389 @@ +resourceMetrics: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/to.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/to.yaml new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/to.yaml @@ -0,0 +1 @@ + diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/to_modified.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/to_modified.yaml new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_none/to_modified.yaml @@ -0,0 +1 @@ + diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/from.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/from.yaml new file mode 100644 index 000000000000..68145249e0bd --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/from.yaml @@ -0,0 +1,389 @@ +resourceMetrics: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/from_modified.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/from_modified.yaml new file mode 100644 index 000000000000..b83427450811 --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/from_modified.yaml @@ -0,0 +1,195 @@ +resourceMetrics: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/to.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/to.yaml new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/to.yaml @@ -0,0 +1 @@ + diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/to_modified.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/to_modified.yaml new file mode 100644 index 000000000000..705311b4fd43 --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_one/to_modified.yaml @@ -0,0 +1,195 @@ +resourceMetrics: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/from.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/from.yaml new file mode 100644 index 000000000000..68145249e0bd --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/from.yaml @@ -0,0 +1,389 @@ +resourceMetrics: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/from_modified.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/from_modified.yaml new file mode 100644 index 000000000000..705311b4fd43 --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/from_modified.yaml @@ -0,0 +1,195 @@ +resourceMetrics: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/to.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/to.yaml new file mode 100644 index 000000000000..52afaa3be9cc --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/to.yaml @@ -0,0 +1,195 @@ +resourceMetrics: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceC + - key: resourceNameAgain + value: + stringValue: resourceC + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" diff --git a/connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/to_modified.yaml b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/to_modified.yaml new file mode 100644 index 000000000000..5548e74519cf --- /dev/null +++ b/connector/routingconnector/internal/pmetricutil/testdata/resource/move_to_preexisting/to_modified.yaml @@ -0,0 +1,389 @@ +resourceMetrics: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceC + - key: resourceNameAgain + value: + stringValue: resourceC + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeMetrics: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + metrics: + - name: sumMonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "101" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "102" + - name: sumNonmonotonicCumulative + sum: + aggregationTemporality: 2 # AGGREGATION_TEMPORALITY_CUMULATIVE + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "102" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "101" + - name: sumMonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: true + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "1" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "2" + - name: sumNonmonotonicDelta + sum: + aggregationTemporality: 1 # AGGREGATION_TEMPORALITY_DELTA + isMonotonic: false + dataPoints: + - attributes: + - key: dataPointName + value: + stringValue: dataPointA + - key: dataPointNameAgain + value: + stringValue: dataPointA + asInt: "2" + - attributes: + - key: dataPointName + value: + stringValue: dataPointB + - key: dataPointNameAgain + value: + stringValue: dataPointB + asInt: "1" diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/from.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/from.yaml new file mode 100644 index 000000000000..914758ed6510 --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/from.yaml @@ -0,0 +1,117 @@ +resourceSpans: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/from_modified.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/from_modified.yaml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/to.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/to.yaml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/to_modified.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/to_modified.yaml new file mode 100644 index 000000000000..914758ed6510 --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/to_modified.yaml @@ -0,0 +1,117 @@ +resourceSpans: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/from.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/from.yaml new file mode 100644 index 000000000000..914758ed6510 --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/from.yaml @@ -0,0 +1,117 @@ +resourceSpans: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/from_modified.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/from_modified.yaml new file mode 100644 index 000000000000..914758ed6510 --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/from_modified.yaml @@ -0,0 +1,117 @@ +resourceSpans: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/to.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/to.yaml new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/to.yaml @@ -0,0 +1 @@ + diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/to_modified.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/to_modified.yaml new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/to_modified.yaml @@ -0,0 +1 @@ + diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/from.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/from.yaml new file mode 100644 index 000000000000..914758ed6510 --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/from.yaml @@ -0,0 +1,117 @@ +resourceSpans: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/from_modified.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/from_modified.yaml new file mode 100644 index 000000000000..638861efcf92 --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/from_modified.yaml @@ -0,0 +1,59 @@ +resourceSpans: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/to.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/to.yaml new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/to.yaml @@ -0,0 +1 @@ + diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/to_modified.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/to_modified.yaml new file mode 100644 index 000000000000..5c862eb1178f --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/to_modified.yaml @@ -0,0 +1,59 @@ +resourceSpans: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/from.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/from.yaml new file mode 100644 index 000000000000..914758ed6510 --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/from.yaml @@ -0,0 +1,117 @@ +resourceSpans: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/from_modified.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/from_modified.yaml new file mode 100644 index 000000000000..5c862eb1178f --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/from_modified.yaml @@ -0,0 +1,59 @@ +resourceSpans: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceA + - key: resourceNameAgain + value: + stringValue: resourceA + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/to.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/to.yaml new file mode 100644 index 000000000000..b0164a87a261 --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/to.yaml @@ -0,0 +1,59 @@ +resourceSpans: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceC + - key: resourceNameAgain + value: + stringValue: resourceC + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/to_modified.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/to_modified.yaml new file mode 100644 index 000000000000..e8294e1e690b --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/to_modified.yaml @@ -0,0 +1,117 @@ +resourceSpans: + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceC + - key: resourceNameAgain + value: + stringValue: resourceC + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - resource: + attributes: + - key: resourceName + value: + stringValue: resourceB + - key: resourceNameAgain + value: + stringValue: resourceB + schemaUrl: https://opentelemetry.io/schemas/1.6.1 + scopeSpans: + - attributes: + - key: scopeName + value: + stringValue: scopeA + - key: scopeNameAgain + value: + stringValue: scopeA + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB + - attributes: + - key: scopeName + value: + stringValue: scopeB + - key: scopeNameAgain + value: + stringValue: scopeB + spans: + - attributes: + - key: spanName + value: + stringValue: spanA + - key: spanNameAgain + value: + stringValue: spanA + name: spanA + - attributes: + - key: spanName + value: + stringValue: spanB + - key: spanNameAgain + value: + stringValue: spanB + name: spanB diff --git a/connector/routingconnector/internal/ptraceutil/traces.go b/connector/routingconnector/internal/ptraceutil/traces.go new file mode 100644 index 000000000000..4f925fb98fcb --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/traces.go @@ -0,0 +1,18 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package ptraceutil // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/routingconnector/internal/ptraceutil" + +import "go.opentelemetry.io/collector/pdata/ptrace" + +// MoveResourcesIf calls f sequentially for each ResourceSpans present in the first ptrace.Traces. +// If f returns true, the element is removed from the first ptrace.Traces and added to the second ptrace.Traces. +func MoveResourcesIf(from, to ptrace.Traces, f func(ptrace.ResourceSpans) bool) { + from.ResourceSpans().RemoveIf(func(rs ptrace.ResourceSpans) bool { + if !f(rs) { + return false + } + rs.CopyTo(to.ResourceSpans().AppendEmpty()) + return true + }) +} diff --git a/connector/routingconnector/internal/ptraceutil/traces_test.go b/connector/routingconnector/internal/ptraceutil/traces_test.go new file mode 100644 index 000000000000..1946cb3ca7ab --- /dev/null +++ b/connector/routingconnector/internal/ptraceutil/traces_test.go @@ -0,0 +1,73 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package ptraceutil_test + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/pdata/ptrace" + + "github.com/open-telemetry/opentelemetry-collector-contrib/connector/routingconnector/internal/ptraceutil" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/ptracetest" +) + +func TestMoveResourcesIf(t *testing.T) { + testCases := []struct { + name string + condition func(ptrace.ResourceSpans) bool + }{ + { + name: "move_none", + condition: func(ptrace.ResourceSpans) bool { + return false + }, + }, + { + name: "move_all", + condition: func(ptrace.ResourceSpans) bool { + return true + }, + }, + { + name: "move_one", + condition: func(rl ptrace.ResourceSpans) bool { + rname, ok := rl.Resource().Attributes().Get("resourceName") + return ok && rname.AsString() == "resourceA" + }, + }, + { + name: "move_to_preexisting", + condition: func(rl ptrace.ResourceSpans) bool { + rname, ok := rl.Resource().Attributes().Get("resourceName") + return ok && rname.AsString() == "resourceB" + }, + }, + } + + for _, tt := range testCases { + t.Run(tt.name, func(t *testing.T) { + // Load up a fresh copy of the input for each test, since it may be modified in place. + from, err := golden.ReadTraces(filepath.Join("testdata", "resource", tt.name, "from.yaml")) + require.NoError(t, err) + + to, err := golden.ReadTraces(filepath.Join("testdata", "resource", tt.name, "to.yaml")) + require.NoError(t, err) + + fromModifed, err := golden.ReadTraces(filepath.Join("testdata", "resource", tt.name, "from_modified.yaml")) + require.NoError(t, err) + + toModified, err := golden.ReadTraces(filepath.Join("testdata", "resource", tt.name, "to_modified.yaml")) + require.NoError(t, err) + + ptraceutil.MoveResourcesIf(from, to, tt.condition) + + assert.NoError(t, ptracetest.CompareTraces(fromModifed, from), "from not modified as expected") + assert.NoError(t, ptracetest.CompareTraces(toModified, to), "to not as expected") + }) + } +} diff --git a/connector/routingconnector/logs.go b/connector/routingconnector/logs.go index deaf20bebf64..20ef54979832 100644 --- a/connector/routingconnector/logs.go +++ b/connector/routingconnector/logs.go @@ -65,7 +65,7 @@ func (c *logsConnector) ConsumeLogs(ctx context.Context, ld plog.Logs) error { if c.config.MatchOnce { return c.switchLogs(ctx, ld) } - return c.matchAll(ctx, ld) + return c.matchAllLogs(ctx, ld) } // switchLogs removes items from the original plog.Logs as they are matched, @@ -73,13 +73,13 @@ func (c *logsConnector) ConsumeLogs(ctx context.Context, ld plog.Logs) error { func (c *logsConnector) switchLogs(ctx context.Context, ld plog.Logs) error { groups := make(map[consumer.Logs]plog.Logs) var errs error - for i := 0; i < len(c.router.routeSlice) && ld.LogRecordCount() > 0; i++ { + for i := 0; i < len(c.router.routeSlice) && ld.ResourceLogs().Len() > 0; i++ { route := c.router.routeSlice[i] matchedLogs := plog.NewLogs() switch route.statementContext { case "request": if route.requestCondition.matchRequest(ctx) { - groupAll(groups, route.consumer, ld) + groupAllLogs(groups, route.consumer, ld) ld = plog.NewLogs() // all logs have been routed } case "", "resource": @@ -105,19 +105,19 @@ func (c *logsConnector) switchLogs(ctx context.Context, ld plog.Logs) error { if c.config.ErrorMode == ottl.PropagateError { return errs } - groupAll(groups, c.router.defaultConsumer, matchedLogs) + groupAllLogs(groups, c.router.defaultConsumer, matchedLogs) } - groupAll(groups, route.consumer, matchedLogs) + groupAllLogs(groups, route.consumer, matchedLogs) } // anything left wasn't matched by any route. Send to default consumer - groupAll(groups, c.router.defaultConsumer, ld) + groupAllLogs(groups, c.router.defaultConsumer, ld) for consumer, group := range groups { errs = errors.Join(errs, consumer.ConsumeLogs(ctx, group)) } return errs } -func (c *logsConnector) matchAll(ctx context.Context, ld plog.Logs) error { +func (c *logsConnector) matchAllLogs(ctx context.Context, ld plog.Logs) error { // routingEntry is used to group plog.ResourceLogs that are routed to // the same set of exporters. // This way we're not ending up with all the logs split up which would cause @@ -134,17 +134,17 @@ func (c *logsConnector) matchAll(ctx context.Context, ld plog.Logs) error { if c.config.ErrorMode == ottl.PropagateError { return err } - group(groups, c.router.defaultConsumer, rlogs) + groupLogs(groups, c.router.defaultConsumer, rlogs) continue } if isMatch { noRoutesMatch = false - group(groups, route.consumer, rlogs) + groupLogs(groups, route.consumer, rlogs) } } if noRoutesMatch { // no route conditions are matched, add resource logs to default exporters group - group(groups, c.router.defaultConsumer, rlogs) + groupLogs(groups, c.router.defaultConsumer, rlogs) } } for consumer, group := range groups { @@ -153,17 +153,17 @@ func (c *logsConnector) matchAll(ctx context.Context, ld plog.Logs) error { return errs } -func groupAll( +func groupAllLogs( groups map[consumer.Logs]plog.Logs, cons consumer.Logs, logs plog.Logs, ) { for i := 0; i < logs.ResourceLogs().Len(); i++ { - group(groups, cons, logs.ResourceLogs().At(i)) + groupLogs(groups, cons, logs.ResourceLogs().At(i)) } } -func group( +func groupLogs( groups map[consumer.Logs]plog.Logs, cons consumer.Logs, logs plog.ResourceLogs, diff --git a/connector/routingconnector/metrics.go b/connector/routingconnector/metrics.go index 6bf9508a6ef2..025a5bc95bb5 100644 --- a/connector/routingconnector/metrics.go +++ b/connector/routingconnector/metrics.go @@ -13,6 +13,7 @@ import ( "go.opentelemetry.io/collector/pdata/pmetric" "go.uber.org/zap" + "github.com/open-telemetry/opentelemetry-collector-contrib/connector/routingconnector/internal/pmetricutil" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlresource" ) @@ -60,13 +61,52 @@ func (c *metricsConnector) Capabilities() consumer.Capabilities { } func (c *metricsConnector) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error { + if c.config.MatchOnce { + return c.switchMetrics(ctx, md) + } + return c.matchAllMetrics(ctx, md) +} + +func (c *metricsConnector) switchMetrics(ctx context.Context, md pmetric.Metrics) error { + groups := make(map[consumer.Metrics]pmetric.Metrics) + var errs error + for i := 0; i < len(c.router.routeSlice) && md.ResourceMetrics().Len() > 0; i++ { + route := c.router.routeSlice[i] + matchedMetrics := pmetric.NewMetrics() + switch route.statementContext { + case "", "resource": + pmetricutil.MoveResourcesIf(md, matchedMetrics, + func(rs pmetric.ResourceMetrics) bool { + rtx := ottlresource.NewTransformContext(rs.Resource(), rs) + _, isMatch, err := route.resourceStatement.Execute(ctx, rtx) + errs = errors.Join(errs, err) + return isMatch + }, + ) + } + if errs != nil { + if c.config.ErrorMode == ottl.PropagateError { + return errs + } + groupAllMetrics(groups, c.router.defaultConsumer, matchedMetrics) + } + groupAllMetrics(groups, route.consumer, matchedMetrics) + } + // anything left wasn't matched by any route. Send to default consumer + groupAllMetrics(groups, c.router.defaultConsumer, md) + for consumer, group := range groups { + errs = errors.Join(errs, consumer.ConsumeMetrics(ctx, group)) + } + return errs +} + +func (c *metricsConnector) matchAllMetrics(ctx context.Context, md pmetric.Metrics) error { // groups is used to group pmetric.ResourceMetrics that are routed to // the same set of exporters. This way we're not ending up with all the // metrics split up which would cause higher CPU usage. groups := make(map[consumer.Metrics]pmetric.Metrics) var errs error - for i := 0; i < md.ResourceMetrics().Len(); i++ { rmetrics := md.ResourceMetrics().At(i) rtx := ottlresource.NewTransformContext(rmetrics.Resource(), rmetrics) @@ -78,32 +118,37 @@ func (c *metricsConnector) ConsumeMetrics(ctx context.Context, md pmetric.Metric if c.config.ErrorMode == ottl.PropagateError { return err } - c.group(groups, c.router.defaultConsumer, rmetrics) + groupMetrics(groups, c.router.defaultConsumer, rmetrics) continue } if isMatch { noRoutesMatch = false - c.group(groups, route.consumer, rmetrics) - if c.config.MatchOnce { - break - } + groupMetrics(groups, route.consumer, rmetrics) } } - if noRoutesMatch { // no route conditions are matched, add resource metrics to default exporters group - c.group(groups, c.router.defaultConsumer, rmetrics) + groupMetrics(groups, c.router.defaultConsumer, rmetrics) } } - for consumer, group := range groups { errs = errors.Join(errs, consumer.ConsumeMetrics(ctx, group)) } return errs } -func (c *metricsConnector) group( +func groupAllMetrics( + groups map[consumer.Metrics]pmetric.Metrics, + cons consumer.Metrics, + metrics pmetric.Metrics, +) { + for i := 0; i < metrics.ResourceMetrics().Len(); i++ { + groupMetrics(groups, cons, metrics.ResourceMetrics().At(i)) + } +} + +func groupMetrics( groups map[consumer.Metrics]pmetric.Metrics, consumer consumer.Metrics, metrics pmetric.ResourceMetrics, diff --git a/connector/routingconnector/traces.go b/connector/routingconnector/traces.go index 98906fd82460..dd5966e6a66d 100644 --- a/connector/routingconnector/traces.go +++ b/connector/routingconnector/traces.go @@ -13,6 +13,7 @@ import ( "go.opentelemetry.io/collector/pdata/ptrace" "go.uber.org/zap" + "github.com/open-telemetry/opentelemetry-collector-contrib/connector/routingconnector/internal/ptraceutil" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlresource" ) @@ -59,17 +60,56 @@ func (*tracesConnector) Capabilities() consumer.Capabilities { return consumer.Capabilities{MutatesData: false} } -func (c *tracesConnector) ConsumeTraces(ctx context.Context, t ptrace.Traces) error { +func (c *tracesConnector) ConsumeTraces(ctx context.Context, td ptrace.Traces) error { + if c.config.MatchOnce { + return c.switchTraces(ctx, td) + } + return c.matchAllTraces(ctx, td) +} + +func (c *tracesConnector) switchTraces(ctx context.Context, td ptrace.Traces) error { + groups := make(map[consumer.Traces]ptrace.Traces) + var errs error + for i := 0; i < len(c.router.routeSlice) && td.ResourceSpans().Len() > 0; i++ { + route := c.router.routeSlice[i] + matchedSpans := ptrace.NewTraces() + switch route.statementContext { + case "", "resource": + ptraceutil.MoveResourcesIf(td, matchedSpans, + func(rs ptrace.ResourceSpans) bool { + rtx := ottlresource.NewTransformContext(rs.Resource(), rs) + _, isMatch, err := route.resourceStatement.Execute(ctx, rtx) + errs = errors.Join(errs, err) + return isMatch + }, + ) + } + if errs != nil { + if c.config.ErrorMode == ottl.PropagateError { + return errs + } + groupAllTraces(groups, c.router.defaultConsumer, matchedSpans) + } + groupAllTraces(groups, route.consumer, matchedSpans) + } + // anything left wasn't matched by any route. Send to default consumer + groupAllTraces(groups, c.router.defaultConsumer, td) + for consumer, group := range groups { + errs = errors.Join(errs, consumer.ConsumeTraces(ctx, group)) + } + return errs +} + +func (c *tracesConnector) matchAllTraces(ctx context.Context, td ptrace.Traces) error { // groups is used to group ptrace.ResourceSpans that are routed to // the same set of pipelines. This way we're not ending up with all the // spans split up which would cause higher CPU usage. groups := make(map[consumer.Traces]ptrace.Traces) var errs error - for i := 0; i < t.ResourceSpans().Len(); i++ { - rspans := t.ResourceSpans().At(i) + for i := 0; i < td.ResourceSpans().Len(); i++ { + rspans := td.ResourceSpans().At(i) rtx := ottlresource.NewTransformContext(rspans.Resource(), rspans) - noRoutesMatch := true for _, route := range c.router.routeSlice { _, isMatch, err := route.resourceStatement.Execute(ctx, rtx) @@ -77,43 +117,48 @@ func (c *tracesConnector) ConsumeTraces(ctx context.Context, t ptrace.Traces) er if c.config.ErrorMode == ottl.PropagateError { return err } - c.group(groups, c.router.defaultConsumer, rspans) + groupTraces(groups, c.router.defaultConsumer, rspans) continue } if isMatch { noRoutesMatch = false - c.group(groups, route.consumer, rspans) - if c.config.MatchOnce { - break - } + groupTraces(groups, route.consumer, rspans) } } - if noRoutesMatch { // no route conditions are matched, add resource spans to default pipelines group - c.group(groups, c.router.defaultConsumer, rspans) + groupTraces(groups, c.router.defaultConsumer, rspans) } } - for consumer, group := range groups { errs = errors.Join(errs, consumer.ConsumeTraces(ctx, group)) } return errs } -func (c *tracesConnector) group( +func groupAllTraces( + groups map[consumer.Traces]ptrace.Traces, + cons consumer.Traces, + traces ptrace.Traces, +) { + for i := 0; i < traces.ResourceSpans().Len(); i++ { + groupTraces(groups, cons, traces.ResourceSpans().At(i)) + } +} + +func groupTraces( groups map[consumer.Traces]ptrace.Traces, - consumer consumer.Traces, + cons consumer.Traces, spans ptrace.ResourceSpans, ) { - if consumer == nil { + if cons == nil { return } - group, ok := groups[consumer] + group, ok := groups[cons] if !ok { group = ptrace.NewTraces() } spans.CopyTo(group.ResourceSpans().AppendEmpty()) - groups[consumer] = group + groups[cons] = group }