From 740d9aa2ccdd74b825d866486efb507e1282362f Mon Sep 17 00:00:00 2001 From: Daniel Jaglowski Date: Mon, 4 Nov 2024 19:08:18 -0500 Subject: [PATCH] [chore][connector/routing] Migrate traces test to concise format (#36165) --- connector/routingconnector/go.mod | 1 - .../internal/plogutiltest/logs.go | 20 +- .../internal/pmetricutiltest/metrics.go | 24 +-- .../internal/pmetricutiltest/metrics_test.go | 2 +- .../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_test.go | 61 +++--- .../internal/ptraceutiltest/traces.go | 44 ++++ .../internal/ptraceutiltest/traces_test.go | 122 +++++++++++ connector/routingconnector/logs_test.go | 2 +- connector/routingconnector/metrics_test.go | 2 +- .../all_match_first_only/config.yaml | 10 - .../all_match_first_only/input.yaml | 117 ---------- .../all_match_first_only/sink_0.yaml | 117 ---------- .../all_match_last_only/config.yaml | 10 - .../all_match_last_only/input.yaml | 117 ---------- .../all_match_last_only/sink_1.yaml | 117 ---------- .../all_match_once/config.yaml | 11 - .../all_match_once/input.yaml | 117 ---------- .../all_match_once/sink_0.yaml | 117 ---------- .../each_matches_one/config.yaml | 10 - .../each_matches_one/input.yaml | 117 ---------- .../each_matches_one/sink_0.yaml | 59 ------ .../each_matches_one/sink_1.yaml | 59 ------ .../match_none_with_default/config.yaml | 10 - .../match_none_with_default/input.yaml | 117 ---------- .../match_none_with_default/sink_default.yaml | 117 ---------- .../match_none_without_default/config.yaml | 10 - .../match_none_without_default/input.yaml | 117 ---------- connector/routingconnector/traces_test.go | 199 ++++++++++++------ 44 files changed, 355 insertions(+), 2529 deletions(-) delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/from.yaml delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/from_modified.yaml delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/to.yaml delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/to_modified.yaml delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/from.yaml delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/from_modified.yaml delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/to.yaml delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/to_modified.yaml delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/from.yaml delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/from_modified.yaml delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/to.yaml delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/to_modified.yaml delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/from.yaml delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/from_modified.yaml delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/to.yaml delete mode 100644 connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/to_modified.yaml create mode 100644 connector/routingconnector/internal/ptraceutiltest/traces.go create mode 100644 connector/routingconnector/internal/ptraceutiltest/traces_test.go delete mode 100644 connector/routingconnector/testdata/traces/resource_context/all_match_first_only/config.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/all_match_first_only/input.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/all_match_first_only/sink_0.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/all_match_last_only/config.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/all_match_last_only/input.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/all_match_last_only/sink_1.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/all_match_once/config.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/all_match_once/input.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/all_match_once/sink_0.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/each_matches_one/config.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/each_matches_one/input.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/each_matches_one/sink_0.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/each_matches_one/sink_1.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/match_none_with_default/config.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/match_none_with_default/input.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/match_none_with_default/sink_default.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/match_none_without_default/config.yaml delete mode 100644 connector/routingconnector/testdata/traces/resource_context/match_none_without_default/input.yaml diff --git a/connector/routingconnector/go.mod b/connector/routingconnector/go.mod index 9edafd5f58aa..3a944677b5ad 100644 --- a/connector/routingconnector/go.mod +++ b/connector/routingconnector/go.mod @@ -3,7 +3,6 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/connector/routi go 1.22.0 require ( - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.112.0 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.112.0 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.112.0 github.com/stretchr/testify v1.9.0 diff --git a/connector/routingconnector/internal/plogutiltest/logs.go b/connector/routingconnector/internal/plogutiltest/logs.go index c8190bbe2179..034162eb25b8 100644 --- a/connector/routingconnector/internal/plogutiltest/logs.go +++ b/connector/routingconnector/internal/plogutiltest/logs.go @@ -20,17 +20,17 @@ import "go.opentelemetry.io/collector/pdata/plog" // each with log1, log2, log3, log4 // // Each byte in the input string is a unique ID for the corresponding element. -func NewLogs(rIDs, sIDs, lIDs string) plog.Logs { +func NewLogs(resourceIDs, scopeIDs, logRecordIDs string) plog.Logs { ld := plog.NewLogs() - for ri := 0; ri < len(rIDs); ri++ { - r := ld.ResourceLogs().AppendEmpty() - r.Resource().Attributes().PutStr("resourceName", "resource"+string(rIDs[ri])) - for si := 0; si < len(sIDs); si++ { - s := r.ScopeLogs().AppendEmpty() - s.Scope().SetName("scope" + string(sIDs[si])) - for li := 0; li < len(lIDs); li++ { - m := s.LogRecords().AppendEmpty() - m.Body().SetStr("log" + string(lIDs[li])) + for resourceN := 0; resourceN < len(resourceIDs); resourceN++ { + rl := ld.ResourceLogs().AppendEmpty() + rl.Resource().Attributes().PutStr("resourceName", "resource"+string(resourceIDs[resourceN])) + for scopeN := 0; scopeN < len(scopeIDs); scopeN++ { + sl := rl.ScopeLogs().AppendEmpty() + sl.Scope().SetName("scope" + string(scopeIDs[scopeN])) + for logRecordN := 0; logRecordN < len(logRecordIDs); logRecordN++ { + lr := sl.LogRecords().AppendEmpty() + lr.Body().SetStr("log" + string(logRecordIDs[logRecordN])) } } } diff --git a/connector/routingconnector/internal/pmetricutiltest/metrics.go b/connector/routingconnector/internal/pmetricutiltest/metrics.go index 79aecf26743a..ce8b2cb06d5e 100644 --- a/connector/routingconnector/internal/pmetricutiltest/metrics.go +++ b/connector/routingconnector/internal/pmetricutiltest/metrics.go @@ -22,21 +22,21 @@ import "go.opentelemetry.io/collector/pdata/pmetric" // each with dp1, dp2, dp3, dp4 // // Each byte in the input string is a unique ID for the corresponding element. -func NewMetrics(rIDs, sIDs, mIDs, dpIDs string) pmetric.Metrics { +func NewMetrics(resourceIDs, scopeIDs, metricIDs, dataPointIDs string) pmetric.Metrics { md := pmetric.NewMetrics() - for ri := 0; ri < len(rIDs); ri++ { - r := md.ResourceMetrics().AppendEmpty() - r.Resource().Attributes().PutStr("resourceName", "resource"+string(rIDs[ri])) - for si := 0; si < len(sIDs); si++ { - s := r.ScopeMetrics().AppendEmpty() - s.Scope().SetName("scope" + string(sIDs[si])) - for mi := 0; mi < len(mIDs); mi++ { - m := s.Metrics().AppendEmpty() - m.SetName("metric" + string(mIDs[mi])) + for resourceN := 0; resourceN < len(resourceIDs); resourceN++ { + rm := md.ResourceMetrics().AppendEmpty() + rm.Resource().Attributes().PutStr("resourceName", "resource"+string(resourceIDs[resourceN])) + for scopeN := 0; scopeN < len(scopeIDs); scopeN++ { + sm := rm.ScopeMetrics().AppendEmpty() + sm.Scope().SetName("scope" + string(scopeIDs[scopeN])) + for metricN := 0; metricN < len(metricIDs); metricN++ { + m := sm.Metrics().AppendEmpty() + m.SetName("metric" + string(metricIDs[metricN])) dps := m.SetEmptyGauge() - for di := 0; di < len(dpIDs); di++ { + for dataPointN := 0; dataPointN < len(dataPointIDs); dataPointN++ { dp := dps.DataPoints().AppendEmpty() - dp.Attributes().PutStr("dpName", "dp"+string(dpIDs[di])) + dp.Attributes().PutStr("dpName", "dp"+string(dataPointIDs[dataPointN])) } } } diff --git a/connector/routingconnector/internal/pmetricutiltest/metrics_test.go b/connector/routingconnector/internal/pmetricutiltest/metrics_test.go index 26c2c1e3e162..069a27f8282c 100644 --- a/connector/routingconnector/internal/pmetricutiltest/metrics_test.go +++ b/connector/routingconnector/internal/pmetricutiltest/metrics_test.go @@ -57,7 +57,7 @@ func TestNewMetrics(t *testing.T) { m.SetName("metricD") // resourceB.scopeC.metricD dps = m.SetEmptyGauge() dp = dps.DataPoints().AppendEmpty() - dp.Attributes().PutStr("dpName", "dpE") // resource.scopeC.metricD.dpE + dp.Attributes().PutStr("dpName", "dpE") // resourceB.scopeC.metricD.dpE return md }() assert.NoError(t, pmetrictest.CompareMetrics(expected, pmetricutiltest.NewMetrics("AB", "C", "D", "E"))) diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/from.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/from.yaml deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/from.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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 deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/to.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/to.yaml deleted file mode 100644 index e69de29bb2d1..000000000000 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 deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_all/to_modified.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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 deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/from.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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 deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/from_modified.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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 deleted file mode 100644 index 8b137891791f..000000000000 --- a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/to.yaml +++ /dev/null @@ -1 +0,0 @@ - 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 deleted file mode 100644 index 8b137891791f..000000000000 --- a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_none/to_modified.yaml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/from.yaml b/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/from.yaml deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/from.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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 deleted file mode 100644 index 638861efcf92..000000000000 --- a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/from_modified.yaml +++ /dev/null @@ -1,59 +0,0 @@ -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 deleted file mode 100644 index 8b137891791f..000000000000 --- a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/to.yaml +++ /dev/null @@ -1 +0,0 @@ - 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 deleted file mode 100644 index 5c862eb1178f..000000000000 --- a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_one/to_modified.yaml +++ /dev/null @@ -1,59 +0,0 @@ -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 deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/from.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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 deleted file mode 100644 index 5c862eb1178f..000000000000 --- a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/from_modified.yaml +++ /dev/null @@ -1,59 +0,0 @@ -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 deleted file mode 100644 index b0164a87a261..000000000000 --- a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/to.yaml +++ /dev/null @@ -1,59 +0,0 @@ -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 deleted file mode 100644 index e8294e1e690b..000000000000 --- a/connector/routingconnector/internal/ptraceutil/testdata/resource/move_to_preexisting/to_modified.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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_test.go b/connector/routingconnector/internal/ptraceutil/traces_test.go index 1946cb3ca7ab..7a47633e2e8e 100644 --- a/connector/routingconnector/internal/ptraceutil/traces_test.go +++ b/connector/routingconnector/internal/ptraceutil/traces_test.go @@ -4,70 +4,79 @@ 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/connector/routingconnector/internal/ptraceutiltest" "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 string + moveIf func(ptrace.ResourceSpans) bool + from ptrace.Traces + to ptrace.Traces + expectFrom ptrace.Traces + expectTo ptrace.Traces }{ { name: "move_none", - condition: func(ptrace.ResourceSpans) bool { + moveIf: func(ptrace.ResourceSpans) bool { return false }, + from: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + to: ptrace.NewTraces(), + expectFrom: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + expectTo: ptrace.NewTraces(), }, { name: "move_all", - condition: func(ptrace.ResourceSpans) bool { + moveIf: func(ptrace.ResourceSpans) bool { return true }, + from: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + to: ptrace.NewTraces(), + expectFrom: ptrace.NewTraces(), + expectTo: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), }, { name: "move_one", - condition: func(rl ptrace.ResourceSpans) bool { + moveIf: func(rl ptrace.ResourceSpans) bool { rname, ok := rl.Resource().Attributes().Get("resourceName") return ok && rname.AsString() == "resourceA" }, + from: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + to: ptrace.NewTraces(), + expectFrom: ptraceutiltest.NewTraces("B", "CD", "EF", "FG"), + expectTo: ptraceutiltest.NewTraces("A", "CD", "EF", "FG"), }, { name: "move_to_preexisting", - condition: func(rl ptrace.ResourceSpans) bool { + moveIf: func(rl ptrace.ResourceSpans) bool { rname, ok := rl.Resource().Attributes().Get("resourceName") return ok && rname.AsString() == "resourceB" }, + from: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + to: ptraceutiltest.NewTraces("1", "2", "3", "4"), + expectFrom: ptraceutiltest.NewTraces("A", "CD", "EF", "FG"), + expectTo: func() ptrace.Traces { + move := ptraceutiltest.NewTraces("B", "CD", "EF", "FG") + moveTo := ptraceutiltest.NewTraces("1", "2", "3", "4") + move.ResourceSpans().MoveAndAppendTo(moveTo.ResourceSpans()) + return moveTo + }(), }, } 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") + ptraceutil.MoveResourcesIf(tt.from, tt.to, tt.moveIf) + assert.NoError(t, ptracetest.CompareTraces(tt.expectFrom, tt.from), "from not modified as expected") + assert.NoError(t, ptracetest.CompareTraces(tt.expectTo, tt.to), "to not as expected") }) } } diff --git a/connector/routingconnector/internal/ptraceutiltest/traces.go b/connector/routingconnector/internal/ptraceutiltest/traces.go new file mode 100644 index 000000000000..863eeb888b58 --- /dev/null +++ b/connector/routingconnector/internal/ptraceutiltest/traces.go @@ -0,0 +1,44 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package ptraceutiltest // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/routingconnector/internal/ptraceutiltest" + +import "go.opentelemetry.io/collector/pdata/ptrace" + +// TestTraces returns a ptrace.Traces with a uniform structure where resources, scopes, spans, +// and spanevents are identical across all instances, except for one identifying field. +// +// Identifying fields: +// - Resources have an attribute called "resourceName" with a value of "resourceN". +// - Scopes have a name with a value of "scopeN". +// - Spans have a name with a value of "spanN". +// - Span Events have an attribute "spanEventName" with a value of "spanEventN". +// +// Example: TestTraces("AB", "XYZ", "MN", "1234") returns: +// +// resourceA, resourceB +// each with scopeX, scopeY, scopeZ +// each with spanM, spanN +// each with spanEvent1, spanEvent2, spanEvent3, spanEvent4 +// +// Each byte in the input string is a unique ID for the corresponding element. +func NewTraces(resourceIDs, scopeIDs, spanIDs, spanEventIDs string) ptrace.Traces { + td := ptrace.NewTraces() + for resourceN := 0; resourceN < len(resourceIDs); resourceN++ { + rs := td.ResourceSpans().AppendEmpty() + rs.Resource().Attributes().PutStr("resourceName", "resource"+string(resourceIDs[resourceN])) + for scopeN := 0; scopeN < len(scopeIDs); scopeN++ { + ss := rs.ScopeSpans().AppendEmpty() + ss.Scope().SetName("scope" + string(scopeIDs[scopeN])) + for spanN := 0; spanN < len(spanIDs); spanN++ { + s := ss.Spans().AppendEmpty() + s.SetName("span" + string(spanIDs[spanN])) + for spanEventN := 0; spanEventN < len(spanEventIDs); spanEventN++ { + se := s.Events().AppendEmpty() + se.Attributes().PutStr("spanEventName", "spanEvent"+string(spanEventIDs[spanEventN])) + } + } + } + } + return td +} diff --git a/connector/routingconnector/internal/ptraceutiltest/traces_test.go b/connector/routingconnector/internal/ptraceutiltest/traces_test.go new file mode 100644 index 000000000000..0de27955b630 --- /dev/null +++ b/connector/routingconnector/internal/ptraceutiltest/traces_test.go @@ -0,0 +1,122 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package ptraceutiltest_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/pdata/ptrace" + + "github.com/open-telemetry/opentelemetry-collector-contrib/connector/routingconnector/internal/ptraceutiltest" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/ptracetest" +) + +func TestNewTraces(t *testing.T) { + + t.Run("empty", func(t *testing.T) { + expected := ptrace.NewTraces() + assert.NoError(t, ptracetest.CompareTraces(expected, ptraceutiltest.NewTraces("", "", "", ""))) + }) + + t.Run("simple", func(t *testing.T) { + expected := func() ptrace.Traces { + td := ptrace.NewTraces() + rs := td.ResourceSpans().AppendEmpty() + rs.Resource().Attributes().PutStr("resourceName", "resourceA") // resourceA + ss := rs.ScopeSpans().AppendEmpty() + ss.Scope().SetName("scopeB") // resourceA.scopeB + s := ss.Spans().AppendEmpty() + s.SetName("spanC") // resourceA.scopeB.spanC + se := s.Events().AppendEmpty() + se.Attributes().PutStr("spanEventName", "spanEventD") // resourceA.scopeB.spanC.spanEventD + return td + }() + assert.NoError(t, ptracetest.CompareTraces(expected, ptraceutiltest.NewTraces("A", "B", "C", "D"))) + }) + + t.Run("two_resources", func(t *testing.T) { + expected := func() ptrace.Traces { + td := ptrace.NewTraces() + rs := td.ResourceSpans().AppendEmpty() + rs.Resource().Attributes().PutStr("resourceName", "resourceA") // resourceA + ss := rs.ScopeSpans().AppendEmpty() + ss.Scope().SetName("scopeC") // resourceA.scopeC + s := ss.Spans().AppendEmpty() + s.SetName("spanD") // resourceA.scopeC.spanD + se := s.Events().AppendEmpty() + se.Attributes().PutStr("spanEventName", "spanEventE") // resourceA.scopeC.spanD.spanEventE + rs = td.ResourceSpans().AppendEmpty() + rs.Resource().Attributes().PutStr("resourceName", "resourceB") // resourceB + ss = rs.ScopeSpans().AppendEmpty() + ss.Scope().SetName("scopeC") // resourceB.scopeC + s = ss.Spans().AppendEmpty() + s.SetName("spanD") // resourceB.scopeC.spanD + se = s.Events().AppendEmpty() + se.Attributes().PutStr("spanEventName", "spanEventE") // resourceB.scopeC.spanD.spanEventE + return td + }() + assert.NoError(t, ptracetest.CompareTraces(expected, ptraceutiltest.NewTraces("AB", "C", "D", "E"))) + }) + + t.Run("two_scopes", func(t *testing.T) { + expected := func() ptrace.Traces { + td := ptrace.NewTraces() + rs := td.ResourceSpans().AppendEmpty() + rs.Resource().Attributes().PutStr("resourceName", "resourceA") // resourceA + ss := rs.ScopeSpans().AppendEmpty() + ss.Scope().SetName("scopeB") // resourceA.scopeB + s := ss.Spans().AppendEmpty() + s.SetName("spanD") // resourceA.scopeB.spanD + se := s.Events().AppendEmpty() + se.Attributes().PutStr("spanEventName", "spanEventE") // resourceA.scopeB.spanD.spanEventE + ss = rs.ScopeSpans().AppendEmpty() + ss.Scope().SetName("scopeC") // resourceA.scopeC + s = ss.Spans().AppendEmpty() + s.SetName("spanD") // resourceA.scopeC.spanD + se = s.Events().AppendEmpty() + se.Attributes().PutStr("spanEventName", "spanEventE") // resourceA.scopeC.spanD.spanEventE + return td + }() + assert.NoError(t, ptracetest.CompareTraces(expected, ptraceutiltest.NewTraces("A", "BC", "D", "E"))) + }) + + t.Run("two_spans", func(t *testing.T) { + expected := func() ptrace.Traces { + td := ptrace.NewTraces() + rs := td.ResourceSpans().AppendEmpty() + rs.Resource().Attributes().PutStr("resourceName", "resourceA") // resourceA + ss := rs.ScopeSpans().AppendEmpty() + ss.Scope().SetName("scopeB") // resourceA.scopeB + s := ss.Spans().AppendEmpty() + s.SetName("spanC") // resourceA.scopeB.spanC + se := s.Events().AppendEmpty() + se.Attributes().PutStr("spanEventName", "spanEventE") // resourceA.scopeB.spanC.spanEventE + s = ss.Spans().AppendEmpty() + s.SetName("spanD") // resourceA.scopeB.spanD + se = s.Events().AppendEmpty() + se.Attributes().PutStr("spanEventName", "spanEventE") // resourceA.scopeB.spanD.spanEventE + return td + }() + assert.NoError(t, ptracetest.CompareTraces(expected, ptraceutiltest.NewTraces("A", "B", "CD", "E"))) + }) + + t.Run("two_spanevents", func(t *testing.T) { + expected := func() ptrace.Traces { + td := ptrace.NewTraces() + rs := td.ResourceSpans().AppendEmpty() + rs.Resource().Attributes().PutStr("resourceName", "resourceA") // resourceA + ss := rs.ScopeSpans().AppendEmpty() + ss.Scope().SetName("scopeB") // resourceA.scopeB + s := ss.Spans().AppendEmpty() + s.SetName("spanC") // resourceA.scopeB.spanC + se := s.Events().AppendEmpty() + se.Attributes().PutStr("spanEventName", "spanEventD") // resourceA.scopeB.spanC.spanEventD + se = s.Events().AppendEmpty() + se.Attributes().PutStr("spanEventName", "spanEventE") // resourceA.scopeB.spanC.spanEventE + return td + }() + assert.NoError(t, ptracetest.CompareTraces(expected, ptraceutiltest.NewTraces("A", "B", "C", "DE"))) + }) +} diff --git a/connector/routingconnector/logs_test.go b/connector/routingconnector/logs_test.go index cc558b51865e..2fefc28b4b97 100644 --- a/connector/routingconnector/logs_test.go +++ b/connector/routingconnector/logs_test.go @@ -468,7 +468,7 @@ func TestLogsConnectorCapabilities(t *testing.T) { assert.False(t, conn.Capabilities().MutatesData) } -func TestLogsConnectorDetailedConcise(t *testing.T) { +func TestLogsConnectorDetailed(t *testing.T) { idSink0 := pipeline.NewIDWithName(pipeline.SignalLogs, "0") idSink1 := pipeline.NewIDWithName(pipeline.SignalLogs, "1") idSinkD := pipeline.NewIDWithName(pipeline.SignalLogs, "default") diff --git a/connector/routingconnector/metrics_test.go b/connector/routingconnector/metrics_test.go index 44ace2f466e7..661d182c7760 100644 --- a/connector/routingconnector/metrics_test.go +++ b/connector/routingconnector/metrics_test.go @@ -498,7 +498,7 @@ func TestMetricsConnectorCapabilities(t *testing.T) { assert.False(t, conn.Capabilities().MutatesData) } -func TestMetricsConnectorDetailedConcise(t *testing.T) { +func TestMetricsConnectorDetailed(t *testing.T) { idSink0 := pipeline.NewIDWithName(pipeline.SignalMetrics, "0") idSink1 := pipeline.NewIDWithName(pipeline.SignalMetrics, "1") idSinkD := pipeline.NewIDWithName(pipeline.SignalMetrics, "default") diff --git a/connector/routingconnector/testdata/traces/resource_context/all_match_first_only/config.yaml b/connector/routingconnector/testdata/traces/resource_context/all_match_first_only/config.yaml deleted file mode 100644 index beded866152d..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/all_match_first_only/config.yaml +++ /dev/null @@ -1,10 +0,0 @@ -routing: - default_pipelines: - - traces/default - table: - - condition: attributes["resourceName"] != nil - pipelines: - - traces/0 - - condition: attributes["resourceName"] == "resourceY" - pipelines: - - traces/1 diff --git a/connector/routingconnector/testdata/traces/resource_context/all_match_first_only/input.yaml b/connector/routingconnector/testdata/traces/resource_context/all_match_first_only/input.yaml deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/all_match_first_only/input.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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/testdata/traces/resource_context/all_match_first_only/sink_0.yaml b/connector/routingconnector/testdata/traces/resource_context/all_match_first_only/sink_0.yaml deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/all_match_first_only/sink_0.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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/testdata/traces/resource_context/all_match_last_only/config.yaml b/connector/routingconnector/testdata/traces/resource_context/all_match_last_only/config.yaml deleted file mode 100644 index a8e0472a0dea..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/all_match_last_only/config.yaml +++ /dev/null @@ -1,10 +0,0 @@ -routing: - default_pipelines: - - traces/default - table: - - condition: attributes["resourceName"] == "resourceX" - pipelines: - - traces/0 - - condition: attributes["resourceName"] != nil - pipelines: - - traces/1 diff --git a/connector/routingconnector/testdata/traces/resource_context/all_match_last_only/input.yaml b/connector/routingconnector/testdata/traces/resource_context/all_match_last_only/input.yaml deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/all_match_last_only/input.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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/testdata/traces/resource_context/all_match_last_only/sink_1.yaml b/connector/routingconnector/testdata/traces/resource_context/all_match_last_only/sink_1.yaml deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/all_match_last_only/sink_1.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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/testdata/traces/resource_context/all_match_once/config.yaml b/connector/routingconnector/testdata/traces/resource_context/all_match_once/config.yaml deleted file mode 100644 index 412189b1ce3c..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/all_match_once/config.yaml +++ /dev/null @@ -1,11 +0,0 @@ -routing: - match_once: true - default_pipelines: - - traces/default - table: - - condition: attributes["resourceName"] != nil - pipelines: - - traces/0 - - condition: attributes["resourceName"] == "resourceA" or attributes["resourceName"] == "resourceB" - pipelines: - - traces/1 diff --git a/connector/routingconnector/testdata/traces/resource_context/all_match_once/input.yaml b/connector/routingconnector/testdata/traces/resource_context/all_match_once/input.yaml deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/all_match_once/input.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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/testdata/traces/resource_context/all_match_once/sink_0.yaml b/connector/routingconnector/testdata/traces/resource_context/all_match_once/sink_0.yaml deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/all_match_once/sink_0.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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/testdata/traces/resource_context/each_matches_one/config.yaml b/connector/routingconnector/testdata/traces/resource_context/each_matches_one/config.yaml deleted file mode 100644 index 87d8044ed135..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/each_matches_one/config.yaml +++ /dev/null @@ -1,10 +0,0 @@ -routing: - default_pipelines: - - traces/default - table: - - condition: attributes["resourceName"] == "resourceB" - pipelines: - - traces/0 - - condition: attributes["resourceName"] == "resourceA" - pipelines: - - traces/1 diff --git a/connector/routingconnector/testdata/traces/resource_context/each_matches_one/input.yaml b/connector/routingconnector/testdata/traces/resource_context/each_matches_one/input.yaml deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/each_matches_one/input.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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/testdata/traces/resource_context/each_matches_one/sink_0.yaml b/connector/routingconnector/testdata/traces/resource_context/each_matches_one/sink_0.yaml deleted file mode 100644 index 638861efcf92..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/each_matches_one/sink_0.yaml +++ /dev/null @@ -1,59 +0,0 @@ -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/testdata/traces/resource_context/each_matches_one/sink_1.yaml b/connector/routingconnector/testdata/traces/resource_context/each_matches_one/sink_1.yaml deleted file mode 100644 index 5c862eb1178f..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/each_matches_one/sink_1.yaml +++ /dev/null @@ -1,59 +0,0 @@ -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/testdata/traces/resource_context/match_none_with_default/config.yaml b/connector/routingconnector/testdata/traces/resource_context/match_none_with_default/config.yaml deleted file mode 100644 index f8f8b30a5aec..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/match_none_with_default/config.yaml +++ /dev/null @@ -1,10 +0,0 @@ -routing: - default_pipelines: - - traces/default - table: - - condition: attributes["resourceName"] == "resourceX" - pipelines: - - traces/0 - - condition: attributes["resourceName"] == "resourceY" - pipelines: - - traces/1 diff --git a/connector/routingconnector/testdata/traces/resource_context/match_none_with_default/input.yaml b/connector/routingconnector/testdata/traces/resource_context/match_none_with_default/input.yaml deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/match_none_with_default/input.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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/testdata/traces/resource_context/match_none_with_default/sink_default.yaml b/connector/routingconnector/testdata/traces/resource_context/match_none_with_default/sink_default.yaml deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/match_none_with_default/sink_default.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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/testdata/traces/resource_context/match_none_without_default/config.yaml b/connector/routingconnector/testdata/traces/resource_context/match_none_without_default/config.yaml deleted file mode 100644 index 919ff44ef1cf..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/match_none_without_default/config.yaml +++ /dev/null @@ -1,10 +0,0 @@ -routing: - match_once: true - # no default pipelines - table: - - condition: attributes["resourceName"] == "resourceX" - pipelines: - - traces/0 - - condition: attributes["resourceName"] == "resourceY" - pipelines: - - traces/1 diff --git a/connector/routingconnector/testdata/traces/resource_context/match_none_without_default/input.yaml b/connector/routingconnector/testdata/traces/resource_context/match_none_without_default/input.yaml deleted file mode 100644 index 914758ed6510..000000000000 --- a/connector/routingconnector/testdata/traces/resource_context/match_none_without_default/input.yaml +++ /dev/null @@ -1,117 +0,0 @@ -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/traces_test.go b/connector/routingconnector/traces_test.go index efa5482a9eea..dd6c862d965a 100644 --- a/connector/routingconnector/traces_test.go +++ b/connector/routingconnector/traces_test.go @@ -5,15 +5,11 @@ package routingconnector // import "github.com/open-telemetry/opentelemetry-coll import ( "context" - "os" - "path/filepath" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/connector" "go.opentelemetry.io/collector/connector/connectortest" "go.opentelemetry.io/collector/consumer" @@ -21,8 +17,7 @@ import ( "go.opentelemetry.io/collector/pdata/ptrace" "go.opentelemetry.io/collector/pipeline" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/ptracetest" + "github.com/open-telemetry/opentelemetry-collector-contrib/connector/routingconnector/internal/ptraceutiltest" ) func TestTracesRegisterConsumersForValidRoute(t *testing.T) { @@ -428,86 +423,150 @@ func TestTraceConnectorCapabilities(t *testing.T) { } func TestTracesConnectorDetailed(t *testing.T) { - testCases := []string{ - filepath.Join("testdata", "traces", "resource_context", "all_match_first_only"), - filepath.Join("testdata", "traces", "resource_context", "all_match_last_only"), - filepath.Join("testdata", "traces", "resource_context", "all_match_once"), - filepath.Join("testdata", "traces", "resource_context", "each_matches_one"), - filepath.Join("testdata", "traces", "resource_context", "match_none_with_default"), - filepath.Join("testdata", "traces", "resource_context", "match_none_without_default"), + idSink0 := pipeline.NewIDWithName(pipeline.SignalTraces, "0") + idSink1 := pipeline.NewIDWithName(pipeline.SignalTraces, "1") + idSinkD := pipeline.NewIDWithName(pipeline.SignalTraces, "default") + + isNotNil := `attributes["resourceName"] != nil` + isA := `attributes["resourceName"] == "resourceA"` + isB := `attributes["resourceName"] == "resourceB"` + isX := `attributes["resourceName"] == "resourceX"` + isY := `attributes["resourceName"] == "resourceY"` + + testCases := []struct { + name string + cfg *Config + input ptrace.Traces + expectSink0 ptrace.Traces + expectSink1 ptrace.Traces + expectSinkD ptrace.Traces + }{ + { + name: "all_match_first_only", + cfg: testConfig( + withRoute("resource", isNotNil, idSink0), + withRoute("resource", isY, idSink1), + withDefault(idSinkD), + ), + input: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + expectSink0: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + expectSink1: ptrace.Traces{}, + expectSinkD: ptrace.Traces{}, + }, + { + name: "all_match_last_only", + cfg: testConfig( + withRoute("resource", isX, idSink0), + withRoute("resource", isNotNil, idSink1), + withDefault(idSinkD), + ), + input: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + expectSink0: ptrace.Traces{}, + expectSink1: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + expectSinkD: ptrace.Traces{}, + }, + { + name: "all_match_only_once", + cfg: testConfig( + withRoute("resource", isNotNil, idSink0), + withRoute("resource", isA+" or "+isB, idSink1), + withDefault(idSinkD), + ), + input: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + expectSink0: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + expectSink1: ptrace.Traces{}, + expectSinkD: ptrace.Traces{}, + }, + { + name: "each_matches_one", + cfg: testConfig( + withRoute("resource", isA, idSink0), + withRoute("resource", isB, idSink1), + withDefault(idSinkD), + ), + input: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + expectSink0: ptraceutiltest.NewTraces("A", "CD", "EF", "FG"), + expectSink1: ptraceutiltest.NewTraces("B", "CD", "EF", "FG"), + expectSinkD: ptrace.Traces{}, + }, + { + name: "some_match_with_default", + cfg: testConfig( + withRoute("resource", isX, idSink0), + withRoute("resource", isB, idSink1), + withDefault(idSinkD), + ), + input: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + expectSink0: ptrace.Traces{}, + expectSink1: ptraceutiltest.NewTraces("B", "CD", "EF", "FG"), + expectSinkD: ptraceutiltest.NewTraces("A", "CD", "EF", "FG"), + }, + { + name: "some_match_without_default", + cfg: testConfig( + withRoute("resource", isX, idSink0), + withRoute("resource", isB, idSink1), + ), + input: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + expectSink0: ptrace.Traces{}, + expectSink1: ptraceutiltest.NewTraces("B", "CD", "EF", "FG"), + expectSinkD: ptrace.Traces{}, + }, + { + name: "match_none_with_default", + cfg: testConfig( + withRoute("resource", isX, idSink0), + withRoute("resource", isY, idSink1), + withDefault(idSinkD), + ), + input: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + expectSink0: ptrace.Traces{}, + expectSink1: ptrace.Traces{}, + expectSinkD: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + }, + { + name: "match_none_without_default", + cfg: testConfig( + withRoute("resource", isX, idSink0), + withRoute("resource", isY, idSink1), + ), + input: ptraceutiltest.NewTraces("AB", "CD", "EF", "FG"), + expectSink0: ptrace.Traces{}, + expectSink1: ptrace.Traces{}, + expectSinkD: ptrace.Traces{}, + }, } for _, tt := range testCases { - t.Run(tt, func(t *testing.T) { - - cm, err := confmaptest.LoadConf(filepath.Join(tt, "config.yaml")) - require.NoError(t, err) - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub("routing") - require.NoError(t, err) - require.NoError(t, sub.Unmarshal(cfg)) - require.NoError(t, component.ValidateConfig(cfg)) - - var sinkDefault, sink0, sink1 consumertest.TracesSink + t.Run(tt.name, func(t *testing.T) { + var sinkD, sink0, sink1 consumertest.TracesSink router := connector.NewTracesRouter(map[pipeline.ID]consumer.Traces{ - pipeline.NewIDWithName(pipeline.SignalTraces, "default"): &sinkDefault, pipeline.NewIDWithName(pipeline.SignalTraces, "0"): &sink0, pipeline.NewIDWithName(pipeline.SignalTraces, "1"): &sink1, + pipeline.NewIDWithName(pipeline.SignalTraces, "default"): &sinkD, }) - conn, err := factory.CreateTracesToTraces( + conn, err := NewFactory().CreateTracesToTraces( context.Background(), connectortest.NewNopSettings(), - cfg, + tt.cfg, router.(consumer.Traces), ) require.NoError(t, err) - var expected0, expected1, expectedDefault *ptrace.Traces - if expected, readErr := golden.ReadTraces(filepath.Join(tt, "sink_0.yaml")); readErr == nil { - expected0 = &expected - } else if !os.IsNotExist(readErr) { - t.Fatalf("Error reading sink_0.yaml: %v", readErr) - } - - if expected, readErr := golden.ReadTraces(filepath.Join(tt, "sink_1.yaml")); readErr == nil { - expected1 = &expected - } else if !os.IsNotExist(readErr) { - t.Fatalf("Error reading sink_1.yaml: %v", readErr) - } - - if expected, readErr := golden.ReadTraces(filepath.Join(tt, "sink_default.yaml")); readErr == nil { - expectedDefault = &expected - } else if !os.IsNotExist(readErr) { - t.Fatalf("Error reading sink_default.yaml: %v", readErr) - } - - input, readErr := golden.ReadTraces(filepath.Join(tt, "input.yaml")) - require.NoError(t, readErr) - - require.NoError(t, conn.ConsumeTraces(context.Background(), input)) - - if expected0 == nil { - assert.Empty(t, sink0.AllTraces(), "sink0 should be empty") - } else { - require.Len(t, sink0.AllTraces(), 1, "sink0 should have one ptrace.Traces") - assert.NoError(t, ptracetest.CompareTraces(*expected0, sink0.AllTraces()[0]), "sink0 has unexpected result") - } - - if expected1 == nil { - assert.Empty(t, sink1.AllTraces(), "sink1 should be empty") - } else { - require.Len(t, sink1.AllTraces(), 1, "sink1 should have one ptrace.Traces") - assert.NoError(t, ptracetest.CompareTraces(*expected1, sink1.AllTraces()[0]), "sink1 has unexpected result") - } + require.NoError(t, conn.ConsumeTraces(context.Background(), tt.input)) - if expectedDefault == nil { - assert.Empty(t, sinkDefault.AllTraces(), "sinkDefault should be empty") - } else { - require.Len(t, sinkDefault.AllTraces(), 1, "sinkDefault should have one ptrace.Traces") - assert.NoError(t, ptracetest.CompareTraces(*expectedDefault, sinkDefault.AllTraces()[0]), "sinkDefault has unexpected result") + assertExpected := func(sink *consumertest.TracesSink, expected ptrace.Traces, name string) { + if expected == (ptrace.Traces{}) { + assert.Empty(t, sink.AllTraces(), name) + } else { + require.Len(t, sink.AllTraces(), 1, name) + assert.Equal(t, expected, sink.AllTraces()[0], name) + } } + assertExpected(&sink0, tt.expectSink0, "sink0") + assertExpected(&sink1, tt.expectSink1, "sink1") + assertExpected(&sinkD, tt.expectSinkD, "sinkD") }) } }