From bbc6b166ad6b99d0331322534bc9ef4c2f42e585 Mon Sep 17 00:00:00 2001 From: Ruslan Kovalov Date: Mon, 15 Aug 2022 11:02:01 +0200 Subject: [PATCH] [chore] Change processor config tests to unmarshal config for that component. - resourcedetectionprocessor - resourceprocessor - routingprocessor - schemaprocessor - spanprocessor - tailsamplingprocessor - transformprocessor --- .../resourcedetectionprocessor/config_test.go | 125 ++++++----- .../factory_test.go | 31 ++- .../testdata/config.yaml | 91 ++++---- .../testdata/invalid_config.yaml | 22 -- processor/resourceprocessor/config_test.go | 56 +++-- .../resourceprocessor/testdata/config.yaml | 58 ++--- processor/routingprocessor/config_test.go | 56 ++--- processor/routingprocessor/factory_test.go | 27 ++- processor/routingprocessor/go.mod | 15 +- processor/routingprocessor/go.sum | 24 +- .../routingprocessor/testdata/config.yaml | 7 + .../testdata/config_logs.yaml | 45 +--- .../testdata/config_metrics.yaml | 45 +--- .../testdata/config_multipipelines.yaml | 31 --- .../testdata/config_traces.yaml | 49 ++-- processor/schemaprocessor/config_test.go | 23 +- processor/schemaprocessor/testdata/config.yml | 48 ++-- processor/spanprocessor/config_test.go | 169 +++++++------- processor/spanprocessor/testdata/config.yaml | 202 ++++++++--------- .../tailsamplingprocessor/config_test.go | 20 +- .../tailsamplingprocessor/factory_test.go | 21 +- .../testdata/tail_sampling_config.yaml | 210 ++++++++---------- processor/transformprocessor/config_test.go | 127 ++++++----- .../transformprocessor/testdata/config.yaml | 70 ++++-- .../invalid_config_bad_syntax_log.yaml | 19 -- .../invalid_config_bad_syntax_metric.yaml | 19 -- .../invalid_config_bad_syntax_trace.yaml | 19 -- .../invalid_config_unknown_function_log.yaml | 19 -- ...nvalid_config_unknown_function_metric.yaml | 19 -- ...invalid_config_unknown_function_trace.yaml | 19 -- 30 files changed, 720 insertions(+), 966 deletions(-) delete mode 100644 processor/resourcedetectionprocessor/testdata/invalid_config.yaml create mode 100644 processor/routingprocessor/testdata/config.yaml delete mode 100644 processor/routingprocessor/testdata/config_multipipelines.yaml delete mode 100644 processor/transformprocessor/testdata/invalid_config_bad_syntax_log.yaml delete mode 100644 processor/transformprocessor/testdata/invalid_config_bad_syntax_metric.yaml delete mode 100644 processor/transformprocessor/testdata/invalid_config_bad_syntax_trace.yaml delete mode 100644 processor/transformprocessor/testdata/invalid_config_unknown_function_log.yaml delete mode 100644 processor/transformprocessor/testdata/invalid_config_unknown_function_metric.yaml delete mode 100644 processor/transformprocessor/testdata/invalid_config_unknown_function_trace.yaml diff --git a/processor/resourcedetectionprocessor/config_test.go b/processor/resourcedetectionprocessor/config_test.go index 5ec161b532f3..29a54f0fd8e0 100644 --- a/processor/resourcedetectionprocessor/config_test.go +++ b/processor/resourcedetectionprocessor/config_test.go @@ -20,10 +20,10 @@ import ( "time" "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/component/componenttest" + "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confighttp" - "go.opentelemetry.io/collector/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/ec2" @@ -31,68 +31,79 @@ import ( ) func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.NoError(t, err) + t.Parallel() - factory := NewFactory() - factories.Processors[typeStr] = factory + cfg := confighttp.NewDefaultHTTPClientSettings() + cfg.Timeout = 2 * time.Second - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) - assert.NoError(t, err) - assert.NotNil(t, cfg) - - p1 := cfg.Processors[config.NewComponentID(typeStr)] - assert.Equal(t, p1, factory.CreateDefaultConfig()) - - p2 := cfg.Processors[config.NewComponentIDWithName(typeStr, "gce")].(*Config) - p2e := &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName(typeStr, "gce")), - Detectors: []string{"env", "gce"}, - HTTPClientSettings: confighttp.HTTPClientSettings{Timeout: 2 * time.Second, MaxIdleConns: p2.MaxIdleConns, IdleConnTimeout: p2.IdleConnTimeout}, - Override: false, - } - assert.Equal(t, p2, p2e) - - p3 := cfg.Processors[config.NewComponentIDWithName(typeStr, "ec2")] - p3e := &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName(typeStr, "ec2")), - Detectors: []string{"env", "ec2"}, - DetectorConfig: DetectorConfig{ - EC2Config: ec2.Config{ - Tags: []string{"^tag1$", "^tag2$"}, + tests := []struct { + id config.ComponentID + expected config.Processor + errorMessage string + }{ + { + id: config.NewComponentIDWithName(typeStr, "gce"), + expected: &Config{ + ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), + Detectors: []string{"env", "gce"}, + HTTPClientSettings: cfg, + Override: false, }, }, - HTTPClientSettings: confighttp.HTTPClientSettings{Timeout: 2 * time.Second, MaxIdleConns: p2.MaxIdleConns, IdleConnTimeout: p2.IdleConnTimeout}, - Override: false, - } - assert.Equal(t, p3, p3e) - - p4 := cfg.Processors[config.NewComponentIDWithName(typeStr, "system")] - p4e := &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName(typeStr, "system")), - Detectors: []string{"env", "system"}, - DetectorConfig: DetectorConfig{ - SystemConfig: system.Config{ - HostnameSources: []string{"os"}, + { + id: config.NewComponentIDWithName(typeStr, "ec2"), + expected: &Config{ + ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), + Detectors: []string{"env", "ec2"}, + DetectorConfig: DetectorConfig{ + EC2Config: ec2.Config{ + Tags: []string{"^tag1$", "^tag2$"}, + }, + }, + HTTPClientSettings: cfg, + Override: false, }, }, - HTTPClientSettings: confighttp.HTTPClientSettings{Timeout: 2 * time.Second, MaxIdleConns: p2.MaxIdleConns, IdleConnTimeout: p2.IdleConnTimeout}, - Override: false, - Attributes: []string{"a", "b"}, + { + id: config.NewComponentIDWithName(typeStr, "system"), + expected: &Config{ + ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), + Detectors: []string{"env", "system"}, + DetectorConfig: DetectorConfig{ + SystemConfig: system.Config{ + HostnameSources: []string{"os"}, + }, + }, + HTTPClientSettings: cfg, + Override: false, + Attributes: []string{"a", "b"}, + }, + }, + { + id: config.NewComponentIDWithName(typeStr, "invalid"), + errorMessage: "hostname_sources contains invalid value: \"invalid_source\"", + }, + } + for _, tt := range tests { + t.Run(tt.id.String(), func(t *testing.T) { + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) + require.NoError(t, err) + + factory := NewFactory() + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub(tt.id.String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalProcessor(sub, cfg)) + + if tt.expected == nil { + assert.EqualError(t, cfg.Validate(), tt.errorMessage) + return + } + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) + }) } - assert.Equal(t, p4, p4e) -} - -func TestLoadInvalidConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.NoError(t, err) - - factory := NewFactory() - factories.Processors[typeStr] = factory - - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "invalid_config.yaml"), factories) - assert.Error(t, err) - assert.NotNil(t, cfg) } func TestGetConfigFromType(t *testing.T) { diff --git a/processor/resourcedetectionprocessor/factory_test.go b/processor/resourcedetectionprocessor/factory_test.go index a978d516ea00..11c7d57f93d8 100644 --- a/processor/resourcedetectionprocessor/factory_test.go +++ b/processor/resourcedetectionprocessor/factory_test.go @@ -20,10 +20,12 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtest" + "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/consumer/consumertest" - "go.opentelemetry.io/collector/service/servicetest" ) func TestCreateDefaultConfig(t *testing.T) { @@ -50,18 +52,25 @@ func TestCreateProcessor(t *testing.T) { } func TestCreateConfigProcessors(t *testing.T) { - factory := NewFactory() - factories, _ := componenttest.NopFactories() - factories.Processors[typeStr] = factory - - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) - assert.NoError(t, err) - assert.NotNil(t, cfg) + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) + require.NoError(t, err) - for k, v := range cfg.Processors { + for k := range cm.ToStringMap() { // Check if all processor variations that are defined in test config can be actually created - t.Run(k.Name(), func(t *testing.T) { - tt, err := factory.CreateTracesProcessor(context.Background(), componenttest.NewNopProcessorCreateSettings(), v, consumertest.NewNop()) + t.Run(k, func(t *testing.T) { + factory := NewFactory() + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub(k) + require.NoError(t, err) + require.NoError(t, config.UnmarshalProcessor(sub, cfg)) + + tt, err := factory.CreateTracesProcessor( + context.Background(), + componenttest.NewNopProcessorCreateSettings(), + cfg, + consumertest.NewNop(), + ) assert.NoError(t, err) assert.NotNil(t, tt) }) diff --git a/processor/resourcedetectionprocessor/testdata/config.yaml b/processor/resourcedetectionprocessor/testdata/config.yaml index 3b591fb74fbd..5be35b48e2f9 100644 --- a/processor/resourcedetectionprocessor/testdata/config.yaml +++ b/processor/resourcedetectionprocessor/testdata/config.yaml @@ -1,53 +1,44 @@ -receivers: - nop: +resourcedetection: +resourcedetection/gce: + detectors: [env, gce] + timeout: 2s + override: false -processors: - resourcedetection: - resourcedetection/gce: - detectors: [env, gce] - timeout: 2s - override: false - resourcedetection/ec2: - detectors: [env, ec2] - timeout: 2s - override: false - ec2: - tags: - - ^tag1$ - - ^tag2$ - resourcedetection/ecs: - detectors: [env, ecs] - timeout: 2s - override: false - resourcedetection/system: - detectors: [env, system] - timeout: 2s - override: false - system: - hostname_sources: [os] - attributes: ["a", "b"] - resourcedetection/docker: - detectors: [env, docker] - timeout: 2s - override: false - resourcedetection/azure: - detectors: [env, azure] - timeout: 2s - override: false +resourcedetection/ec2: + detectors: [env, ec2] + timeout: 2s + override: false + ec2: + tags: + - ^tag1$ + - ^tag2$ -exporters: - nop: +resourcedetection/ecs: + detectors: [env, ecs] + timeout: 2s + override: false -service: - pipelines: - metrics: - receivers: [nop] - processors: - # Choose one depending on your cloud provider and environment: - # - resourcedetection/system - # - resourcedetection/docker - # - resourcedetection/gce - # - resourcedetection/ec2 - # - resourcedetection/ecs - # - resourcedetection/azure - exporters: [nop] +resourcedetection/system: + detectors: [env, system] + timeout: 2s + override: false + system: + hostname_sources: [os] + attributes: ["a", "b"] + +resourcedetection/docker: + detectors: [env, docker] + timeout: 2s + override: false + +resourcedetection/azure: + detectors: [env, azure] + timeout: 2s + override: false + +resourcedetection/invalid: + detectors: [env, system] + timeout: 2s + override: false + system: + hostname_sources: [invalid_source] diff --git a/processor/resourcedetectionprocessor/testdata/invalid_config.yaml b/processor/resourcedetectionprocessor/testdata/invalid_config.yaml deleted file mode 100644 index eb366d063e7e..000000000000 --- a/processor/resourcedetectionprocessor/testdata/invalid_config.yaml +++ /dev/null @@ -1,22 +0,0 @@ -receivers: - nop: - -processors: - resourcedetection/system: - detectors: [env, system] - timeout: 2s - override: false - system: - hostname_sources: [invalid_source] - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [nop] - processors: - # Choose one depending on your cloud provider and environment: - # - resourcedetection/system - exporters: [nop] diff --git a/processor/resourceprocessor/config_test.go b/processor/resourceprocessor/config_test.go index 06f0c027f13f..a7f9120c04e0 100644 --- a/processor/resourceprocessor/config_test.go +++ b/processor/resourceprocessor/config_test.go @@ -19,33 +19,51 @@ import ( "testing" "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/component/componenttest" + "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/config" - "go.opentelemetry.io/collector/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/attraction" ) func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.NoError(t, err) + t.Parallel() - factories.Processors[typeStr] = NewFactory() + tests := []struct { + id config.ComponentID + expected config.Processor + }{ + { + id: config.NewComponentIDWithName(typeStr, ""), + expected: &Config{ + ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), + AttributesActions: []attraction.ActionKeyValue{ + {Key: "cloud.availability_zone", Value: "zone-1", Action: attraction.UPSERT}, + {Key: "k8s.cluster.name", FromAttribute: "k8s-cluster", Action: attraction.INSERT}, + {Key: "redundant-attribute", Action: attraction.DELETE}, + }, + }, + }, + { + id: config.NewComponentIDWithName(typeStr, "invalid"), + expected: createDefaultConfig(), + }, + } - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) - assert.NoError(t, err) - assert.NotNil(t, cfg) + for _, tt := range tests { + t.Run(tt.id.String(), func(t *testing.T) { + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) + require.NoError(t, err) - assert.Equal(t, cfg.Processors[config.NewComponentID(typeStr)], &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - AttributesActions: []attraction.ActionKeyValue{ - {Key: "cloud.availability_zone", Value: "zone-1", Action: attraction.UPSERT}, - {Key: "k8s.cluster.name", FromAttribute: "k8s-cluster", Action: attraction.INSERT}, - {Key: "redundant-attribute", Action: attraction.DELETE}, - }, - }) + factory := NewFactory() + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub(tt.id.String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalProcessor(sub, cfg)) - assert.Equal(t, cfg.Processors[config.NewComponentIDWithName(typeStr, "invalid")], &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName(typeStr, "invalid")), - }) + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) + }) + } } diff --git a/processor/resourceprocessor/testdata/config.yaml b/processor/resourceprocessor/testdata/config.yaml index 66d1b7031f7a..1eb36bcc4407 100644 --- a/processor/resourceprocessor/testdata/config.yaml +++ b/processor/resourceprocessor/testdata/config.yaml @@ -1,41 +1,19 @@ -receivers: - nop: +# The following specifies a resource configuration doing the changes on resource attributes: +# 1. Set "cloud.availability_zone" attributes with "zone-1" value ignoring existing values. +# 2. Copy "k8s-cluster" attribute value to "k8s.cluster.name" attribute, nothing happens if "k8s-cluster" not found. +# 3. Remove "redundant-attribute" attribute. +# There are many more attribute modification actions supported, +# check processor/attributesprocessor/testdata/config.yaml for reference. +resource: + attributes: + - key: cloud.availability_zone + value: zone-1 + action: upsert + - key: k8s.cluster.name + from_attribute: k8s-cluster + action: insert + - key: redundant-attribute + action: delete -processors: - # The following specifies a resource configuration doing the changes on resource attributes: - # 1. Set "cloud.availability_zone" attributes with "zone-1" value ignoring existing values. - # 2. Copy "k8s-cluster" attribute value to "k8s.cluster.name" attribute, nothing happens if "k8s-cluster" not found. - # 3. Remove "redundant-attribute" attribute. - # There are many more attribute modification actions supported, - # check processor/attributesprocessor/testdata/config.yaml for reference. - resource: - attributes: - - key: cloud.availability_zone - value: zone-1 - action: upsert - - key: k8s.cluster.name - from_attribute: k8s-cluster - action: insert - - key: redundant-attribute - action: delete - # The following specifies an invalid resource configuration, it has to have at least one action set in attributes field. - resource/invalid: - - -exporters: - nop: - -service: - pipelines: - logs: - receivers: [nop] - processors: [resource] - exporters: [nop] - metrics: - receivers: [nop] - processors: [resource] - exporters: [nop] - traces: - receivers: [nop] - processors: [resource] - exporters: [nop] +# The following specifies an invalid resource configuration, it has to have at least one action set in attributes field. +resource/empty: diff --git a/processor/routingprocessor/config_test.go b/processor/routingprocessor/config_test.go index adc560b9a327..7ab5e21f3aa2 100644 --- a/processor/routingprocessor/config_test.go +++ b/processor/routingprocessor/config_test.go @@ -20,31 +20,18 @@ import ( "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/config" - "go.opentelemetry.io/collector/exporter/loggingexporter" - "go.opentelemetry.io/collector/exporter/otlpexporter" - "go.opentelemetry.io/collector/service/servicetest" - - "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter" + "go.opentelemetry.io/collector/confmap/confmaptest" ) func TestLoadConfig(t *testing.T) { testcases := []struct { - configPath string - factoriesFunc func(component.Factories) component.Factories - expectedConfig *Config + configPath string + expected config.Processor }{ { configPath: "config_traces.yaml", - factoriesFunc: func(factories component.Factories) component.Factories { - // we don't need to use them in this test, but the config has them - factories.Exporters["otlp"] = otlpexporter.NewFactory() - factories.Exporters["jaeger"] = jaegerexporter.NewFactory() - return factories - }, - expectedConfig: &Config{ + expected: &Config{ ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), DefaultExporters: []string{"otlp"}, AttributeSource: "context", @@ -63,12 +50,7 @@ func TestLoadConfig(t *testing.T) { }, { configPath: "config_metrics.yaml", - factoriesFunc: func(factories component.Factories) component.Factories { - // we don't need to use it in this test, but the config has them - factories.Exporters["logging"] = loggingexporter.NewFactory() - return factories - }, - expectedConfig: &Config{ + expected: &Config{ ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), DefaultExporters: []string{"logging/default"}, AttributeSource: "context", @@ -87,12 +69,7 @@ func TestLoadConfig(t *testing.T) { }, { configPath: "config_logs.yaml", - factoriesFunc: func(factories component.Factories) component.Factories { - // we don't need to use it in this test, but the config has them - factories.Exporters["logging"] = loggingexporter.NewFactory() - return factories - }, - expectedConfig: &Config{ + expected: &Config{ ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), DefaultExporters: []string{"logging/default"}, AttributeSource: "context", @@ -111,21 +88,20 @@ func TestLoadConfig(t *testing.T) { }, } - for _, tc := range testcases { - t.Run(tc.configPath, func(t *testing.T) { - tc := tc + for _, tt := range testcases { + t.Run(tt.configPath, func(t *testing.T) { + cm, err := confmaptest.LoadConf(filepath.Join("testdata", tt.configPath)) + require.NoError(t, err) - factories, err := componenttest.NopFactories() - assert.NoError(t, err) - factories.Processors[typeStr] = NewFactory() - factories = tc.factoriesFunc(factories) + factory := NewFactory() + cfg := factory.CreateDefaultConfig() - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", tc.configPath), factories) + sub, err := cm.Sub(config.NewComponentIDWithName(typeStr, "").String()) require.NoError(t, err) - require.NotNil(t, cfg) + require.NoError(t, config.UnmarshalProcessor(sub, cfg)) - parsed := cfg.Processors[config.NewComponentID(typeStr)] - assert.Equal(t, tc.expectedConfig, parsed) + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) }) } } diff --git a/processor/routingprocessor/factory_test.go b/processor/routingprocessor/factory_test.go index 81c06ab7397b..3ebf344499fc 100644 --- a/processor/routingprocessor/factory_test.go +++ b/processor/routingprocessor/factory_test.go @@ -25,11 +25,11 @@ import ( "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configgrpc" + "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/exporter/otlpexporter" "go.opentelemetry.io/collector/pdata/ptrace" "go.opentelemetry.io/collector/processor/processorhelper" - "go.opentelemetry.io/collector/service/servicetest" "go.uber.org/zap" ) @@ -181,15 +181,24 @@ func TestProcessorDoesNotFailToBuildExportersWithMultiplePipelines(t *testing.T) }, } - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config_multipipelines.yaml"), factories) - assert.NoError(t, err) + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) + require.NoError(t, err) - for _, cfg := range cfg.Processors { - exp := newProcessor(zap.NewNop(), cfg) - err = exp.Start(context.Background(), host) - // assert that no error is thrown due to multiple pipelines and exporters not using the routing processor - assert.NoError(t, err) - assert.NoError(t, exp.Shutdown(context.Background())) + for k := range cm.ToStringMap() { + // Check if all processor variations that are defined in test config can be actually created + t.Run(k, func(t *testing.T) { + cfg := factories.Processors[typeStr].CreateDefaultConfig() + + sub, err := cm.Sub(k) + require.NoError(t, err) + require.NoError(t, config.UnmarshalProcessor(sub, cfg)) + + exp := newProcessor(zap.NewNop(), cfg) + err = exp.Start(context.Background(), host) + // assert that no error is thrown due to multiple pipelines and exporters not using the routing processor + assert.NoError(t, err) + assert.NoError(t, exp.Shutdown(context.Background())) + }) } } diff --git a/processor/routingprocessor/go.mod b/processor/routingprocessor/go.mod index 3a815e17af5a..8b5edce37c4f 100644 --- a/processor/routingprocessor/go.mod +++ b/processor/routingprocessor/go.mod @@ -3,7 +3,6 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/processor/routi go 1.18 require ( - github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter v0.58.0 github.com/stretchr/testify v1.8.0 go.opentelemetry.io/collector v0.58.0 go.opentelemetry.io/collector/pdata v0.58.0 @@ -13,16 +12,14 @@ require ( require ( cloud.google.com/go/compute v1.8.0 // indirect - github.com/apache/thrift v0.16.0 // indirect github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fsnotify/fsnotify v1.5.4 // indirect github.com/go-logr/logr v1.2.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/gogo/googleapis v1.4.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/jaegertracing/jaeger v1.37.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.15.9 // indirect github.com/knadh/koanf v1.4.2 // indirect @@ -32,14 +29,11 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/mostynb/go-grpc-compression v1.1.17 // indirect - github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.58.0 // indirect - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger v0.58.0 // indirect - github.com/opentracing/opentracing-go v1.2.0 // indirect + github.com/pelletier/go-toml v1.9.5 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect - github.com/uber/jaeger-lib v2.4.1+incompatible // indirect + github.com/rogpeppe/go-internal v1.6.2 // indirect go.opencensus.io v0.23.0 // indirect - go.opentelemetry.io/collector/semconv v0.58.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.34.0 // indirect go.opentelemetry.io/otel v1.9.0 // indirect go.opentelemetry.io/otel/metric v0.31.0 // indirect @@ -53,6 +47,7 @@ require ( google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20220804142021-4e6b2dfa6612 // indirect google.golang.org/protobuf v1.28.1 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/processor/routingprocessor/go.sum b/processor/routingprocessor/go.sum index ef05272b5281..29818a9ff3e4 100644 --- a/processor/routingprocessor/go.sum +++ b/processor/routingprocessor/go.sum @@ -35,10 +35,7 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/HdrHistogram/hdrhistogram-go v1.1.2 h1:5IcZpTvzydCQeHzK4Ef/D5rrSqwxob0t8PQPMybUNFM= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/apache/thrift v0.16.0 h1:qEy6UW60iVOlUy+b9ZR0d5WzUWYGOo4HfopoyBaNmoY= -github.com/apache/thrift v0.16.0/go.mod h1:PHK3hniurgQaNMZYaCLEqXKsYK8upmhPbmdP2FXSqgU= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/aws/aws-sdk-go-v2 v1.9.2/go.mod h1:cK/D0BBs0b/oWPIcX/Z/obahJK1TT7IPVjy53i/mX/4= @@ -84,6 +81,7 @@ github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga github.com/frankban/quicktest v1.14.0/go.mod h1:NeW+ay9A/U67EYXNFA1nPE8e/tnQv/09mUdL/ijj8og= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= +github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -95,8 +93,6 @@ github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-test/deep v1.0.2-0.20181118220953-042da051cf31/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= -github.com/gogo/googleapis v1.4.1 h1:1Yx4Myt7BxzvUr5ldGSbwYiZG6t9wGBZ+8/fX3Wvtq0= -github.com/gogo/googleapis v1.4.1/go.mod h1:2lpHqI5OcWCtVElxXnPt+s8oJvMpySlOyM6xDCrzib4= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -111,7 +107,6 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= -github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -184,8 +179,6 @@ github.com/hashicorp/vault/sdk v0.1.13/go.mod h1:B+hVj7TpuQY1Y/GPbCpffmgd+tSEwvh github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/jaegertracing/jaeger v1.37.0 h1:/EY0n/IUFT/NozEM78bzW2Lm2dPoKuIF/9c9UcoMBxQ= -github.com/jaegertracing/jaeger v1.37.0/go.mod h1:2tPPMcktsOFhmsiyxoYnUE0QAlP4UC6DEsC2jdllt5g= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= @@ -201,6 +194,7 @@ github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHU github.com/knadh/koanf v1.4.2 h1:2itp+cdC6miId4pO4Jw7c/3eiYD26Z/Sz3ATJMwHxIs= github.com/knadh/koanf v1.4.2/go.mod h1:4NCo0q4pmU398vF9vq2jStF9MWQZ8JEDcDMHlDCr4h0= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -233,14 +227,14 @@ github.com/mostynb/go-grpc-compression v1.1.17 h1:N9t6taOJN3mNTTi0wDf4e3lp/G/ON1 github.com/mostynb/go-grpc-compression v1.1.17/go.mod h1:FUSBr0QjKqQgoDG/e0yiqlR6aqyXC39+g/hFLDfSsEY= github.com/npillmayer/nestext v0.1.3/go.mod h1:h2lrijH8jpicr25dFY+oAJLyzlya6jhnuG+zWp9L0Uk= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= -github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= -github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= +github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= @@ -250,12 +244,12 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.6.2 h1:aIihoIOHCiLZHxyoNQ+ABL4NKhFTgKLBdMLyEAh98m0= +github.com/rogpeppe/go-internal v1.6.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -266,10 +260,6 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/uber/jaeger-client-go v2.30.0+incompatible h1:D6wyKGCecFaSRUpo8lCVbaOOb6ThwMmTEbhRwtKR97o= -github.com/uber/jaeger-client-go v2.30.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= -github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg= -github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -285,8 +275,6 @@ go.opentelemetry.io/collector v0.58.0 h1:ofl5qa+vTV69PC9NaZKQjE7MP/49iclDKRppl00 go.opentelemetry.io/collector v0.58.0/go.mod h1:U3TE477WDi3CYhmE7JGinnpIg8qMH1KCBkRmk3BxKyw= go.opentelemetry.io/collector/pdata v0.58.0 h1:SKWw4vjd6ZjCuvsCvEzqwBaxvov4YbXnnXkc9C4xMqM= go.opentelemetry.io/collector/pdata v0.58.0/go.mod h1:iMv7Pz+hRthi30rkYkwLVusxQ94GU4pPJgFq7gjGcBk= -go.opentelemetry.io/collector/semconv v0.58.0 h1:wk9KXVnt8IRdNzD9mmdW3d1M/IJ3HyLp1Lz2ZY1fBCM= -go.opentelemetry.io/collector/semconv v0.58.0/go.mod h1:aRkHuJ/OshtDFYluKEtnG5nkKTsy1HZuvZVHmakx+Vo= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.34.0 h1:PNEMW4EvpNQ7SuoPFNkvbZqi1STkTPKq+8vfoMl/6AE= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.34.0/go.mod h1:fk1+icoN47ytLSgkoWHLJrtVTSQ+HgmkNgPTKrk/Nsc= go.opentelemetry.io/otel v1.9.0 h1:8WZNQFIB2a71LnANS9JeyidJKKGOOremcUtb/OtHISw= @@ -420,6 +408,7 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220624220833-87e55d714810 h1:rHZQSjJdAI4Xf5Qzeh2bBc5YJIkPFVM6oDtMFYmgws0= golang.org/x/sys v0.0.0-20220624220833-87e55d714810/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -576,6 +565,7 @@ gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUy gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/processor/routingprocessor/testdata/config.yaml b/processor/routingprocessor/testdata/config.yaml new file mode 100644 index 000000000000..d1349749e152 --- /dev/null +++ b/processor/routingprocessor/testdata/config.yaml @@ -0,0 +1,7 @@ +routing: + attribute_source: resource + from_attribute: X-Tenant + table: + - value: acme + exporters: + - otlp/traces diff --git a/processor/routingprocessor/testdata/config_logs.yaml b/processor/routingprocessor/testdata/config_logs.yaml index 9fcc8381cf10..9f0d178b356b 100644 --- a/processor/routingprocessor/testdata/config_logs.yaml +++ b/processor/routingprocessor/testdata/config_logs.yaml @@ -1,33 +1,12 @@ -receivers: - nop: - -processors: - routing: - default_exporters: - - logging/default - attribute_source: context - from_attribute: X-Custom-Logs-Header - table: - - value: acme - exporters: - - logging/acme - - value: globex - exporters: - - logging/globex - -exporters: - logging/acme: - logging/default: - logging/globex: - -service: - pipelines: - logs: - receivers: - - nop - processors: - - routing - exporters: - - logging/acme - - logging/default - - logging/globex +routing: + default_exporters: + - logging/default + attribute_source: context + from_attribute: X-Custom-Logs-Header + table: + - value: acme + exporters: + - logging/acme + - value: globex + exporters: + - logging/globex diff --git a/processor/routingprocessor/testdata/config_metrics.yaml b/processor/routingprocessor/testdata/config_metrics.yaml index c4b135ca33d0..eab535bb3831 100644 --- a/processor/routingprocessor/testdata/config_metrics.yaml +++ b/processor/routingprocessor/testdata/config_metrics.yaml @@ -1,33 +1,12 @@ -receivers: - nop: - -processors: - routing: - default_exporters: - - logging/default - attribute_source: context - from_attribute: X-Custom-Metrics-Header - table: - - value: acme - exporters: - - logging/acme - - value: globex - exporters: - - logging/globex - -exporters: - logging/acme: - logging/default: - logging/globex: - -service: - pipelines: - metrics: - receivers: - - nop - processors: - - routing - exporters: - - logging/acme - - logging/default - - logging/globex +routing: + default_exporters: + - logging/default + attribute_source: context + from_attribute: X-Custom-Metrics-Header + table: + - value: acme + exporters: + - logging/acme + - value: globex + exporters: + - logging/globex diff --git a/processor/routingprocessor/testdata/config_multipipelines.yaml b/processor/routingprocessor/testdata/config_multipipelines.yaml deleted file mode 100644 index 8837a472a1d6..000000000000 --- a/processor/routingprocessor/testdata/config_multipipelines.yaml +++ /dev/null @@ -1,31 +0,0 @@ -receivers: - nop: - -processors: - routing: - attribute_source: resource - from_attribute: X-Tenant - table: - - value: acme - exporters: - - otlp/traces - -exporters: - otlp/metrics: - otlp/traces: - -service: - pipelines: - traces: - receivers: - - nop - processors: - - routing - exporters: - - otlp/traces - metrics: - receivers: - - nop - processors: [] - exporters: - - otlp/metrics diff --git a/processor/routingprocessor/testdata/config_traces.yaml b/processor/routingprocessor/testdata/config_traces.yaml index bb5333ba78d6..f40d7d2d4de8 100644 --- a/processor/routingprocessor/testdata/config_traces.yaml +++ b/processor/routingprocessor/testdata/config_traces.yaml @@ -1,36 +1,13 @@ -receivers: - nop: - -processors: - routing: - default_exporters: - - otlp - attribute_source: context - from_attribute: X-Tenant - table: - - value: acme - exporters: - - jaeger/acme - - otlp/acme - - value: globex - exporters: - - otlp/globex - -exporters: - otlp: - otlp/acme: - otlp/globex: - jaeger/acme: - endpoint: localhost:14250 - -service: - pipelines: - traces: - receivers: - - nop - processors: - - routing - exporters: - - jaeger/acme - - otlp/acme - - otlp/globex +routing: + default_exporters: + - otlp + attribute_source: context + from_attribute: X-Tenant + table: + - value: acme + exporters: + - jaeger/acme + - otlp/acme + - value: globex + exporters: + - otlp/globex diff --git a/processor/schemaprocessor/config_test.go b/processor/schemaprocessor/config_test.go index 0dff99765765..02336e77ff1a 100644 --- a/processor/schemaprocessor/config_test.go +++ b/processor/schemaprocessor/config_test.go @@ -15,15 +15,14 @@ package schemaprocessor import ( - "path" + "path/filepath" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/confighttp" - "go.opentelemetry.io/collector/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/schemaprocessor/internal/translation" ) @@ -31,18 +30,18 @@ import ( func TestLoadConfig(t *testing.T) { t.Parallel() - factories, err := componenttest.NopFactories() - require.NoError(t, err, "Must not error on creating Nop factories") + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yml")) + require.NoError(t, err) factory := NewFactory() - factories.Processors[typeStr] = factory + cfg := factory.CreateDefaultConfig() - cfg, err := servicetest.LoadConfigAndValidate(path.Join("testdata", "config.yml"), factories) - require.NoError(t, err, "Must not error when loading configuration") + sub, err := cm.Sub(config.NewComponentIDWithName(typeStr, "with-all-options").String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalProcessor(sub, cfg)) - pcfg := cfg.Processors[config.NewComponentIDWithName(typeStr, "with-all-options")] - assert.Equal(t, pcfg, &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName(typeStr, "with-all-options")), + assert.Equal(t, &Config{ + ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), HTTPClientSettings: confighttp.NewDefaultHTTPClientSettings(), Prefetch: []string{ "https://opentelemetry.io/schemas/1.9.0", @@ -51,7 +50,7 @@ func TestLoadConfig(t *testing.T) { "https://opentelemetry.io/schemas/1.4.2", "https://example.com/otel/schemas/1.2.0", }, - }) + }, cfg) } func TestConfigurationValidation(t *testing.T) { diff --git a/processor/schemaprocessor/testdata/config.yml b/processor/schemaprocessor/testdata/config.yml index 070e3a6c8280..859d0f2c4780 100644 --- a/processor/schemaprocessor/testdata/config.yml +++ b/processor/schemaprocessor/testdata/config.yml @@ -1,38 +1,16 @@ -receivers: - nop: - -processors: - schema/with-all-options: - # Prefetch is an optional field that allows - # the collector to fetch the defined schema files - # as the collector starts. - prefetch: +schema/with-all-options: + # Prefetch is an optional field that allows + # the collector to fetch the defined schema files + # as the collector starts. + prefetch: - https://opentelemetry.io/schemas/1.9.0 - - # Targets is a required field that will enable - # the processor to convert all telemetry sent - # via the semantic convention family (ie. opentelemetry.io/schemas/*) - # to the defined schema identifier set in the target. - # This example will convert signals to 1.4.2 for all opentelemetry.io/schemas/ - # and 1.2.0 for example.com/otel/schemas/. - targets: + + # Targets is a required field that will enable + # the processor to convert all telemetry sent + # via the semantic convention family (ie. opentelemetry.io/schemas/*) + # to the defined schema identifier set in the target. + # This example will convert signals to 1.4.2 for all opentelemetry.io/schemas/ + # and 1.2.0 for example.com/otel/schemas/. + targets: - https://opentelemetry.io/schemas/1.4.2 - https://example.com/otel/schemas/1.2.0 - -exporters: - nop: - -service: - pipelines: - traces: - receivers: [nop] - processors: [schema/with-all-options] - exporters: [nop] - logs: - receivers: [nop] - processors: [schema/with-all-options] - exporters: [nop] - metrics: - receivers: [nop] - processors: [schema/with-all-options] - exporters: [nop] \ No newline at end of file diff --git a/processor/spanprocessor/config_test.go b/processor/spanprocessor/config_test.go index 1ad3a6c23532..a92c5c6d144e 100644 --- a/processor/spanprocessor/config_test.go +++ b/processor/spanprocessor/config_test.go @@ -19,99 +19,118 @@ import ( "testing" "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/component/componenttest" + "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/config" - "go.opentelemetry.io/collector/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterconfig" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/filterset" ) -func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.NoError(t, err) +func TestLoadingConfig(t *testing.T) { + t.Parallel() - factory := NewFactory() - factories.Processors[typeStr] = factory - - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) - - assert.NoError(t, err) - assert.NotNil(t, cfg) - - p0 := cfg.Processors[config.NewComponentIDWithName("span", "custom")] - assert.Equal(t, p0, &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName("span", "custom")), - Rename: Name{ - FromAttributes: []string{"db.svc", "operation", "id"}, - Separator: "::", - }, - }) - - p1 := cfg.Processors[config.NewComponentIDWithName("span", "no-separator")] - assert.Equal(t, p1, &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName("span", "no-separator")), - Rename: Name{ - FromAttributes: []string{"db.svc", "operation", "id"}, - Separator: "", - }, - }) - - p2 := cfg.Processors[config.NewComponentIDWithName("span", "to_attributes")] - assert.Equal(t, p2, &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName("span", "to_attributes")), - Rename: Name{ - ToAttributes: &ToAttributes{ - Rules: []string{`^\/api\/v1\/document\/(?P.*)\/update$`}, + tests := []struct { + id config.ComponentID + expected config.Processor + }{ + { + id: config.NewComponentIDWithName("span", "custom"), + expected: &Config{ + ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("span")), + Rename: Name{ + FromAttributes: []string{"db.svc", "operation", "id"}, + Separator: "::", + }, }, }, - }) - - p3 := cfg.Processors[config.NewComponentIDWithName("span", "includeexclude")] - assert.Equal(t, p3, &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName("span", "includeexclude")), - MatchConfig: filterconfig.MatchConfig{ - Include: &filterconfig.MatchProperties{ - Config: *createMatchConfig(filterset.Regexp), - Services: []string{`banks`}, - SpanNames: []string{"^(.*?)/(.*?)$"}, - }, - Exclude: &filterconfig.MatchProperties{ - Config: *createMatchConfig(filterset.Strict), - SpanNames: []string{`donot/change`}, + { + id: config.NewComponentIDWithName("span", "no-separator"), + expected: &Config{ + ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("span")), + Rename: Name{ + FromAttributes: []string{"db.svc", "operation", "id"}, + Separator: "", + }, }, }, - Rename: Name{ - ToAttributes: &ToAttributes{ - Rules: []string{`(?P.*?)$`}, + { + id: config.NewComponentIDWithName("span", "to_attributes"), + expected: &Config{ + ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("span")), + Rename: Name{ + ToAttributes: &ToAttributes{ + Rules: []string{`^\/api\/v1\/document\/(?P.*)\/update$`}, + }, + }, }, }, - }) - - // Set name - p4 := cfg.Processors[config.NewComponentIDWithName("span", "set_status_err")] - assert.Equal(t, p4, &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName("span", "set_status_err")), - SetStatus: &Status{ - Code: "Error", - Description: "some additional error description", + { + id: config.NewComponentIDWithName("span", "includeexclude"), + expected: &Config{ + ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("span")), + MatchConfig: filterconfig.MatchConfig{ + Include: &filterconfig.MatchProperties{ + Config: *createMatchConfig(filterset.Regexp), + Services: []string{`banks`}, + SpanNames: []string{"^(.*?)/(.*?)$"}, + }, + Exclude: &filterconfig.MatchProperties{ + Config: *createMatchConfig(filterset.Strict), + SpanNames: []string{`donot/change`}, + }, + }, + Rename: Name{ + ToAttributes: &ToAttributes{ + Rules: []string{`(?P.*?)$`}, + }, + }, + }, }, - }) - - p5 := cfg.Processors[config.NewComponentIDWithName("span", "set_status_ok")] - assert.Equal(t, p5, &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName("span", "set_status_ok")), - MatchConfig: filterconfig.MatchConfig{ - Include: &filterconfig.MatchProperties{ - Attributes: []filterconfig.Attribute{ - {Key: "http.status_code", Value: 400}, + { + // Set name + id: config.NewComponentIDWithName("span", "set_status_err"), + expected: &Config{ + ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("span")), + SetStatus: &Status{ + Code: "Error", + Description: "some additional error description", }, }, }, - SetStatus: &Status{ - Code: "Ok", + { + id: config.NewComponentIDWithName("span", "set_status_ok"), + expected: &Config{ + ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("span")), + MatchConfig: filterconfig.MatchConfig{ + Include: &filterconfig.MatchProperties{ + Attributes: []filterconfig.Attribute{ + {Key: "http.status_code", Value: 400}, + }, + }, + }, + SetStatus: &Status{ + Code: "Ok", + }, + }, }, - }) + } + for _, tt := range tests { + t.Run(tt.id.String(), func(t *testing.T) { + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) + require.NoError(t, err) + + factory := NewFactory() + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub(tt.id.String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalProcessor(sub, cfg)) + + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) + }) + } } func createMatchConfig(matchType filterset.MatchType) *filterset.Config { diff --git a/processor/spanprocessor/testdata/config.yaml b/processor/spanprocessor/testdata/config.yaml index 1c900520d32e..b90fc158ba49 100644 --- a/processor/spanprocessor/testdata/config.yaml +++ b/processor/spanprocessor/testdata/config.yaml @@ -1,113 +1,99 @@ -receivers: - nop: +# The following specifies the values of attribute `db.svc`, `operation`, +# and `id` will form the new name of the span, in that order, separated by the +# value `::`. All attribute keys needs to be specified in the span for +# the processor to rename it. +# Note: There is no default configuration for the span processor. For 'name', +# the field `from_attributes` is required. +# +# Example 1 - All keys are in the span: +# Span name before processor: +# "Span.Name": "serviceA" +# Attributes Key/Value pair for a span +# { "db.svc": "location", "operation": "get", "id": "1234"} +# Separator: "::" +# Results in the following new span name: +# "Span.Name": "location::get::1234" +# +# Example 2 - Some keys are missing from the span. +# Span name(before processor): +# "Span.Name": "serviceA" +# Attributes Key/Value pair for a span +# { "db.svc": "location", "id": "1234"} +# Separator: "::" +# Results in no new name because the attribute key `operation` isn't set. +# Span name after processor: +# "Span.Name": "serviceA" +span/custom: + name: + separator: "::" + from_attributes: [db.svc, operation, id] -processors: - # The following specifies the values of attribute `db.svc`, `operation`, - # and `id` will form the new name of the span, in that order, separated by the - # value `::`. All attribute keys needs to be specified in the span for - # the processor to rename it. - # Note: There is no default configuration for the span processor. For 'name', - # the field `from_attributes` is required. - # - # Example 1 - All keys are in the span: - # Span name before processor: - # "Span.Name": "serviceA" - # Attributes Key/Value pair for a span - # { "db.svc": "location", "operation": "get", "id": "1234"} - # Separator: "::" - # Results in the following new span name: - # "Span.Name": "location::get::1234" - # - # Example 2 - Some keys are missing from the span. - # Span name(before processor): - # "Span.Name": "serviceA" - # Attributes Key/Value pair for a span - # { "db.svc": "location", "id": "1234"} - # Separator: "::" - # Results in no new name because the attribute key `operation` isn't set. - # Span name after processor: - # "Span.Name": "serviceA" - span/custom: - name: - separator: "::" - from_attributes: [db.svc, operation, id] +# The following specifies generating a span name with no separator. +# Example: +# Attributes Key/Value pair +# { "db.svc": "location:, "operation": "get", "id": "1234"} +# Separator: "" +# Results in the following new span name: +# "locationget1234" +span/no-separator: + name: + from_attributes: [db.svc, operation, id] - # The following specifies generating a span name with no separator. - # Example: - # Attributes Key/Value pair - # { "db.svc": "location:, "operation": "get", "id": "1234"} - # Separator: "" - # Results in the following new span name: - # "locationget1234" - span/no-separator: - name: - from_attributes: [db.svc, operation, id] +# The following extracts attributes from span name and replaces extracted +# parts with attribute names. +# to_attributes is a list of rules that extract attribute values from span name and +# replace them by attributes names in the span name. Each rule in the list is +# regex pattern string. Span name is checked against the regex and if the regex matches +# all named subexpressions from the regex then the matches are extracted as attributes +# and added to the span. Subexpression name becomes the attribute name and +# subexpression matched portion becomes the attribute value. The matched portion +# in the span name is replaced by extracted attribute name. If the attributes exist +# they will be overwritten. Checks are performed for elements in this array in the +# order they are specified. +# +# Example: +# Let's assume input span name is /api/v1/document/12345678/update +# Applying the following results in output span name /api/v1/document/{documentId}/update +# and will add a new attribute "documentId"="12345678" to the span. +span/to_attributes: + name: + to_attributes: + rules: + - ^\/api\/v1\/document\/(?P.*)\/update$ - # The following extracts attributes from span name and replaces extracted - # parts with attribute names. - # to_attributes is a list of rules that extract attribute values from span name and - # replace them by attributes names in the span name. Each rule in the list is - # regex pattern string. Span name is checked against the regex and if the regex matches - # all named subexpressions from the regex then the matches are extracted as attributes - # and added to the span. Subexpression name becomes the attribute name and - # subexpression matched portion becomes the attribute value. The matched portion - # in the span name is replaced by extracted attribute name. If the attributes exist - # they will be overwritten. Checks are performed for elements in this array in the - # order they are specified. - # - # Example: - # Let's assume input span name is /api/v1/document/12345678/update - # Applying the following results in output span name /api/v1/document/{documentId}/update - # and will add a new attribute "documentId"="12345678" to the span. - span/to_attributes: - name: - to_attributes: - rules: - - ^\/api\/v1\/document\/(?P.*)\/update$ +# The following demonstrates renaming the span name to `{operation_website}` +# and adding the attribute {Key: operation_website, Value: } +# when the span has the following properties +# - Services names that contain the word `banks`. +# - The span name contains '/' anywhere in the string. +# - The span name is not 'donot/change'. +span/includeexclude: + include: + match_type: regexp + services: ["banks"] + span_names: ["^(.*?)/(.*?)$"] + exclude: + match_type: strict + span_names: ["donot/change"] + name: + to_attributes: + rules: + - "(?P.*?)$" - # The following demonstrates renaming the span name to `{operation_website}` - # and adding the attribute {Key: operation_website, Value: } - # when the span has the following properties - # - Services names that contain the word `banks`. - # - The span name contains '/' anywhere in the string. - # - The span name is not 'donot/change'. - span/includeexclude: - include: - match_type: regexp - services: ["banks"] - span_names: ["^(.*?)/(.*?)$"] - exclude: - match_type: strict - span_names: ["donot/change"] - name: - to_attributes: - rules: - - "(?P.*?)$" +# This example changes status of a span to error and sets description. +# Possible values for code are: "Ok", "Error" or "Unset". +# Description is an optional field used for documenting Error statuses. +span/set_status_err: + status: + code: "Error" + description: "some additional error description" - # This example changes status of a span to error and sets description. - # Possible values for code are: "Ok", "Error" or "Unset". - # Description is an optional field used for documenting Error statuses. - span/set_status_err: - status: - code: "Error" - description: "some additional error description" - - # However you may want to set status conditionally. Example below sets - # status to success only when attribute http.status_code is equal to 400 - span/set_status_ok: - include: - attributes: - - Key: http.status_code - Value: 400 - status: - code: "Ok" - -exporters: - nop: - -service: - pipelines: - traces: - receivers: [nop] - processors: [span/custom] - exporters: [nop] +# However you may want to set status conditionally. Example below sets +# status to success only when attribute http.status_code is equal to 400 +span/set_status_ok: + include: + attributes: + - Key: http.status_code + Value: 400 + status: + code: "Ok" diff --git a/processor/tailsamplingprocessor/config_test.go b/processor/tailsamplingprocessor/config_test.go index e7ec3ed70444..37b57df09433 100644 --- a/processor/tailsamplingprocessor/config_test.go +++ b/processor/tailsamplingprocessor/config_test.go @@ -21,23 +21,25 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" - "go.opentelemetry.io/collector/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" ) func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.NoError(t, err) + t.Parallel() + + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "tail_sampling_config.yaml")) + require.NoError(t, err) factory := NewFactory() - factories.Processors[factory.Type()] = factory + cfg := factory.CreateDefaultConfig() - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "tail_sampling_config.yaml"), factories) - require.Nil(t, err) - require.NotNil(t, cfg) + sub, err := cm.Sub(config.NewComponentIDWithName(typeStr, "").String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalProcessor(sub, cfg)) - assert.Equal(t, cfg.Processors[config.NewComponentID(typeStr)], + assert.Equal(t, + cfg, &Config{ ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), DecisionWait: 10 * time.Second, diff --git a/processor/tailsamplingprocessor/factory_test.go b/processor/tailsamplingprocessor/factory_test.go index e70a1d0725f5..6c0b258e1ea7 100644 --- a/processor/tailsamplingprocessor/factory_test.go +++ b/processor/tailsamplingprocessor/factory_test.go @@ -20,11 +20,12 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtest" + "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/consumer/consumertest" - "go.opentelemetry.io/collector/service/servicetest" ) func TestCreateDefaultConfig(t *testing.T) { @@ -34,19 +35,15 @@ func TestCreateDefaultConfig(t *testing.T) { } func TestCreateProcessor(t *testing.T) { - factory := NewFactory() - - cfg := factory.CreateDefaultConfig().(*Config) + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "tail_sampling_config.yaml")) + require.NoError(t, err) - factories, err := componenttest.NopFactories() - assert.NoError(t, err) - factories.Processors[factory.Type()] = factory - serviceCfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "tail_sampling_config.yaml"), factories) - assert.NoError(t, err) + factory := NewFactory() + cfg := factory.CreateDefaultConfig() - // Manually set required fields - cfg.ExpectedNewTracesPerSec = 64 - cfg.PolicyCfgs = serviceCfg.Processors[config.NewComponentID(typeStr)].(*Config).PolicyCfgs + sub, err := cm.Sub(config.NewComponentIDWithName(typeStr, "").String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalProcessor(sub, cfg)) params := componenttest.NewNopProcessorCreateSettings() tp, err := factory.CreateTracesProcessor(context.Background(), params, cfg, consumertest.NewNop()) diff --git a/processor/tailsamplingprocessor/testdata/tail_sampling_config.yaml b/processor/tailsamplingprocessor/testdata/tail_sampling_config.yaml index b5e2865f005d..381cf6b400e9 100644 --- a/processor/tailsamplingprocessor/testdata/tail_sampling_config.yaml +++ b/processor/tailsamplingprocessor/testdata/tail_sampling_config.yaml @@ -1,121 +1,107 @@ -receivers: - nop: - -exporters: - nop: - -processors: - tail_sampling: - decision_wait: 10s - num_traces: 100 - expected_new_traces_per_sec: 10 - policies: - [ - { - name: test-policy-1, - type: always_sample - }, - { - name: test-policy-2, - type: latency, - latency: {threshold_ms: 5000} - }, - { - name: test-policy-3, - type: numeric_attribute, - numeric_attribute: {key: key1, min_value: 50, max_value: 100} - }, - { - name: test-policy-4, - type: probabilistic, - probabilistic: {hash_salt: "custom-salt", sampling_percentage: 0.1} - }, - { - name: test-policy-5, - type: status_code, - status_code: {status_codes: [ERROR, UNSET]} - }, - { - name: test-policy-6, - type: string_attribute, - string_attribute: {key: key2, values: [value1, value2]} - }, +tail_sampling: + decision_wait: 10s + num_traces: 100 + expected_new_traces_per_sec: 10 + policies: + [ + { + name: test-policy-1, + type: always_sample + }, + { + name: test-policy-2, + type: latency, + latency: {threshold_ms: 5000} + }, + { + name: test-policy-3, + type: numeric_attribute, + numeric_attribute: {key: key1, min_value: 50, max_value: 100} + }, + { + name: test-policy-4, + type: probabilistic, + probabilistic: {hash_salt: "custom-salt", sampling_percentage: 0.1} + }, + { + name: test-policy-5, + type: status_code, + status_code: {status_codes: [ERROR, UNSET]} + }, + { + name: test-policy-6, + type: string_attribute, + string_attribute: {key: key2, values: [value1, value2]} + }, + { + name: test-policy-7, + type: rate_limiting, + rate_limiting: {spans_per_second: 35} + }, + { + name: test-policy-8, + type: span_count, + span_count: {min_spans: 2} + }, + { + name: test-policy-9, + type: trace_state, + trace_state: { key: key3, values: [ value1, value2 ] } + }, + { + name: and-policy-1, + type: and, + and: { + and_sub_policy: + [ + { + name: test-and-policy-1, + type: numeric_attribute, + numeric_attribute: { key: key1, min_value: 50, max_value: 100 } + }, + { + name: test-and-policy-2, + type: string_attribute, + string_attribute: { key: key2, values: [ value1, value2 ] } + }, + ] + } + }, + { + name: composite-policy-1, + type: composite, + composite: { - name: test-policy-7, - type: rate_limiting, - rate_limiting: {spans_per_second: 35} - }, - { - name: test-policy-8, - type: span_count, - span_count: {min_spans: 2} - }, - { - name: test-policy-9, - type: trace_state, - trace_state: { key: key3, values: [ value1, value2 ] } - }, - { - name: and-policy-1, - type: and, - and: { - and_sub_policy: + max_total_spans_per_second: 1000, + policy_order: [ test-composite-policy-1, test-composite-policy-2, test-composite-policy-3 ], + composite_sub_policy: [ { - name: test-and-policy-1, + name: test-composite-policy-1, type: numeric_attribute, numeric_attribute: { key: key1, min_value: 50, max_value: 100 } }, { - name: test-and-policy-2, - type: string_attribute, - string_attribute: { key: key2, values: [ value1, value2 ] } + name: test-composite-policy-2, + type: string_attribute, + string_attribute: { key: key2, values: [ value1, value2 ] } }, + { + name: test-composite-policy-3, + type: always_sample + } + ], + rate_allocation: + [ + { + policy: test-composite-policy-1, + percent: 50 + }, + { + policy: test-composite-policy-2, + percent: 25 + } ] - } - }, - { - name: composite-policy-1, - type: composite, - composite: - { - max_total_spans_per_second: 1000, - policy_order: [ test-composite-policy-1, test-composite-policy-2, test-composite-policy-3 ], - composite_sub_policy: - [ - { - name: test-composite-policy-1, - type: numeric_attribute, - numeric_attribute: { key: key1, min_value: 50, max_value: 100 } - }, - { - name: test-composite-policy-2, - type: string_attribute, - string_attribute: { key: key2, values: [ value1, value2 ] } - }, - { - name: test-composite-policy-3, - type: always_sample - } - ], - rate_allocation: - [ - { - policy: test-composite-policy-1, - percent: 50 - }, - { - policy: test-composite-policy-2, - percent: 25 - } - ] - } - }, - ] - -service: - pipelines: - traces: - receivers: [nop] - processors: [tail_sampling] - exporters: [nop] + } + }, + ] diff --git a/processor/transformprocessor/config_test.go b/processor/transformprocessor/config_test.go index e9911f3af4c7..839c3c1f933c 100644 --- a/processor/transformprocessor/config_test.go +++ b/processor/transformprocessor/config_test.go @@ -20,73 +20,86 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" - "go.opentelemetry.io/collector/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" ) -func TestLoadingConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.NoError(t, err) +func TestLoadConfig(t *testing.T) { + t.Parallel() - factory := NewFactory() - factories.Processors[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) - assert.NoError(t, err) - require.NotNil(t, cfg) - - p0 := cfg.Processors[config.NewComponentID(typeStr)] - assert.Equal(t, p0, &Config{ - ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), - Traces: SignalConfig{ - Queries: []string{ - `set(name, "bear") where attributes["http.path"] == "/animal"`, - `keep_keys(attributes, "http.method", "http.path")`, + tests := []struct { + id config.ComponentID + expected config.Processor + errorMessage string + }{ + { + id: config.NewComponentIDWithName(typeStr, ""), + expected: &Config{ + ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)), + Traces: SignalConfig{ + Queries: []string{ + `set(name, "bear") where attributes["http.path"] == "/animal"`, + `keep_keys(attributes, "http.method", "http.path")`, + }, + }, + Metrics: SignalConfig{ + Queries: []string{ + `set(metric.name, "bear") where attributes["http.path"] == "/animal"`, + `keep_keys(attributes, "http.method", "http.path")`, + }, + }, + Logs: SignalConfig{ + Queries: []string{ + `set(body, "bear") where attributes["http.path"] == "/animal"`, + `keep_keys(attributes, "http.method", "http.path")`, + }, + }, }, }, - Metrics: SignalConfig{ - Queries: []string{ - `set(metric.name, "bear") where attributes["http.path"] == "/animal"`, - `keep_keys(attributes, "http.method", "http.path")`, - }, + { + id: config.NewComponentIDWithName(typeStr, "bad_syntax_trace"), + errorMessage: "1:18: unexpected token \"where\" (expected \")\")", }, - Logs: SignalConfig{ - Queries: []string{ - `set(body, "bear") where attributes["http.path"] == "/animal"`, - `keep_keys(attributes, "http.method", "http.path")`, - }, + { + id: config.NewComponentIDWithName(typeStr, "unknown_function_trace"), + errorMessage: "undefined function not_a_function", }, - }) -} - -func TestLoadInvalidConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.NoError(t, err) - - factory := NewFactory() - factories.Processors[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "invalid_config_bad_syntax_trace.yaml"), factories) - assert.Error(t, err) - assert.NotNil(t, cfg) - - cfg, err = servicetest.LoadConfigAndValidate(filepath.Join("testdata", "invalid_config_unknown_function_trace.yaml"), factories) - assert.Error(t, err) - assert.NotNil(t, cfg) - - cfg, err = servicetest.LoadConfigAndValidate(filepath.Join("testdata", "invalid_config_bad_syntax_metric.yaml"), factories) - assert.Error(t, err) - assert.NotNil(t, cfg) + { + id: config.NewComponentIDWithName(typeStr, "bad_syntax_metric"), + errorMessage: "1:18: unexpected token \"where\" (expected \")\")", + }, + { + id: config.NewComponentIDWithName(typeStr, "unknown_function_metric"), + errorMessage: "undefined function not_a_function", + }, + { + id: config.NewComponentIDWithName(typeStr, "bad_syntax_log"), + errorMessage: "1:18: unexpected token \"where\" (expected \")\")", + }, + { + id: config.NewComponentIDWithName(typeStr, "unknown_function_log"), + errorMessage: "undefined function not_a_function", + }, + } + for _, tt := range tests { + t.Run(tt.id.String(), func(t *testing.T) { + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) + require.NoError(t, err) - cfg, err = servicetest.LoadConfigAndValidate(filepath.Join("testdata", "invalid_config_unknown_function_metric.yaml"), factories) - assert.Error(t, err) - assert.NotNil(t, cfg) + factory := NewFactory() + cfg := factory.CreateDefaultConfig() - cfg, err = servicetest.LoadConfigAndValidate(filepath.Join("testdata", "invalid_config_bad_syntax_log.yaml"), factories) - assert.Error(t, err) - assert.NotNil(t, cfg) + sub, err := cm.Sub(tt.id.String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalProcessor(sub, cfg)) - cfg, err = servicetest.LoadConfigAndValidate(filepath.Join("testdata", "invalid_config_unknown_function_log.yaml"), factories) - assert.Error(t, err) - assert.NotNil(t, cfg) + if tt.expected == nil { + assert.EqualError(t, cfg.Validate(), tt.errorMessage) + return + } + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) + }) + } } diff --git a/processor/transformprocessor/testdata/config.yaml b/processor/transformprocessor/testdata/config.yaml index c9bfde4ff62e..b369328f5168 100644 --- a/processor/transformprocessor/testdata/config.yaml +++ b/processor/transformprocessor/testdata/config.yaml @@ -1,27 +1,49 @@ -processors: - transform: - traces: - queries: - - set(name, "bear") where attributes["http.path"] == "/animal" - - keep_keys(attributes, "http.method", "http.path") - metrics: - queries: - - set(metric.name, "bear") where attributes["http.path"] == "/animal" - - keep_keys(attributes, "http.method", "http.path") - logs: - queries: - - set(body, "bear") where attributes["http.path"] == "/animal" - - keep_keys(attributes, "http.method", "http.path") +transform: + traces: + queries: + - set(name, "bear") where attributes["http.path"] == "/animal" + - keep_keys(attributes, "http.method", "http.path") + metrics: + queries: + - set(metric.name, "bear") where attributes["http.path"] == "/animal" + - keep_keys(attributes, "http.method", "http.path") + logs: + queries: + - set(body, "bear") where attributes["http.path"] == "/animal" + - keep_keys(attributes, "http.method", "http.path") -receivers: - nop: +transform/bad_syntax_log: + logs: + queries: + - set(body, "bear" where attributes["http.path"] == "/animal" + - keep_keys(attributes, "http.method", "http.path") -exporters: - nop: +transform/bad_syntax_metric: + metrics: + queries: + - set(name, "bear" where attributes["http.path"] == "/animal" + - keep_keys(attributes, "http.method", "http.path") -service: - pipelines: - traces: - receivers: [nop] - processors: [transform] - exporters: [nop] +transform/bad_syntax_trace: + traces: + queries: + - set(name, "bear" where attributes["http.path"] == "/animal" + - keep_keys(attributes, "http.method", "http.path") + +transform/unknown_function_log: + logs: + queries: + - set(body, "bear") where attributes["http.path"] == "/animal" + - not_a_function(attributes, "http.method", "http.path") + +transform/unknown_function_metric: + metrics: + queries: + - set(metric.name, "bear") where attributes["http.path"] == "/animal" + - not_a_function(attributes, "http.method", "http.path") + +transform/unknown_function_trace: + traces: + queries: + - set(name, "bear") where attributes["http.path"] == "/animal" + - not_a_function(attributes, "http.method", "http.path") diff --git a/processor/transformprocessor/testdata/invalid_config_bad_syntax_log.yaml b/processor/transformprocessor/testdata/invalid_config_bad_syntax_log.yaml deleted file mode 100644 index b9f35171cb93..000000000000 --- a/processor/transformprocessor/testdata/invalid_config_bad_syntax_log.yaml +++ /dev/null @@ -1,19 +0,0 @@ -processors: - transform: - logs: - queries: - - set(body, "bear" where attributes["http.path"] == "/animal" - - keep_keys(attributes, "http.method", "http.path") - -receivers: - nop: - -exporters: - nop: - -service: - pipelines: - traces: - receivers: [nop] - processors: [transform] - exporters: [nop] diff --git a/processor/transformprocessor/testdata/invalid_config_bad_syntax_metric.yaml b/processor/transformprocessor/testdata/invalid_config_bad_syntax_metric.yaml deleted file mode 100644 index eeee4170d3d4..000000000000 --- a/processor/transformprocessor/testdata/invalid_config_bad_syntax_metric.yaml +++ /dev/null @@ -1,19 +0,0 @@ -processors: - transform: - metrics: - queries: - - set(name, "bear" where attributes["http.path"] == "/animal" - - keep_keys(attributes, "http.method", "http.path") - -receivers: - nop: - -exporters: - nop: - -service: - pipelines: - traces: - receivers: [nop] - processors: [transform] - exporters: [nop] diff --git a/processor/transformprocessor/testdata/invalid_config_bad_syntax_trace.yaml b/processor/transformprocessor/testdata/invalid_config_bad_syntax_trace.yaml deleted file mode 100644 index 18d61839caa8..000000000000 --- a/processor/transformprocessor/testdata/invalid_config_bad_syntax_trace.yaml +++ /dev/null @@ -1,19 +0,0 @@ -processors: - transform: - traces: - queries: - - set(name, "bear" where attributes["http.path"] == "/animal" - - keep_keys(attributes, "http.method", "http.path") - -receivers: - nop: - -exporters: - nop: - -service: - pipelines: - traces: - receivers: [nop] - processors: [transform] - exporters: [nop] diff --git a/processor/transformprocessor/testdata/invalid_config_unknown_function_log.yaml b/processor/transformprocessor/testdata/invalid_config_unknown_function_log.yaml deleted file mode 100644 index 0b29bcf2876c..000000000000 --- a/processor/transformprocessor/testdata/invalid_config_unknown_function_log.yaml +++ /dev/null @@ -1,19 +0,0 @@ -processors: - transform: - logs: - queries: - - set(body, "bear") where attributes["http.path"] == "/animal" - - not_a_function(attributes, "http.method", "http.path") - -receivers: - nop: - -exporters: - nop: - -service: - pipelines: - traces: - receivers: [nop] - processors: [transform] - exporters: [nop] diff --git a/processor/transformprocessor/testdata/invalid_config_unknown_function_metric.yaml b/processor/transformprocessor/testdata/invalid_config_unknown_function_metric.yaml deleted file mode 100644 index a07895346d35..000000000000 --- a/processor/transformprocessor/testdata/invalid_config_unknown_function_metric.yaml +++ /dev/null @@ -1,19 +0,0 @@ -processors: - transform: - metrics: - queries: - - set(metric.name, "bear") where attributes["http.path"] == "/animal" - - not_a_function(attributes, "http.method", "http.path") - -receivers: - nop: - -exporters: - nop: - -service: - pipelines: - traces: - receivers: [nop] - processors: [transform] - exporters: [nop] diff --git a/processor/transformprocessor/testdata/invalid_config_unknown_function_trace.yaml b/processor/transformprocessor/testdata/invalid_config_unknown_function_trace.yaml deleted file mode 100644 index 75e62bc40663..000000000000 --- a/processor/transformprocessor/testdata/invalid_config_unknown_function_trace.yaml +++ /dev/null @@ -1,19 +0,0 @@ -processors: - transform: - traces: - queries: - - set(name, "bear") where attributes["http.path"] == "/animal" - - not_a_function(attributes, "http.method", "http.path") - -receivers: - nop: - -exporters: - nop: - -service: - pipelines: - traces: - receivers: [nop] - processors: [transform] - exporters: [nop]