From 596c15f8f82bb903bca61ec6a5fde657e54113cd Mon Sep 17 00:00:00 2001 From: Ruslan Kovalov Date: Wed, 28 Sep 2022 18:51:58 +0200 Subject: [PATCH] [chore] Change receiver config tests to unmarshal config only for that component. (part5) (#14563) - [x] splunkhecreceiver - [x] sqlqueryreceiver - [x] sqlserverreceiver - [x] statsdreceiver - [x] syslogreceiver - [x] tcplogreceiver - [x] udplogreceiver - [x] vcenterreceiver - [x] wavefrontreceiver - [x] windowsperfcountersreceiver - [x] zipkinreceiver - [x] zookeeperreceiver --- receiver/splunkhecreceiver/config_test.go | 115 ++++---- .../splunkhecreceiver/testdata/config.yaml | 46 ++-- receiver/sqlqueryreceiver/config_test.go | 177 +++++++----- .../testdata/config-invalid-aggregation.yaml | 38 +-- .../testdata/config-invalid-datatype.yaml | 38 +-- .../config-invalid-missing-datasource.yaml | 36 +-- .../config-invalid-missing-driver.yaml | 36 +-- .../config-invalid-missing-metricname.yaml | 36 +-- .../config-invalid-missing-metrics.yaml | 22 +- .../config-invalid-missing-queries.yaml | 18 +- .../testdata/config-invalid-missing-sql.yaml | 36 +-- .../config-invalid-missing-valuecolumn.yaml | 36 +-- .../testdata/config-invalid-multierr.yaml | 38 +-- .../testdata/config-invalid-valuetype.yaml | 38 +-- .../config-unnecessary-aggregation.yaml | 38 +-- .../sqlqueryreceiver/testdata/config.yaml | 42 ++- .../testdata/oracledb-receiver-config.yaml | 64 ++--- receiver/sqlserverreceiver/config_test.go | 21 +- .../sqlserverreceiver/testdata/config.yaml | 18 +- receiver/statsdreceiver/config_test.go | 67 +++-- receiver/statsdreceiver/testdata/config.yaml | 36 +-- receiver/syslogreceiver/syslog_test.go | 18 +- receiver/syslogreceiver/testdata/config.yaml | 28 +- receiver/tcplogreceiver/tcp_test.go | 18 +- receiver/tcplogreceiver/testdata/config.yaml | 22 +- receiver/udplogreceiver/testdata/config.yaml | 18 +- receiver/udplogreceiver/udp_test.go | 18 +- receiver/vcenterreceiver/testdata/config.yaml | 30 +-- receiver/wavefrontreceiver/config_test.go | 58 ++-- .../wavefrontreceiver/testdata/config.yaml | 36 +-- .../config_test.go | 254 ++++++++---------- .../testdata/config-allerrors.yaml | 20 -- .../testdata/config-emptyinstance.yaml | 26 -- .../config-negative-collection-interval.yaml | 26 -- .../testdata/config-nocounters.yaml | 22 -- .../testdata/config-nometrics.yaml | 19 -- .../testdata/config-nometricspecified.yaml | 24 -- .../testdata/config-noobjectname.yaml | 24 -- .../testdata/config-noperfcounters.yaml | 19 -- .../testdata/config-summetric.yaml | 26 -- .../config-unspecifiedmetrictype.yaml | 24 -- .../testdata/config.yaml | 180 +++++++++---- receiver/zipkinreceiver/config_test.go | 70 +++-- receiver/zipkinreceiver/testdata/config.yaml | 25 +- 44 files changed, 827 insertions(+), 1174 deletions(-) delete mode 100644 receiver/windowsperfcountersreceiver/testdata/config-allerrors.yaml delete mode 100644 receiver/windowsperfcountersreceiver/testdata/config-emptyinstance.yaml delete mode 100644 receiver/windowsperfcountersreceiver/testdata/config-negative-collection-interval.yaml delete mode 100644 receiver/windowsperfcountersreceiver/testdata/config-nocounters.yaml delete mode 100644 receiver/windowsperfcountersreceiver/testdata/config-nometrics.yaml delete mode 100644 receiver/windowsperfcountersreceiver/testdata/config-nometricspecified.yaml delete mode 100644 receiver/windowsperfcountersreceiver/testdata/config-noobjectname.yaml delete mode 100644 receiver/windowsperfcountersreceiver/testdata/config-noperfcounters.yaml delete mode 100644 receiver/windowsperfcountersreceiver/testdata/config-summetric.yaml delete mode 100644 receiver/windowsperfcountersreceiver/testdata/config-unspecifiedmetrictype.yaml diff --git a/receiver/splunkhecreceiver/config_test.go b/receiver/splunkhecreceiver/config_test.go index b959d9acd4ae..b628007be622 100644 --- a/receiver/splunkhecreceiver/config_test.go +++ b/receiver/splunkhecreceiver/config_test.go @@ -20,72 +20,85 @@ 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/config/confighttp" "go.opentelemetry.io/collector/config/configtls" - "go.opentelemetry.io/collector/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk" ) func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.Nil(t, err) - - factory := NewFactory() - factories.Receivers[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) + t.Parallel() + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) - require.NotNil(t, cfg) - - assert.Equal(t, len(cfg.Receivers), 3) - - r0 := cfg.Receivers[config.NewComponentID(typeStr)].(*Config) - assert.Equal(t, r0, createDefaultConfig()) - r1 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "allsettings")].(*Config) - expectedAllSettings := &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "allsettings")), - HTTPServerSettings: confighttp.HTTPServerSettings{ - Endpoint: "localhost:8088", - }, - AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{ - AccessTokenPassthrough: true, - }, - RawPath: "/foo", - HecToOtelAttrs: splunk.HecToOtelAttrs{ - Source: "file.name", - SourceType: "foobar", - Index: "myindex", - Host: "myhostfield", + tests := []struct { + id config.ComponentID + expected config.Receiver + }{ + { + id: config.NewComponentID(typeStr), + expected: createDefaultConfig(), }, - } - assert.Equal(t, expectedAllSettings, r1) - - r2 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "tls")].(*Config) - expectedTLSConfig := &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "tls")), - HTTPServerSettings: confighttp.HTTPServerSettings{ - Endpoint: ":8088", - TLSSetting: &configtls.TLSServerSetting{ - TLSSetting: configtls.TLSSetting{ - CertFile: "/test.crt", - KeyFile: "/test.key", + { + id: config.NewComponentIDWithName(typeStr, "allsettings"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + HTTPServerSettings: confighttp.HTTPServerSettings{ + Endpoint: "localhost:8088", + }, + AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{ + AccessTokenPassthrough: true, + }, + RawPath: "/foo", + HecToOtelAttrs: splunk.HecToOtelAttrs{ + Source: "file.name", + SourceType: "foobar", + Index: "myindex", + Host: "myhostfield", }, }, }, - AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{ - AccessTokenPassthrough: false, - }, - RawPath: "/services/collector/raw", - HecToOtelAttrs: splunk.HecToOtelAttrs{ - Source: "com.splunk.source", - SourceType: "com.splunk.sourcetype", - Index: "com.splunk.index", - Host: "host.name", + { + id: config.NewComponentIDWithName(typeStr, "tls"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + HTTPServerSettings: confighttp.HTTPServerSettings{ + Endpoint: ":8088", + TLSSetting: &configtls.TLSServerSetting{ + TLSSetting: configtls.TLSSetting{ + CertFile: "/test.crt", + KeyFile: "/test.key", + }, + }, + }, + AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{ + AccessTokenPassthrough: false, + }, + RawPath: "/services/collector/raw", + HecToOtelAttrs: splunk.HecToOtelAttrs{ + Source: "com.splunk.source", + SourceType: "com.splunk.sourcetype", + Index: "com.splunk.index", + Host: "host.name", + }, + }, }, } - assert.Equal(t, expectedTLSConfig, r2) + + for _, tt := range tests { + t.Run(tt.id.String(), func(t *testing.T) { + factory := NewFactory() + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub(tt.id.String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) + + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) + }) + } } diff --git a/receiver/splunkhecreceiver/testdata/config.yaml b/receiver/splunkhecreceiver/testdata/config.yaml index 481cb8a4b875..3bce83e60856 100644 --- a/receiver/splunkhecreceiver/testdata/config.yaml +++ b/receiver/splunkhecreceiver/testdata/config.yaml @@ -1,30 +1,16 @@ -receivers: - splunk_hec: - splunk_hec/allsettings: - # endpoint specifies the network interface and port which will receive - # Splunk metrics. - endpoint: localhost:8088 - access_token_passthrough: true - raw_path: "/foo" - hec_metadata_to_otel_attrs: - source: "file.name" - sourcetype: "foobar" - index: "myindex" - host: "myhostfield" - splunk_hec/tls: - tls: - cert_file: /test.crt - key_file: /test.key - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [splunk_hec, splunk_hec/allsettings] - processors: [nop] - exporters: [nop] +splunk_hec: +splunk_hec/allsettings: + # endpoint specifies the network interface and port which will receive + # Splunk metrics. + endpoint: localhost:8088 + access_token_passthrough: true + raw_path: "/foo" + hec_metadata_to_otel_attrs: + source: "file.name" + sourcetype: "foobar" + index: "myindex" + host: "myhostfield" +splunk_hec/tls: + tls: + cert_file: /test.crt + key_file: /test.key diff --git a/receiver/sqlqueryreceiver/config_test.go b/receiver/sqlqueryreceiver/config_test.go index 97386bfa4898..378cfbfa99e3 100644 --- a/receiver/sqlqueryreceiver/config_test.go +++ b/receiver/sqlqueryreceiver/config_test.go @@ -15,117 +15,154 @@ package sqlqueryreceiver import ( - "path" + "path/filepath" "testing" "time" "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/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" + "go.opentelemetry.io/collector/receiver/scraperhelper" ) -func TestCreateDefaultConfig(t *testing.T) { - cfg := createDefaultConfig().(*Config) - assert.Equal(t, 10*time.Second, cfg.ScraperControllerSettings.CollectionInterval) -} - -func TestParseConfig(t *testing.T) { - cfg, err := servicetest.LoadConfigAndValidate(path.Join("testdata", "config.yaml"), testFactories(t)) - require.NoError(t, err) - sqlCfg := cfg.Receivers[config.NewComponentID(typeStr)].(*Config) - assert.Equal(t, "mydriver", sqlCfg.Driver) - assert.Equal(t, "host=localhost port=5432 user=me password=s3cr3t sslmode=disable", sqlCfg.DataSource) - q := sqlCfg.Queries[0] - assert.Equal(t, "select count(*) as count, type from mytable group by type", q.SQL) - metric := q.Metrics[0] - assert.Equal(t, "val.count", metric.MetricName) - assert.Equal(t, "count", metric.ValueColumn) - assert.Equal(t, "type", metric.AttributeColumns[0]) - assert.Equal(t, false, metric.Monotonic) - assert.Equal(t, MetricTypeSum, metric.DataType) - assert.Equal(t, MetricValueTypeInt, metric.ValueType) - assert.Equal(t, map[string]string{"foo": "bar"}, metric.StaticAttributes) - assert.Equal(t, MetricAggregationCumulative, metric.Aggregation) -} +func TestLoadConfig(t *testing.T) { + t.Parallel() -func TestValidateConfig_Invalid(t *testing.T) { tests := []struct { - fname string - errSubstr string + fname string + id config.ComponentID + expected config.Receiver + errorMessage string }{ { - fname: "config-invalid-datatype.yaml", - errSubstr: "unsupported data_type: 'xyzgauge'", + id: config.NewComponentIDWithName(typeStr, ""), + fname: "config.yaml", + expected: &Config{ + ScraperControllerSettings: scraperhelper.ScraperControllerSettings{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + CollectionInterval: 10 * time.Second, + }, + Driver: "mydriver", + DataSource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable", + Queries: []Query{ + { + SQL: "select count(*) as count, type from mytable group by type", + Metrics: []MetricCfg{ + { + MetricName: "val.count", + ValueColumn: "count", + AttributeColumns: []string{"type"}, + Monotonic: false, + ValueType: MetricValueTypeInt, + DataType: MetricTypeSum, + Aggregation: MetricAggregationCumulative, + StaticAttributes: map[string]string{"foo": "bar"}, + }, + }, + }, + }, + }, }, { - fname: "config-invalid-valuetype.yaml", - errSubstr: "unsupported value_type: 'xyzint'", + fname: "config-invalid-datatype.yaml", + id: config.NewComponentIDWithName(typeStr, ""), + errorMessage: "unsupported data_type: 'xyzgauge'", }, { - fname: "config-invalid-aggregation.yaml", - errSubstr: "unsupported aggregation: 'xyzcumulative'", + fname: "config-invalid-valuetype.yaml", + id: config.NewComponentIDWithName(typeStr, ""), + errorMessage: "unsupported value_type: 'xyzint'", }, { - fname: "config-invalid-missing-metricname.yaml", - errSubstr: "'metric_name' cannot be empty", + fname: "config-invalid-aggregation.yaml", + id: config.NewComponentIDWithName(typeStr, ""), + errorMessage: "unsupported aggregation: 'xyzcumulative'", }, { - fname: "config-invalid-missing-valuecolumn.yaml", - errSubstr: "'value_column' cannot be empty", + fname: "config-invalid-missing-metricname.yaml", + id: config.NewComponentIDWithName(typeStr, ""), + errorMessage: "'metric_name' cannot be empty", }, { - fname: "config-invalid-missing-sql.yaml", - errSubstr: "'query.sql' cannot be empty", + fname: "config-invalid-missing-valuecolumn.yaml", + id: config.NewComponentIDWithName(typeStr, ""), + errorMessage: "'value_column' cannot be empty", }, { - fname: "config-invalid-missing-queries.yaml", - errSubstr: "'queries' cannot be empty", + fname: "config-invalid-missing-sql.yaml", + id: config.NewComponentIDWithName(typeStr, ""), + errorMessage: "'query.sql' cannot be empty", }, { - fname: "config-invalid-missing-driver.yaml", - errSubstr: "'driver' cannot be empty", + fname: "config-invalid-missing-queries.yaml", + id: config.NewComponentIDWithName(typeStr, ""), + errorMessage: "'queries' cannot be empty", }, { - fname: "config-invalid-missing-metrics.yaml", - errSubstr: "'query.metrics' cannot be empty", + fname: "config-invalid-missing-driver.yaml", + id: config.NewComponentIDWithName(typeStr, ""), + errorMessage: "'driver' cannot be empty", }, { - fname: "config-invalid-missing-datasource.yaml", - errSubstr: "'datasource' cannot be empty", + fname: "config-invalid-missing-metrics.yaml", + id: config.NewComponentIDWithName(typeStr, ""), + errorMessage: "'query.metrics' cannot be empty", }, { - fname: "config-unnecessary-aggregation.yaml", - errSubstr: "aggregation=cumulative but data_type=gauge does not support aggregation", + fname: "config-invalid-missing-datasource.yaml", + id: config.NewComponentIDWithName(typeStr, ""), + errorMessage: "'datasource' cannot be empty", + }, + { + fname: "config-unnecessary-aggregation.yaml", + id: config.NewComponentIDWithName(typeStr, ""), + errorMessage: "aggregation=cumulative but data_type=gauge does not support aggregation", }, } - for _, test := range tests { - t.Run(test.fname, func(t *testing.T) { - _, err := servicetest.LoadConfigAndValidate( - path.Join("testdata", test.fname), - testFactories(t), - ) - assert.ErrorContains(t, err, test.errSubstr) + + for _, tt := range tests { + t.Run(tt.id.String(), func(t *testing.T) { + cm, err := confmaptest.LoadConf(filepath.Join("testdata", tt.fname)) + require.NoError(t, err) + + factory := NewFactory() + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub(tt.id.String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) + + if tt.expected == nil { + assert.ErrorContains(t, cfg.Validate(), tt.errorMessage) + return + } + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) }) } } +func TestCreateDefaultConfig(t *testing.T) { + cfg := createDefaultConfig().(*Config) + assert.Equal(t, 10*time.Second, cfg.ScraperControllerSettings.CollectionInterval) +} + func TestConfig_Validate_Multierr(t *testing.T) { - _, err := servicetest.LoadConfigAndValidate( - path.Join("testdata", "config-invalid-multierr.yaml"), - testFactories(t), - ) + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config-invalid-multierr.yaml")) + require.NoError(t, err) + + factory := NewFactory() + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub(config.NewComponentIDWithName(typeStr, "").String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) + + err = cfg.Validate() + assert.ErrorContains(t, err, "invalid metric config with metric_name 'my.metric'") assert.ErrorContains(t, err, "metric config has unsupported value_type: 'xint'") assert.ErrorContains(t, err, "metric config has unsupported data_type: 'xgauge'") assert.ErrorContains(t, err, "metric config has unsupported aggregation: 'xcumulative'") } - -func testFactories(t *testing.T) component.Factories { - factories, err := componenttest.NopFactories() - require.NoError(t, err) - factories.Receivers[typeStr] = NewFactory() - return factories -} diff --git a/receiver/sqlqueryreceiver/testdata/config-invalid-aggregation.yaml b/receiver/sqlqueryreceiver/testdata/config-invalid-aggregation.yaml index 751858e87ea2..286e5fe7a6de 100644 --- a/receiver/sqlqueryreceiver/testdata/config-invalid-aggregation.yaml +++ b/receiver/sqlqueryreceiver/testdata/config-invalid-aggregation.yaml @@ -1,24 +1,14 @@ -receivers: - sqlquery: - collection_interval: 10s - driver: mydriver - datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" - queries: - - sql: "select count(*) as count, type from mytable group by type" - metrics: - - metric_name: val.count - value_column: "count" - attribute_columns: [ "type" ] - data_type: gauge - value_type: int - monotonic: false - aggregation: xyzcumulative -exporters: - nop: -service: - pipelines: - metrics: - receivers: - - sqlquery - exporters: - - nop +sqlquery: + collection_interval: 10s + driver: mydriver + datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" + queries: + - sql: "select count(*) as count, type from mytable group by type" + metrics: + - metric_name: val.count + value_column: "count" + attribute_columns: [ "type" ] + data_type: gauge + value_type: int + monotonic: false + aggregation: xyzcumulative diff --git a/receiver/sqlqueryreceiver/testdata/config-invalid-datatype.yaml b/receiver/sqlqueryreceiver/testdata/config-invalid-datatype.yaml index 797a9af828f4..b25db3a17de7 100644 --- a/receiver/sqlqueryreceiver/testdata/config-invalid-datatype.yaml +++ b/receiver/sqlqueryreceiver/testdata/config-invalid-datatype.yaml @@ -1,24 +1,14 @@ -receivers: - sqlquery: - collection_interval: 10s - driver: mydriver - datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" - queries: - - sql: "select count(*) as count, type from mytable group by type" - metrics: - - metric_name: val.count - value_column: "count" - attribute_columns: [ "type" ] - data_type: xyzgauge - value_type: int - monotonic: false - aggregation: cumulative -exporters: - nop: -service: - pipelines: - metrics: - receivers: - - sqlquery - exporters: - - nop +sqlquery: + collection_interval: 10s + driver: mydriver + datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" + queries: + - sql: "select count(*) as count, type from mytable group by type" + metrics: + - metric_name: val.count + value_column: "count" + attribute_columns: [ "type" ] + data_type: xyzgauge + value_type: int + monotonic: false + aggregation: cumulative diff --git a/receiver/sqlqueryreceiver/testdata/config-invalid-missing-datasource.yaml b/receiver/sqlqueryreceiver/testdata/config-invalid-missing-datasource.yaml index dc995319edcd..e23b692c7efb 100644 --- a/receiver/sqlqueryreceiver/testdata/config-invalid-missing-datasource.yaml +++ b/receiver/sqlqueryreceiver/testdata/config-invalid-missing-datasource.yaml @@ -1,23 +1,13 @@ -receivers: - sqlquery: - collection_interval: 10s - driver: mydriver - queries: - - sql: "select count(*) as count, type from mytable group by type" - metrics: - - metric_name: val.count - value_column: "count" - attribute_columns: [ "type" ] - data_type: gauge - value_type: int - monotonic: false - aggregation: cumulative -exporters: - nop: -service: - pipelines: - metrics: - receivers: - - sqlquery - exporters: - - nop +sqlquery: + collection_interval: 10s + driver: mydriver + queries: + - sql: "select count(*) as count, type from mytable group by type" + metrics: + - metric_name: val.count + value_column: "count" + attribute_columns: [ "type" ] + data_type: gauge + value_type: int + monotonic: false + aggregation: cumulative diff --git a/receiver/sqlqueryreceiver/testdata/config-invalid-missing-driver.yaml b/receiver/sqlqueryreceiver/testdata/config-invalid-missing-driver.yaml index 9bb1170e656d..586763186703 100644 --- a/receiver/sqlqueryreceiver/testdata/config-invalid-missing-driver.yaml +++ b/receiver/sqlqueryreceiver/testdata/config-invalid-missing-driver.yaml @@ -1,23 +1,13 @@ -receivers: - sqlquery: - collection_interval: 10s - datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" - queries: - - sql: "select count(*) as count, type from mytable group by type" - metrics: - - metric_name: val.count - value_column: "count" - attribute_columns: [ "type" ] - data_type: gauge - value_type: int - monotonic: false - aggregation: cumulative -exporters: - nop: -service: - pipelines: - metrics: - receivers: - - sqlquery - exporters: - - nop +sqlquery: + collection_interval: 10s + datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" + queries: + - sql: "select count(*) as count, type from mytable group by type" + metrics: + - metric_name: val.count + value_column: "count" + attribute_columns: [ "type" ] + data_type: gauge + value_type: int + monotonic: false + aggregation: cumulative diff --git a/receiver/sqlqueryreceiver/testdata/config-invalid-missing-metricname.yaml b/receiver/sqlqueryreceiver/testdata/config-invalid-missing-metricname.yaml index 5671a5c455b2..28fd4e347c5b 100644 --- a/receiver/sqlqueryreceiver/testdata/config-invalid-missing-metricname.yaml +++ b/receiver/sqlqueryreceiver/testdata/config-invalid-missing-metricname.yaml @@ -1,23 +1,13 @@ -receivers: - sqlquery: - collection_interval: 10s - driver: mydriver - datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" - queries: - - sql: "select count(*) as count, type from mytable group by type" - metrics: - - value_column: "count" - attribute_columns: [ "type" ] - data_type: gauge - value_type: int - monotonic: false - aggregation: cumulative -exporters: - nop: -service: - pipelines: - metrics: - receivers: - - sqlquery - exporters: - - nop +sqlquery: + collection_interval: 10s + driver: mydriver + datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" + queries: + - sql: "select count(*) as count, type from mytable group by type" + metrics: + - value_column: "count" + attribute_columns: [ "type" ] + data_type: gauge + value_type: int + monotonic: false + aggregation: cumulative diff --git a/receiver/sqlqueryreceiver/testdata/config-invalid-missing-metrics.yaml b/receiver/sqlqueryreceiver/testdata/config-invalid-missing-metrics.yaml index 2db349c9a25b..f62872fbc21a 100644 --- a/receiver/sqlqueryreceiver/testdata/config-invalid-missing-metrics.yaml +++ b/receiver/sqlqueryreceiver/testdata/config-invalid-missing-metrics.yaml @@ -1,16 +1,6 @@ -receivers: - sqlquery: - collection_interval: 10s - driver: mydriver - datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" - queries: - - sql: "select count(*) as count, type from mytable group by type" -exporters: - nop: -service: - pipelines: - metrics: - receivers: - - sqlquery - exporters: - - nop +sqlquery: + collection_interval: 10s + driver: mydriver + datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" + queries: + - sql: "select count(*) as count, type from mytable group by type" diff --git a/receiver/sqlqueryreceiver/testdata/config-invalid-missing-queries.yaml b/receiver/sqlqueryreceiver/testdata/config-invalid-missing-queries.yaml index da6233c090f6..37e1f175f4d5 100644 --- a/receiver/sqlqueryreceiver/testdata/config-invalid-missing-queries.yaml +++ b/receiver/sqlqueryreceiver/testdata/config-invalid-missing-queries.yaml @@ -1,14 +1,4 @@ -receivers: - sqlquery: - collection_interval: 10s - driver: mydriver - datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" -exporters: - nop: -service: - pipelines: - metrics: - receivers: - - sqlquery - exporters: - - nop +sqlquery: + collection_interval: 10s + driver: mydriver + datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" diff --git a/receiver/sqlqueryreceiver/testdata/config-invalid-missing-sql.yaml b/receiver/sqlqueryreceiver/testdata/config-invalid-missing-sql.yaml index 8ef07388fa6a..829ab15e4929 100644 --- a/receiver/sqlqueryreceiver/testdata/config-invalid-missing-sql.yaml +++ b/receiver/sqlqueryreceiver/testdata/config-invalid-missing-sql.yaml @@ -1,23 +1,13 @@ -receivers: - sqlquery: - collection_interval: 10s - driver: mydriver - datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" - queries: - - metrics: - - metric_name: val.count - value_column: "count" - attribute_columns: [ "type" ] - data_type: gauge - value_type: int - monotonic: false - aggregation: cumulative -exporters: - nop: -service: - pipelines: - metrics: - receivers: - - sqlquery - exporters: - - nop +sqlquery: + collection_interval: 10s + driver: mydriver + datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" + queries: + - metrics: + - metric_name: val.count + value_column: "count" + attribute_columns: [ "type" ] + data_type: gauge + value_type: int + monotonic: false + aggregation: cumulative diff --git a/receiver/sqlqueryreceiver/testdata/config-invalid-missing-valuecolumn.yaml b/receiver/sqlqueryreceiver/testdata/config-invalid-missing-valuecolumn.yaml index 7faa2018ae31..902956c5521c 100644 --- a/receiver/sqlqueryreceiver/testdata/config-invalid-missing-valuecolumn.yaml +++ b/receiver/sqlqueryreceiver/testdata/config-invalid-missing-valuecolumn.yaml @@ -1,23 +1,13 @@ -receivers: - sqlquery: - collection_interval: 10s - driver: mydriver - datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" - queries: - - sql: "select count(*) as count, type from mytable group by type" - metrics: - - metric_name: val.count - attribute_columns: [ "type" ] - data_type: gauge - value_type: int - monotonic: false - aggregation: cumulative -exporters: - nop: -service: - pipelines: - metrics: - receivers: - - sqlquery - exporters: - - nop +sqlquery: + collection_interval: 10s + driver: mydriver + datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" + queries: + - sql: "select count(*) as count, type from mytable group by type" + metrics: + - metric_name: val.count + attribute_columns: [ "type" ] + data_type: gauge + value_type: int + monotonic: false + aggregation: cumulative diff --git a/receiver/sqlqueryreceiver/testdata/config-invalid-multierr.yaml b/receiver/sqlqueryreceiver/testdata/config-invalid-multierr.yaml index 19a50896620f..0236a9d8a092 100644 --- a/receiver/sqlqueryreceiver/testdata/config-invalid-multierr.yaml +++ b/receiver/sqlqueryreceiver/testdata/config-invalid-multierr.yaml @@ -1,24 +1,14 @@ -receivers: - sqlquery: - collection_interval: 10s - driver: mydriver - datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" - queries: - - sql: "select count(*) as count, type from mytable group by type" - metrics: - - metric_name: my.metric - value_column: "count" - attribute_columns: [ "type" ] - data_type: xgauge - value_type: xint - monotonic: false - aggregation: xcumulative -exporters: - nop: -service: - pipelines: - metrics: - receivers: - - sqlquery - exporters: - - nop +sqlquery: + collection_interval: 10s + driver: mydriver + datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" + queries: + - sql: "select count(*) as count, type from mytable group by type" + metrics: + - metric_name: my.metric + value_column: "count" + attribute_columns: [ "type" ] + data_type: xgauge + value_type: xint + monotonic: false + aggregation: xcumulative diff --git a/receiver/sqlqueryreceiver/testdata/config-invalid-valuetype.yaml b/receiver/sqlqueryreceiver/testdata/config-invalid-valuetype.yaml index dabaffe58983..36c62b136fc3 100644 --- a/receiver/sqlqueryreceiver/testdata/config-invalid-valuetype.yaml +++ b/receiver/sqlqueryreceiver/testdata/config-invalid-valuetype.yaml @@ -1,24 +1,14 @@ -receivers: - sqlquery: - collection_interval: 10s - driver: mydriver - datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" - queries: - - sql: "select count(*) as count, type from mytable group by type" - metrics: - - metric_name: val.count - value_column: "count" - attribute_columns: [ "type" ] - data_type: gauge - value_type: xyzint - monotonic: false - aggregation: cumulative -exporters: - nop: -service: - pipelines: - metrics: - receivers: - - sqlquery - exporters: - - nop +sqlquery: + collection_interval: 10s + driver: mydriver + datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" + queries: + - sql: "select count(*) as count, type from mytable group by type" + metrics: + - metric_name: val.count + value_column: "count" + attribute_columns: [ "type" ] + data_type: gauge + value_type: xyzint + monotonic: false + aggregation: cumulative diff --git a/receiver/sqlqueryreceiver/testdata/config-unnecessary-aggregation.yaml b/receiver/sqlqueryreceiver/testdata/config-unnecessary-aggregation.yaml index 2c6a9df8321a..046dc0904a5d 100644 --- a/receiver/sqlqueryreceiver/testdata/config-unnecessary-aggregation.yaml +++ b/receiver/sqlqueryreceiver/testdata/config-unnecessary-aggregation.yaml @@ -1,24 +1,14 @@ -receivers: - sqlquery: - collection_interval: 10s - driver: mydriver - datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" - queries: - - sql: "select count(*) as count, type from mytable group by type" - metrics: - - metric_name: val.count - value_column: "count" - attribute_columns: [ "type" ] - data_type: gauge - value_type: int - monotonic: false - aggregation: cumulative -exporters: - nop: -service: - pipelines: - metrics: - receivers: - - sqlquery - exporters: - - nop +sqlquery: + collection_interval: 10s + driver: mydriver + datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" + queries: + - sql: "select count(*) as count, type from mytable group by type" + metrics: + - metric_name: val.count + value_column: "count" + attribute_columns: [ "type" ] + data_type: gauge + value_type: int + monotonic: false + aggregation: cumulative diff --git a/receiver/sqlqueryreceiver/testdata/config.yaml b/receiver/sqlqueryreceiver/testdata/config.yaml index 604541d15d2c..5af1192d5ee2 100644 --- a/receiver/sqlqueryreceiver/testdata/config.yaml +++ b/receiver/sqlqueryreceiver/testdata/config.yaml @@ -1,26 +1,16 @@ -receivers: - sqlquery: - collection_interval: 10s - driver: mydriver - datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" - queries: - - sql: "select count(*) as count, type from mytable group by type" - metrics: - - metric_name: val.count - value_column: "count" - attribute_columns: [ "type" ] - data_type: sum - value_type: int - monotonic: false - aggregation: cumulative - static_attributes: - foo: bar -exporters: - nop: -service: - pipelines: - metrics: - receivers: - - sqlquery - exporters: - - nop +sqlquery: + collection_interval: 10s + driver: mydriver + datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable" + queries: + - sql: "select count(*) as count, type from mytable group by type" + metrics: + - metric_name: val.count + value_column: "count" + attribute_columns: [ "type" ] + data_type: sum + value_type: int + monotonic: false + aggregation: cumulative + static_attributes: + foo: bar diff --git a/receiver/sqlqueryreceiver/testdata/oracledb-receiver-config.yaml b/receiver/sqlqueryreceiver/testdata/oracledb-receiver-config.yaml index 8c9643fc80fe..6e7c84fd2ab0 100644 --- a/receiver/sqlqueryreceiver/testdata/oracledb-receiver-config.yaml +++ b/receiver/sqlqueryreceiver/testdata/oracledb-receiver-config.yaml @@ -1,37 +1,27 @@ -receivers: - sqlquery: - # driver name: oracle - # username: otel - # password: password - # host: localhost - # container exposed port: 51521 - # Oracle DB service name: XE - # Refer to Oracle Go Driver go_ora documentation for full connection string options - datasource: "oracle://otel:password@localhost:51521/XE" - driver: oracle - queries: - # Note: The table name may need to be preceded by the name of the user who created the table. - # If the table is created by an initialization script within a docker container, it would be referred - # to as "sys.movie", as the sys user runs initialization scripts. Permission would need to be granted - # to the "otel" user to access or modify the table in that case. - # This example assumes "otel" created the movie table. - - sql: "select count(*) as count, genre, avg(imdb_rating) as avg from otel.movie group by genre" - metrics: - - metric_name: genre.count - # Note that COUNT and GENRE are now all capital letters, the queries will return nothing if this isn't - # accounted for. - value_column: "COUNT" - attribute_columns: [GENRE] - - metric_name: genre.imdb - value_column: "AVG" - attribute_columns: [GENRE] - value_type: "double" -exporters: - nop: -service: - pipelines: - metrics: - receivers: - - sqlquery - exporters: - - nop +sqlquery: + # driver name: oracle + # username: otel + # password: password + # host: localhost + # container exposed port: 51521 + # Oracle DB service name: XE + # Refer to Oracle Go Driver go_ora documentation for full connection string options + datasource: "oracle://otel:password@localhost:51521/XE" + driver: oracle + queries: + # Note: The table name may need to be preceded by the name of the user who created the table. + # If the table is created by an initialization script within a docker container, it would be referred + # to as "sys.movie", as the sys user runs initialization scripts. Permission would need to be granted + # to the "otel" user to access or modify the table in that case. + # This example assumes "otel" created the movie table. + - sql: "select count(*) as count, genre, avg(imdb_rating) as avg from otel.movie group by genre" + metrics: + - metric_name: genre.count + # Note that COUNT and GENRE are now all capital letters, the queries will return nothing if this isn't + # accounted for. + value_column: "COUNT" + attribute_columns: [ GENRE ] + - metric_name: genre.imdb + value_column: "AVG" + attribute_columns: [ GENRE ] + value_type: "double" diff --git a/receiver/sqlserverreceiver/config_test.go b/receiver/sqlserverreceiver/config_test.go index c0ca2afdff2c..7c69752130b6 100644 --- a/receiver/sqlserverreceiver/config_test.go +++ b/receiver/sqlserverreceiver/config_test.go @@ -18,10 +18,10 @@ import ( "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/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver/internal/metadata" ) @@ -55,16 +55,15 @@ func TestValidate(t *testing.T) { } func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - require.Nil(t, err) - - factory := NewFactory() - factories.Receivers[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) - require.NotNil(t, cfg) + factory := NewFactory() + cfg := factory.CreateDefaultConfig() - require.Equal(t, len(cfg.Receivers), 1) + sub, err := cm.Sub("sqlserver") + require.NoError(t, err) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) - require.Equal(t, factory.CreateDefaultConfig(), cfg.Receivers[config.NewComponentID("sqlserver")]) + assert.NoError(t, cfg.Validate()) + assert.Equal(t, factory.CreateDefaultConfig(), cfg) } diff --git a/receiver/sqlserverreceiver/testdata/config.yaml b/receiver/sqlserverreceiver/testdata/config.yaml index 7a9bd67d262b..c31404757c13 100644 --- a/receiver/sqlserverreceiver/testdata/config.yaml +++ b/receiver/sqlserverreceiver/testdata/config.yaml @@ -1,16 +1,2 @@ -receivers: - sqlserver: - collection_interval: 10s - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [sqlserver] - processors: [nop] - exporters: [nop] +sqlserver: + collection_interval: 10s diff --git a/receiver/statsdreceiver/config_test.go b/receiver/statsdreceiver/config_test.go index a7b23b6e5c7b..d2042d1c8df7 100644 --- a/receiver/statsdreceiver/config_test.go +++ b/receiver/statsdreceiver/config_test.go @@ -22,40 +22,63 @@ 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/config/confignet" - "go.opentelemetry.io/collector/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/protocol" ) func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.Nil(t, err) - - factory := NewFactory() - factories.Receivers[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) + t.Parallel() + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) - require.NotNil(t, cfg) - assert.Equal(t, len(cfg.Receivers), 2) + tests := []struct { + id config.ComponentID + expected config.Receiver + }{ + { + id: config.NewComponentID(typeStr), + expected: createDefaultConfig(), + }, + { + id: config.NewComponentIDWithName(typeStr, "receiver_settings"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + NetAddr: confignet.NetAddr{ + Endpoint: "localhost:12345", + Transport: "custom_transport", + }, + AggregationInterval: 70 * time.Second, + TimerHistogramMapping: []protocol.TimerHistogramMapping{ + { + StatsdType: "histogram", + ObserverType: "gauge", + }, + { + StatsdType: "timing", + ObserverType: "gauge", + }, + }, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.id.String(), func(t *testing.T) { + factory := NewFactory() + cfg := factory.CreateDefaultConfig() - r0 := cfg.Receivers[config.NewComponentID(typeStr)] - assert.Equal(t, factory.CreateDefaultConfig(), r0) + sub, err := cm.Sub(tt.id.String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) - r1 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "receiver_settings")] - assert.Equal(t, &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "receiver_settings")), - NetAddr: confignet.NetAddr{ - Endpoint: "localhost:12345", - Transport: "custom_transport", - }, - AggregationInterval: 70 * time.Second, - TimerHistogramMapping: []protocol.TimerHistogramMapping{{StatsdType: "histogram", ObserverType: "gauge"}, {StatsdType: "timing", ObserverType: "gauge"}}, - }, r1) + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) + }) + } } func TestValidate(t *testing.T) { diff --git a/receiver/statsdreceiver/testdata/config.yaml b/receiver/statsdreceiver/testdata/config.yaml index 684fac02af6e..24a14e1a7850 100644 --- a/receiver/statsdreceiver/testdata/config.yaml +++ b/receiver/statsdreceiver/testdata/config.yaml @@ -1,25 +1,11 @@ -receivers: - statsd: - statsd/receiver_settings: - endpoint: "localhost:12345" - transport: "custom_transport" - aggregation_interval: 70s - enable_metric_type: false - timer_histogram_mapping: - - statsd_type: "histogram" - observer_type: "gauge" - - statsd_type: "timing" - observer_type: "gauge" - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [statsd] - processors: [nop] - exporters: [nop] \ No newline at end of file +statsd: +statsd/receiver_settings: + endpoint: "localhost:12345" + transport: "custom_transport" + aggregation_interval: 70s + enable_metric_type: false + timer_histogram_mapping: + - statsd_type: "histogram" + observer_type: "gauge" + - statsd_type: "timing" + observer_type: "gauge" diff --git a/receiver/syslogreceiver/syslog_test.go b/receiver/syslogreceiver/syslog_test.go index 282b33f038fe..26456db1251b 100644 --- a/receiver/syslogreceiver/syslog_test.go +++ b/receiver/syslogreceiver/syslog_test.go @@ -26,9 +26,9 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/pdata/pcommon" - "go.opentelemetry.io/collector/service/servicetest" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/adapter" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator" @@ -88,17 +88,17 @@ func testSyslog(t *testing.T, cfg *SysLogConfig) { } func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.Nil(t, err) - + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) + require.NoError(t, err) factory := NewFactory() - factories.Receivers[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub("syslog") require.NoError(t, err) - require.NotNil(t, cfg) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) - assert.Equal(t, len(cfg.Receivers), 1) - assert.Equal(t, testdataConfigYaml(), cfg.Receivers[config.NewComponentID(typeStr)]) + assert.NoError(t, cfg.Validate()) + assert.Equal(t, testdataConfigYaml(), cfg) } func testdataConfigYaml() *SysLogConfig { diff --git a/receiver/syslogreceiver/testdata/config.yaml b/receiver/syslogreceiver/testdata/config.yaml index 238280a96313..6f95159cf068 100644 --- a/receiver/syslogreceiver/testdata/config.yaml +++ b/receiver/syslogreceiver/testdata/config.yaml @@ -1,21 +1,7 @@ -receivers: - syslog: - tcp: - listen_address: "0.0.0.0:29018" - protocol: rfc5424 - converter: - flush_interval: 100ms - worker_count: 1 - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - logs: - receivers: [syslog] - processors: [ nop ] - exporters: [ nop ] +syslog: + tcp: + listen_address: "0.0.0.0:29018" + protocol: rfc5424 + converter: + flush_interval: 100ms + worker_count: 1 diff --git a/receiver/tcplogreceiver/tcp_test.go b/receiver/tcplogreceiver/tcp_test.go index b134a41be4f6..add75b5dd578 100644 --- a/receiver/tcplogreceiver/tcp_test.go +++ b/receiver/tcplogreceiver/tcp_test.go @@ -26,8 +26,8 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/consumer/consumertest" - "go.opentelemetry.io/collector/service/servicetest" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/adapter" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator" @@ -74,17 +74,17 @@ func testTCP(t *testing.T, cfg *TCPLogConfig) { } func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.Nil(t, err) - + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) + require.NoError(t, err) factory := NewFactory() - factories.Receivers[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub("tcplog") require.NoError(t, err) - require.NotNil(t, cfg) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) - assert.Equal(t, len(cfg.Receivers), 1) - assert.Equal(t, testdataConfigYaml(), cfg.Receivers[config.NewComponentID(typeStr)]) + assert.NoError(t, cfg.Validate()) + assert.Equal(t, testdataConfigYaml(), cfg) } func testdataConfigYaml() *TCPLogConfig { diff --git a/receiver/tcplogreceiver/testdata/config.yaml b/receiver/tcplogreceiver/testdata/config.yaml index 37c3eaa0efe5..06e5173740b6 100644 --- a/receiver/tcplogreceiver/testdata/config.yaml +++ b/receiver/tcplogreceiver/testdata/config.yaml @@ -1,18 +1,4 @@ -receivers: - tcplog: - listen_address: "0.0.0.0:29018" - converter: - worker_count: 1 - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - logs: - receivers: [tcplog] - processors: [ nop ] - exporters: [ nop ] +tcplog: + listen_address: "0.0.0.0:29018" + converter: + worker_count: 1 diff --git a/receiver/udplogreceiver/testdata/config.yaml b/receiver/udplogreceiver/testdata/config.yaml index 57a260f83b75..7c9ba6216f62 100644 --- a/receiver/udplogreceiver/testdata/config.yaml +++ b/receiver/udplogreceiver/testdata/config.yaml @@ -1,16 +1,2 @@ -receivers: - udplog: - listen_address: "0.0.0.0:29018" - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - logs: - receivers: [udplog] - processors: [ nop ] - exporters: [ nop ] +udplog: + listen_address: "0.0.0.0:29018" diff --git a/receiver/udplogreceiver/udp_test.go b/receiver/udplogreceiver/udp_test.go index 6b99dce610be..32014d61ebd8 100644 --- a/receiver/udplogreceiver/udp_test.go +++ b/receiver/udplogreceiver/udp_test.go @@ -26,8 +26,8 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" + "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/consumer/consumertest" - "go.opentelemetry.io/collector/service/servicetest" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/adapter" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator" @@ -78,17 +78,17 @@ func testUDP(t *testing.T, cfg *UDPLogConfig) { } func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.Nil(t, err) - + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) + require.NoError(t, err) factory := NewFactory() - factories.Receivers[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub("udplog") require.NoError(t, err) - require.NotNil(t, cfg) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) - assert.Equal(t, len(cfg.Receivers), 1) - assert.Equal(t, testdataConfigYaml(), cfg.Receivers[config.NewComponentID("udplog")]) + assert.NoError(t, cfg.Validate()) + assert.Equal(t, testdataConfigYaml(), cfg) } func testdataConfigYaml() *UDPLogConfig { diff --git a/receiver/vcenterreceiver/testdata/config.yaml b/receiver/vcenterreceiver/testdata/config.yaml index 8b9fd5882d60..6ba195d186c5 100644 --- a/receiver/vcenterreceiver/testdata/config.yaml +++ b/receiver/vcenterreceiver/testdata/config.yaml @@ -1,22 +1,8 @@ -receivers: - vcenter: - endpoint: http://vcsa.host.localnet - username: otelu - password: $VCENTER_PASSWORD - collection_interval: 5m - metrics: - vcenter.host.cpu.utilization: - enabled: false - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [vcenter] - processors: [nop] - exporters: [nop] +vcenter: + endpoint: http://vcsa.host.localnet + username: otelu + password: $VCENTER_PASSWORD + collection_interval: 5m + metrics: + vcenter.host.cpu.utilization: + enabled: false diff --git a/receiver/wavefrontreceiver/config_test.go b/receiver/wavefrontreceiver/config_test.go index 414ebd048c1a..23e8f715f959 100644 --- a/receiver/wavefrontreceiver/config_test.go +++ b/receiver/wavefrontreceiver/config_test.go @@ -21,37 +21,49 @@ 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/config/confignet" - "go.opentelemetry.io/collector/service/servicetest" + "go.opentelemetry.io/collector/confmap/confmaptest" ) func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - assert.Nil(t, err) - - factory := NewFactory() - factories.Receivers[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) + t.Parallel() + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) - require.NotNil(t, cfg) - - assert.Equal(t, len(cfg.Receivers), 2) - r0 := cfg.Receivers[config.NewComponentID(typeStr)] - assert.Equal(t, factory.CreateDefaultConfig(), r0) - - r1 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "allsettings")].(*Config) - assert.Equal(t, - &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "allsettings")), - TCPAddr: confignet.TCPAddr{ - Endpoint: "localhost:8080", + tests := []struct { + id config.ComponentID + expected config.Receiver + }{ + { + id: config.NewComponentID(typeStr), + expected: createDefaultConfig(), + }, + { + id: config.NewComponentIDWithName(typeStr, "allsettings"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + TCPAddr: confignet.TCPAddr{ + Endpoint: "localhost:8080", + }, + TCPIdleTimeout: 5 * time.Second, + ExtractCollectdTags: true, }, - TCPIdleTimeout: 5 * time.Second, - ExtractCollectdTags: true, }, - r1) + } + + for _, tt := range tests { + t.Run(tt.id.String(), func(t *testing.T) { + factory := NewFactory() + cfg := factory.CreateDefaultConfig() + + sub, err := cm.Sub(tt.id.String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) + + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) + }) + } } diff --git a/receiver/wavefrontreceiver/testdata/config.yaml b/receiver/wavefrontreceiver/testdata/config.yaml index 9f006dd31b67..4eb3ad6ca9de 100644 --- a/receiver/wavefrontreceiver/testdata/config.yaml +++ b/receiver/wavefrontreceiver/testdata/config.yaml @@ -1,25 +1,11 @@ -receivers: - wavefront: - wavefront/allsettings: - # endpoint specifies the network interface and port which will receive - # Wavefront data. - endpoint: localhost:8080 - # tcp_idle_timeout is max duration that a tcp connection will idle wait for - # new data. The default value is 30 seconds. - tcp_idle_timeout: 5s - # extract_collectd_tags instructs the Wavefront receiver to attempt to extract - # tags in the CollectD format from the metric name. The default is false. - extract_collectd_tags: true - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [wavefront, wavefront/allsettings] - processors: [nop] - exporters: [nop] +wavefront: +wavefront/allsettings: + # endpoint specifies the network interface and port which will receive + # Wavefront data. + endpoint: localhost:8080 + # tcp_idle_timeout is max duration that a tcp connection will idle wait for + # new data. The default value is 30 seconds. + tcp_idle_timeout: 5s + # extract_collectd_tags instructs the Wavefront receiver to attempt to extract + # tags in the CollectD format from the metric name. The default is false. + extract_collectd_tags: true diff --git a/receiver/windowsperfcountersreceiver/config_test.go b/receiver/windowsperfcountersreceiver/config_test.go index 6a74b87ea6ca..42f8dd3073e3 100644 --- a/receiver/windowsperfcountersreceiver/config_test.go +++ b/receiver/windowsperfcountersreceiver/config_test.go @@ -22,27 +22,24 @@ 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/confmap/confmaptest" "go.opentelemetry.io/collector/receiver/scraperhelper" - "go.opentelemetry.io/collector/service/servicetest" ) -func TestLoadConfig(t *testing.T) { - factories, err := componenttest.NopFactories() - require.NoError(t, err) +const ( + negativeCollectionIntervalErr = "collection_interval must be a positive duration" + noPerfCountersErr = "must specify at least one perf counter" + noObjectNameErr = "must specify object name for all perf counters" + noCountersErr = `perf counter for object "%s" does not specify any counters` + emptyInstanceErr = `perf counter for object "%s" includes an empty instance` +) - factory := NewFactory() - factories.Receivers[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) +func TestLoadConfig(t *testing.T) { + t.Parallel() + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) - require.NotNil(t, cfg) - - assert.Equal(t, len(cfg.Receivers), 2) - - r0 := cfg.Receivers[config.NewComponentID(typeStr)] - defaultConfigSingleObject := factory.CreateDefaultConfig() counterConfig := CounterConfig{ Name: "counter1", @@ -50,8 +47,9 @@ func TestLoadConfig(t *testing.T) { Name: "metric", }, } - defaultConfigSingleObject.(*Config).PerfCounters = []ObjectConfig{{Object: "object", Counters: []CounterConfig{counterConfig}}} - defaultConfigSingleObject.(*Config).MetricMetaData = map[string]MetricConfig{ + singleObject := createDefaultConfig() + singleObject.(*Config).PerfCounters = []ObjectConfig{{Object: "object", Counters: []CounterConfig{counterConfig}}} + singleObject.(*Config).MetricMetaData = map[string]MetricConfig{ "metric": { Description: "desc", Unit: "1", @@ -59,58 +57,61 @@ func TestLoadConfig(t *testing.T) { }, } - assert.Equal(t, defaultConfigSingleObject, r0) - - counterConfig2 := CounterConfig{ - Name: "counter2", - MetricRep: MetricRep{ - Name: "metric2", - }, - } - - r1 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "customname")].(*Config) - expectedConfig := &Config{ - ScraperControllerSettings: scraperhelper.ScraperControllerSettings{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "customname")), - CollectionInterval: 30 * time.Second, - }, - PerfCounters: []ObjectConfig{ - { - Object: "object1", - Counters: []CounterConfig{counterConfig}, - }, - { - Object: "object2", - Counters: []CounterConfig{counterConfig, counterConfig2}, - }, + tests := []struct { + id config.ComponentID + expected config.Receiver + expectedErr string + }{ + { + id: config.NewComponentIDWithName(typeStr, ""), + expected: singleObject, }, - MetricMetaData: map[string]MetricConfig{ - "metric": { - Description: "desc", - Unit: "1", - Gauge: GaugeMetric{}, - }, - "metric2": { - Description: "desc", - Unit: "1", - Gauge: GaugeMetric{}, + { + id: config.NewComponentIDWithName(typeStr, "customname"), + expected: &Config{ + ScraperControllerSettings: scraperhelper.ScraperControllerSettings{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + CollectionInterval: 30 * time.Second, + }, + PerfCounters: []ObjectConfig{ + { + Object: "object1", + Counters: []CounterConfig{counterConfig}, + }, + { + Object: "object2", + Counters: []CounterConfig{ + counterConfig, + { + Name: "counter2", + MetricRep: MetricRep{ + Name: "metric2", + }, + }, + }, + }, + }, + MetricMetaData: map[string]MetricConfig{ + "metric": { + Description: "desc", + Unit: "1", + Gauge: GaugeMetric{}, + }, + "metric2": { + Description: "desc", + Unit: "1", + Gauge: GaugeMetric{}, + }, + }, }, }, - } - - assert.Equal(t, expectedConfig, r1) -} - -func TestLoadConfigMetrics(t *testing.T) { - testCases := []struct { - TestName string - TestPath string - Expected Config - }{ { - TestName: "NoMetricsDefined", - TestPath: filepath.Join("testdata", "config-nometrics.yaml"), - Expected: Config{ + id: config.NewComponentIDWithName(typeStr, "nometrics"), + expected: &Config{ + ScraperControllerSettings: scraperhelper.ScraperControllerSettings{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + CollectionInterval: 60 * time.Second, + }, PerfCounters: []ObjectConfig{ { Object: "object", @@ -120,9 +121,12 @@ func TestLoadConfigMetrics(t *testing.T) { }, }, { - TestName: "NoMetricSpecified", - TestPath: filepath.Join("testdata", "config-nometricspecified.yaml"), - Expected: Config{ + id: config.NewComponentIDWithName(typeStr, "nometricspecified"), + expected: &Config{ + ScraperControllerSettings: scraperhelper.ScraperControllerSettings{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + CollectionInterval: 60 * time.Second, + }, PerfCounters: []ObjectConfig{ { Object: "object", @@ -139,9 +143,12 @@ func TestLoadConfigMetrics(t *testing.T) { }, }, { - TestName: "SumMetric", - TestPath: filepath.Join("testdata", "config-summetric.yaml"), - Expected: Config{ + id: config.NewComponentIDWithName(typeStr, "summetric"), + expected: &Config{ + ScraperControllerSettings: scraperhelper.ScraperControllerSettings{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + CollectionInterval: 60 * time.Second, + }, PerfCounters: []ObjectConfig{ { Object: "object", @@ -161,9 +168,12 @@ func TestLoadConfigMetrics(t *testing.T) { }, }, { - TestName: "MetricUnspecifiedType", - TestPath: filepath.Join("testdata", "config-unspecifiedmetrictype.yaml"), - Expected: Config{ + id: config.NewComponentIDWithName(typeStr, "unspecifiedmetrictype"), + expected: &Config{ + ScraperControllerSettings: scraperhelper.ScraperControllerSettings{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + CollectionInterval: 60 * time.Second, + }, PerfCounters: []ObjectConfig{ { Object: "object", @@ -179,97 +189,53 @@ func TestLoadConfigMetrics(t *testing.T) { }, }, }, - } - for _, test := range testCases { - t.Run(test.TestName, func(t *testing.T) { - factories, err := componenttest.NopFactories() - require.NoError(t, err) - - factory := NewFactory() - factories.Receivers[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(test.TestPath, factories) - - require.NoError(t, err) - require.NotNil(t, cfg) - - assert.Equal(t, len(cfg.Receivers), 1) - - actualReceiver := cfg.Receivers[config.NewComponentID(typeStr)] - expectedReceiver := factory.CreateDefaultConfig() - expectedReceiver.(*Config).PerfCounters = test.Expected.PerfCounters - expectedReceiver.(*Config).MetricMetaData = test.Expected.MetricMetaData - - assert.Equal(t, expectedReceiver, actualReceiver) - }) - } -} - -func TestLoadConfig_Error(t *testing.T) { - type testCase struct { - name string - cfgFile string - expectedErr string - } - - const ( - errorPrefix = "receiver \"windowsperfcounters\" has invalid configuration" - negativeCollectionIntervalErr = "collection_interval must be a positive duration" - noPerfCountersErr = "must specify at least one perf counter" - noObjectNameErr = "must specify object name for all perf counters" - noCountersErr = `perf counter for object "%s" does not specify any counters` - emptyInstanceErr = `perf counter for object "%s" includes an empty instance` - ) - - testCases := []testCase{ - { - name: "NegativeCollectionInterval", - cfgFile: "config-negative-collection-interval.yaml", - expectedErr: fmt.Sprintf("%s: %s", errorPrefix, negativeCollectionIntervalErr), - }, { - name: "NoPerfCounters", - cfgFile: "config-noperfcounters.yaml", - expectedErr: fmt.Sprintf("%s: %s", errorPrefix, noPerfCountersErr), + id: config.NewComponentIDWithName(typeStr, "negative-collection-interval"), + expectedErr: negativeCollectionIntervalErr, }, { - name: "NoObjectName", - cfgFile: "config-noobjectname.yaml", - expectedErr: fmt.Sprintf("%s: %s", errorPrefix, noObjectNameErr), + id: config.NewComponentIDWithName(typeStr, "noperfcounters"), + expectedErr: noPerfCountersErr, }, { - name: "NoCounters", - cfgFile: "config-nocounters.yaml", - expectedErr: fmt.Sprintf("%s: %s", errorPrefix, fmt.Sprintf(noCountersErr, "object")), + id: config.NewComponentIDWithName(typeStr, "noobjectname"), + expectedErr: noObjectNameErr, }, { - name: "EmptyInstance", - cfgFile: "config-emptyinstance.yaml", - expectedErr: fmt.Sprintf("%s: %s", errorPrefix, fmt.Sprintf(emptyInstanceErr, "object")), + id: config.NewComponentIDWithName(typeStr, "nocounters"), + expectedErr: fmt.Sprintf(noCountersErr, "object"), }, { - name: "AllErrors", - cfgFile: "config-allerrors.yaml", + id: config.NewComponentIDWithName(typeStr, "allerrors"), expectedErr: fmt.Sprintf( - "%s: %s; %s; %s; %s", - errorPrefix, + "%s; %s; %s; %s", negativeCollectionIntervalErr, fmt.Sprintf(noCountersErr, "object"), fmt.Sprintf(emptyInstanceErr, "object"), noObjectNameErr, ), }, + { + id: config.NewComponentIDWithName(typeStr, "emptyinstance"), + expectedErr: fmt.Sprintf(emptyInstanceErr, "object"), + }, } - for _, test := range testCases { - t.Run(test.name, func(t *testing.T) { - factories, err := componenttest.NopFactories() - require.NoError(t, err) - + for _, tt := range tests { + t.Run(tt.id.String(), func(t *testing.T) { factory := NewFactory() - factories.Receivers[typeStr] = factory - _, err = servicetest.LoadConfigAndValidate(filepath.Join("testdata", test.cfgFile), factories) + cfg := factory.CreateDefaultConfig() - require.EqualError(t, err, test.expectedErr) + sub, err := cm.Sub(tt.id.String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) + + if tt.expectedErr != "" { + assert.Equal(t, cfg.Validate().Error(), tt.expectedErr) + return + } + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) }) } } diff --git a/receiver/windowsperfcountersreceiver/testdata/config-allerrors.yaml b/receiver/windowsperfcountersreceiver/testdata/config-allerrors.yaml deleted file mode 100644 index 6158070d9515..000000000000 --- a/receiver/windowsperfcountersreceiver/testdata/config-allerrors.yaml +++ /dev/null @@ -1,20 +0,0 @@ -receivers: - windowsperfcounters: - collection_interval: -1m - perfcounters: - - - - object: "object" - instances: [ "instance", "", "*" ] - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [windowsperfcounters] - processors: [nop] - exporters: [nop] diff --git a/receiver/windowsperfcountersreceiver/testdata/config-emptyinstance.yaml b/receiver/windowsperfcountersreceiver/testdata/config-emptyinstance.yaml deleted file mode 100644 index 5a8b2091dc67..000000000000 --- a/receiver/windowsperfcountersreceiver/testdata/config-emptyinstance.yaml +++ /dev/null @@ -1,26 +0,0 @@ -receivers: - windowsperfcounters: - metrics: - metric: - description: desc - unit: "1" - gauge: - perfcounters: - - object: "object" - instances: [""] - counters: - - name: counter - metric: metric - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [windowsperfcounters] - processors: [nop] - exporters: [nop] diff --git a/receiver/windowsperfcountersreceiver/testdata/config-negative-collection-interval.yaml b/receiver/windowsperfcountersreceiver/testdata/config-negative-collection-interval.yaml deleted file mode 100644 index 83a5c9d25a64..000000000000 --- a/receiver/windowsperfcountersreceiver/testdata/config-negative-collection-interval.yaml +++ /dev/null @@ -1,26 +0,0 @@ -receivers: - windowsperfcounters: - metrics: - metric: - description: desc - unit: "1" - gauge: - collection_interval: -1m - perfcounters: - - object: "object" - counters: - - name: counter1 - metric: metric - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [windowsperfcounters] - processors: [nop] - exporters: [nop] diff --git a/receiver/windowsperfcountersreceiver/testdata/config-nocounters.yaml b/receiver/windowsperfcountersreceiver/testdata/config-nocounters.yaml deleted file mode 100644 index 7781bb162af0..000000000000 --- a/receiver/windowsperfcountersreceiver/testdata/config-nocounters.yaml +++ /dev/null @@ -1,22 +0,0 @@ -receivers: - windowsperfcounters: - metrics: - metric: - description: desc - unit: "1" - gauge: - perfcounters: - - object: "object" - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [windowsperfcounters] - processors: [nop] - exporters: [nop] diff --git a/receiver/windowsperfcountersreceiver/testdata/config-nometrics.yaml b/receiver/windowsperfcountersreceiver/testdata/config-nometrics.yaml deleted file mode 100644 index efa3251595b5..000000000000 --- a/receiver/windowsperfcountersreceiver/testdata/config-nometrics.yaml +++ /dev/null @@ -1,19 +0,0 @@ -receivers: - windowsperfcounters: - perfcounters: - - object: "object" - counters: - - name: counter1 - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [windowsperfcounters] - processors: [nop] - exporters: [nop] diff --git a/receiver/windowsperfcountersreceiver/testdata/config-nometricspecified.yaml b/receiver/windowsperfcountersreceiver/testdata/config-nometricspecified.yaml deleted file mode 100644 index 8277abe96d46..000000000000 --- a/receiver/windowsperfcountersreceiver/testdata/config-nometricspecified.yaml +++ /dev/null @@ -1,24 +0,0 @@ -receivers: - windowsperfcounters: - metrics: - metric: - description: desc - unit: "1" - gauge: - perfcounters: - - object: "object" - counters: - - name: counter1 - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [windowsperfcounters] - processors: [nop] - exporters: [nop] diff --git a/receiver/windowsperfcountersreceiver/testdata/config-noobjectname.yaml b/receiver/windowsperfcountersreceiver/testdata/config-noobjectname.yaml deleted file mode 100644 index ad2d27ed10c7..000000000000 --- a/receiver/windowsperfcountersreceiver/testdata/config-noobjectname.yaml +++ /dev/null @@ -1,24 +0,0 @@ -receivers: - windowsperfcounters: - metrics: - metric: - description: desc - unit: "1" - gauge: - perfcounters: - - counters: - - - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [windowsperfcounters] - processors: [nop] - exporters: [nop] diff --git a/receiver/windowsperfcountersreceiver/testdata/config-noperfcounters.yaml b/receiver/windowsperfcountersreceiver/testdata/config-noperfcounters.yaml deleted file mode 100644 index 03d5d4eb3382..000000000000 --- a/receiver/windowsperfcountersreceiver/testdata/config-noperfcounters.yaml +++ /dev/null @@ -1,19 +0,0 @@ -receivers: - windowsperfcounters: - metrics: - metric: - description: desc - unit: "1" - gauge: -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [windowsperfcounters] - processors: [nop] - exporters: [nop] diff --git a/receiver/windowsperfcountersreceiver/testdata/config-summetric.yaml b/receiver/windowsperfcountersreceiver/testdata/config-summetric.yaml deleted file mode 100644 index 0efdf4af1ebe..000000000000 --- a/receiver/windowsperfcountersreceiver/testdata/config-summetric.yaml +++ /dev/null @@ -1,26 +0,0 @@ -receivers: - windowsperfcounters: - metrics: - metric: - description: desc - unit: "1" - sum: - aggregation: cumulative - perfcounters: - - object: "object" - counters: - - name: counter1 - metric: metric - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [windowsperfcounters] - processors: [nop] - exporters: [nop] diff --git a/receiver/windowsperfcountersreceiver/testdata/config-unspecifiedmetrictype.yaml b/receiver/windowsperfcountersreceiver/testdata/config-unspecifiedmetrictype.yaml deleted file mode 100644 index 831b395dc24a..000000000000 --- a/receiver/windowsperfcountersreceiver/testdata/config-unspecifiedmetrictype.yaml +++ /dev/null @@ -1,24 +0,0 @@ -receivers: - windowsperfcounters: - metrics: - metric: - description: desc - unit: "1" - perfcounters: - - object: "object" - counters: - - name: counter1 - metric: metric - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [windowsperfcounters] - processors: [nop] - exporters: [nop] diff --git a/receiver/windowsperfcountersreceiver/testdata/config.yaml b/receiver/windowsperfcountersreceiver/testdata/config.yaml index 41660cebd152..d6a834f11e3f 100644 --- a/receiver/windowsperfcountersreceiver/testdata/config.yaml +++ b/receiver/windowsperfcountersreceiver/testdata/config.yaml @@ -1,47 +1,133 @@ -receivers: - windowsperfcounters: - metrics: - metric: - description: desc - unit: "1" - gauge: - perfcounters: - - object: "object" - counters: - - name: counter1 - metric: metric - windowsperfcounters/customname: - metrics: - metric: - description: desc - unit: "1" - gauge: - metric2: - description: desc - unit: "1" - gauge: - collection_interval: 30s - perfcounters: - - object: object1 - counters: - - name: counter1 - metric: metric - - object: object2 - counters: - - name: counter1 - metric: metric - - name: counter2 - metric: metric2 - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - metrics: - receivers: [windowsperfcounters] - processors: [nop] - exporters: [nop] +windowsperfcounters: + metrics: + metric: + description: desc + unit: "1" + gauge: + perfcounters: + - object: "object" + counters: + - name: counter1 + metric: metric + +windowsperfcounters/customname: + metrics: + metric: + description: desc + unit: "1" + gauge: + metric2: + description: desc + unit: "1" + gauge: + collection_interval: 30s + perfcounters: + - object: object1 + counters: + - name: counter1 + metric: metric + - object: object2 + counters: + - name: counter1 + metric: metric + - name: counter2 + metric: metric2 + +windowsperfcounters/nometricspecified: + metrics: + metric: + description: desc + unit: "1" + gauge: + perfcounters: + - object: "object" + counters: + - name: counter1 + +windowsperfcounters/unspecifiedmetrictype: + metrics: + metric: + description: desc + unit: "1" + perfcounters: + - object: "object" + counters: + - name: counter1 + metric: metric + +windowsperfcounters/summetric: + metrics: + metric: + description: desc + unit: "1" + sum: + aggregation: cumulative + perfcounters: + - object: "object" + counters: + - name: counter1 + metric: metric + +windowsperfcounters/nometrics: + perfcounters: + - object: "object" + counters: + - name: counter1 + +windowsperfcounters/allerrors: + collection_interval: -1m + perfcounters: + - + - object: "object" + instances: [ "instance", "", "*" ] + +windowsperfcounters/emptyinstance: + metrics: + metric: + description: desc + unit: "1" + gauge: + perfcounters: + - object: "object" + instances: [ "" ] + counters: + - name: counter + metric: metric + +windowsperfcounters/negative-collection-interval: + metrics: + metric: + description: desc + unit: "1" + gauge: + collection_interval: -1m + perfcounters: + - object: "object" + counters: + - name: counter1 + metric: metric + +windowsperfcounters/nocounters: + metrics: + metric: + description: desc + unit: "1" + gauge: + perfcounters: + - object: "object" + +windowsperfcounters/noobjectname: + metrics: + metric: + description: desc + unit: "1" + gauge: + perfcounters: + - counters: + +windowsperfcounters/noperfcounters: + metrics: + metric: + description: desc + unit: "1" + gauge: diff --git a/receiver/zipkinreceiver/config_test.go b/receiver/zipkinreceiver/config_test.go index 36371594c940..68fbe4ff40b2 100644 --- a/receiver/zipkinreceiver/config_test.go +++ b/receiver/zipkinreceiver/config_test.go @@ -20,44 +20,58 @@ 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/config/confighttp" - "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) - - factory := NewFactory() - factories.Receivers[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) + t.Parallel() + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) - require.NotNil(t, cfg) - assert.Equal(t, len(cfg.Receivers), 3) + tests := []struct { + id config.ComponentID + expected config.Receiver + }{ + { + id: config.NewComponentID(typeStr), + expected: createDefaultConfig(), + }, + { + id: config.NewComponentIDWithName(typeStr, "customname"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + HTTPServerSettings: confighttp.HTTPServerSettings{ + Endpoint: "localhost:8765", + }, + ParseStringTags: false, + }, + }, + { + id: config.NewComponentIDWithName(typeStr, "parse_strings"), + expected: &Config{ + ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)), + HTTPServerSettings: confighttp.HTTPServerSettings{ + Endpoint: defaultBindEndpoint, + }, + ParseStringTags: true, + }, + }, + } - r0 := cfg.Receivers[config.NewComponentID(typeStr)] - assert.Equal(t, r0, factory.CreateDefaultConfig()) + for _, tt := range tests { + t.Run(tt.id.String(), func(t *testing.T) { + factory := NewFactory() + cfg := factory.CreateDefaultConfig() - r1 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "customname")].(*Config) - assert.Equal(t, r1, - &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "customname")), - HTTPServerSettings: confighttp.HTTPServerSettings{ - Endpoint: "localhost:8765", - }, - }) + sub, err := cm.Sub(tt.id.String()) + require.NoError(t, err) + require.NoError(t, config.UnmarshalReceiver(sub, cfg)) - r2 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "parse_strings")].(*Config) - assert.Equal(t, r2, - &Config{ - ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "parse_strings")), - HTTPServerSettings: confighttp.HTTPServerSettings{ - Endpoint: "0.0.0.0:9411", - }, - ParseStringTags: true, + assert.NoError(t, cfg.Validate()) + assert.Equal(t, tt.expected, cfg) }) + } } diff --git a/receiver/zipkinreceiver/testdata/config.yaml b/receiver/zipkinreceiver/testdata/config.yaml index 437ca11a8c49..f0ccdc3c65ae 100644 --- a/receiver/zipkinreceiver/testdata/config.yaml +++ b/receiver/zipkinreceiver/testdata/config.yaml @@ -1,20 +1,5 @@ -receivers: - zipkin: - zipkin/customname: - endpoint: "localhost:8765" - zipkin/parse_strings: - parse_string_tags: true - -processors: - nop: - -exporters: - nop: - -service: - pipelines: - traces: - receivers: [zipkin] - processors: [nop] - exporters: [nop] - +zipkin: +zipkin/customname: + endpoint: "localhost:8765" +zipkin/parse_strings: + parse_string_tags: true