Skip to content

Commit

Permalink
[chore] Change receiver config tests to unmarshal config only for tha…
Browse files Browse the repository at this point in the history
…t component. (part4)

- [x] pulsarreceiver
- [x] rabbitmqreceiver
- [x] redisreceiver
- [x] riakreceiver
- [x] saphanareceiver
- [x] sapmreceiver
- [x] signalfxreceiver
- [x] simpleprometheusreceiver
- [x] skywalkingreceiver
- [x] solacereceiver
  • Loading branch information
kovrus committed Sep 28, 2022
1 parent 575c72b commit d7a6128
Show file tree
Hide file tree
Showing 32 changed files with 725 additions and 906 deletions.
26 changes: 6 additions & 20 deletions receiver/mongodbreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
receivers:
mongodb:
hosts:
- endpoint: localhost:27017
username: otel
password: $MONGO_PASSWORD
collection_interval: 60s

processors:
nop:

exporters:
nop:

service:
pipelines:
metrics:
receivers: [mongodb]
processors: [nop]
exporters: [nop]
mongodb:
hosts:
- endpoint: localhost:27017
username: otel
password: $MONGO_PASSWORD
collection_interval: 60s
26 changes: 6 additions & 20 deletions receiver/mysqlreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
receivers:
mysql:
endpoint: localhost:3306
username: otel
password: $MYSQL_PASSWORD
database: otel
collection_interval: 10s

processors:
nop:

exporters:
nop:

service:
pipelines:
metrics:
receivers: [mysql]
processors: [nop]
exporters: [nop]
mysql:
endpoint: localhost:3306
username: otel
password: $MYSQL_PASSWORD
database: otel
collection_interval: 10s
20 changes: 9 additions & 11 deletions receiver/nginxreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,21 @@ 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"
)

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(config.NewComponentIDWithName(typeStr, "").String())
require.NoError(t, err)
require.NoError(t, config.UnmarshalReceiver(sub, cfg))

require.Equal(t, factory.CreateDefaultConfig(), cfg.Receivers[config.NewComponentID("nginx")])
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
}
20 changes: 3 additions & 17 deletions receiver/nginxreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
receivers:
nginx:
endpoint: "http://localhost:80/status"
collection_interval: 10s

processors:
nop:

exporters:
nop:

service:
pipelines:
metrics:
receivers: [nginx]
processors: [nop]
exporters: [nop]
nginx:
endpoint: "http://localhost:80/status"
collection_interval: 10s
26 changes: 7 additions & 19 deletions receiver/nsxtreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
### Metrics
receivers:
nsxt:
collection_interval: 1m
endpoint: https://nsx-manager-endpoint
username: admin
password: password123
tls:
insecure: true

exporters:
file:
path: "./content.json"

service:
pipelines:
metrics:
receivers: [nsx]
exporters: [file]
nsxt:
collection_interval: 1m
endpoint: https://nsx-manager-endpoint
username: admin
password: password123
tls:
insecure: true
215 changes: 111 additions & 104 deletions receiver/opencensusreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,135 +21,142 @@ 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/configgrpc"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/config/configtls"
"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), 7)

r0 := cfg.Receivers[config.NewComponentID(typeStr)]
assert.Equal(t, r0, factory.CreateDefaultConfig())

r1 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "customname")].(*Config)
assert.Equal(t, r1,
&Config{
ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "customname")),
GRPCServerSettings: configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "0.0.0.0:9090",
Transport: "tcp",
tests := []struct {
id config.ComponentID
expected config.Receiver
}{
{
id: config.NewComponentIDWithName(typeStr, "customname"),
expected: &Config{
ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)),
GRPCServerSettings: configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "0.0.0.0:9090",
Transport: "tcp",
},
ReadBufferSize: 512 * 1024,
},
ReadBufferSize: 512 * 1024,
},
})

r2 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "keepalive")].(*Config)
assert.Equal(t, r2,
&Config{
ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "keepalive")),
GRPCServerSettings: configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "0.0.0.0:55678",
Transport: "tcp",
},
ReadBufferSize: 512 * 1024,
Keepalive: &configgrpc.KeepaliveServerConfig{
ServerParameters: &configgrpc.KeepaliveServerParameters{
MaxConnectionIdle: 11 * time.Second,
MaxConnectionAge: 12 * time.Second,
MaxConnectionAgeGrace: 13 * time.Second,
Time: 30 * time.Second,
Timeout: 5 * time.Second,
},
{
id: config.NewComponentIDWithName(typeStr, "keepalive"),
expected: &Config{
ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)),
GRPCServerSettings: configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "0.0.0.0:55678",
Transport: "tcp",
},
EnforcementPolicy: &configgrpc.KeepaliveEnforcementPolicy{
MinTime: 10 * time.Second,
PermitWithoutStream: true,
ReadBufferSize: 512 * 1024,
Keepalive: &configgrpc.KeepaliveServerConfig{
ServerParameters: &configgrpc.KeepaliveServerParameters{
MaxConnectionIdle: 11 * time.Second,
MaxConnectionAge: 12 * time.Second,
MaxConnectionAgeGrace: 13 * time.Second,
Time: 30 * time.Second,
Timeout: 5 * time.Second,
},
EnforcementPolicy: &configgrpc.KeepaliveEnforcementPolicy{
MinTime: 10 * time.Second,
PermitWithoutStream: true,
},
},
},
},
})

r3 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "msg-size-conc-connect-max-idle")].(*Config)
assert.Equal(t, r3,
&Config{
ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "msg-size-conc-connect-max-idle")),
GRPCServerSettings: configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "0.0.0.0:55678",
Transport: "tcp",
},
MaxRecvMsgSizeMiB: 32,
MaxConcurrentStreams: 16,
ReadBufferSize: 1024,
WriteBufferSize: 1024,
Keepalive: &configgrpc.KeepaliveServerConfig{
ServerParameters: &configgrpc.KeepaliveServerParameters{
MaxConnectionIdle: 10 * time.Second,
},
{
id: config.NewComponentIDWithName(typeStr, "msg-size-conc-connect-max-idle"),
expected: &Config{
ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)),
GRPCServerSettings: configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "0.0.0.0:55678",
Transport: "tcp",
},
MaxRecvMsgSizeMiB: 32,
MaxConcurrentStreams: 16,
ReadBufferSize: 1024,
WriteBufferSize: 1024,
Keepalive: &configgrpc.KeepaliveServerConfig{
ServerParameters: &configgrpc.KeepaliveServerParameters{
MaxConnectionIdle: 10 * time.Second,
},
},
},
},
})

// TODO(ccaraman): Once the config loader checks for the files existence, this test may fail and require
// use of fake cert/key for test purposes.
r4 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "tlscredentials")].(*Config)
assert.Equal(t, r4,
&Config{
ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "tlscredentials")),
GRPCServerSettings: configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "0.0.0.0:55678",
Transport: "tcp",
},
ReadBufferSize: 512 * 1024,
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
CertFile: "test.crt",
KeyFile: "test.key",
},
{
id: config.NewComponentIDWithName(typeStr, "tlscredentials"),
expected: &Config{
ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)),
GRPCServerSettings: configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "0.0.0.0:55678",
Transport: "tcp",
},
ReadBufferSize: 512 * 1024,
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
CertFile: "test.crt",
KeyFile: "test.key",
},
},
},
},
})

r5 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "cors")].(*Config)
assert.Equal(t, r5,
&Config{
ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "cors")),
GRPCServerSettings: configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "0.0.0.0:55678",
Transport: "tcp",
},
{
id: config.NewComponentIDWithName(typeStr, "cors"),
expected: &Config{
ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)),
GRPCServerSettings: configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "0.0.0.0:55678",
Transport: "tcp",
},
ReadBufferSize: 512 * 1024,
},
ReadBufferSize: 512 * 1024,
CorsOrigins: []string{"https://*.test.com", "https://test.com"},
},
CorsOrigins: []string{"https://*.test.com", "https://test.com"},
})

r6 := cfg.Receivers[config.NewComponentIDWithName(typeStr, "uds")].(*Config)
assert.Equal(t, r6,
&Config{
ReceiverSettings: config.NewReceiverSettings(config.NewComponentIDWithName(typeStr, "uds")),
GRPCServerSettings: configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "/tmp/opencensus.sock",
Transport: "unix",
},
{
id: config.NewComponentIDWithName(typeStr, "uds"),
expected: &Config{
ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)),
GRPCServerSettings: configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "/tmp/opencensus.sock",
Transport: "unix",
},
ReadBufferSize: 512 * 1024,
},
ReadBufferSize: 512 * 1024,
},
},
}

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)
})
}
}
Loading

0 comments on commit d7a6128

Please sign in to comment.