Skip to content

Commit

Permalink
[internal/components] Add all receivers to lifecycle tests (#6974)
Browse files Browse the repository at this point in the history
* Adding in existing receivers into the test suite

* Making the receivers testable

* Disabling windows test

* Fixing windows tests
  • Loading branch information
MovieStoreGuy authored Jan 3, 2022
1 parent f28b47e commit 3dfb709
Showing 1 changed file with 147 additions and 2 deletions.
149 changes: 147 additions & 2 deletions internal/components/receivers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package components
import (
"context"
"errors"
"path"
"runtime"
"testing"

promconfig "github.com/prometheus/prometheus/config"
Expand All @@ -28,7 +30,14 @@ import (
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer/consumertest"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/stanza"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/syslogreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/tcplogreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/udplogreceiver"
)

func TestDefaultReceivers(t *testing.T) {
Expand All @@ -47,16 +56,87 @@ func TestDefaultReceivers(t *testing.T) {
// TODO: skipped since it will only function in a container environment with procfs in expected location.
skipLifecyle: true,
},
{
receiver: "awsecscontainermetrics",
skipLifecyle: true, // Requires container metaendpoint to be running
},
{
receiver: "awsxray",
skipLifecyle: true, // Requires AWS endpoint to check identity to run
},
{
receiver: "carbon",
getConfigFn: func() config.Receiver {
cfg := rcvrFactories["carbon"].CreateDefaultConfig().(*carbonreceiver.Config)
cfg.Endpoint = "0.0.0.0:0"
return cfg
},
skipLifecyle: true, // Panics after test have completed, requires a wait group
},
{
receiver: "collectd",
},
{
receiver: "docker_stats",
skipLifecyle: runtime.GOOS == "windows", // Unable to start docker client on windows
},
{
receiver: "dotnet_diagnostics",
skipLifecyle: true, // Requires a running .NET process to examine
},
{
receiver: "filelog",
getConfigFn: func() config.Receiver {
cfg := rcvrFactories["filelog"].CreateDefaultConfig().(*filelogreceiver.FileLogConfig)
cfg.Input = stanza.InputConfig{
"include": []string{
path.Join(testutil.NewTemporaryDirectory(t), "*"),
},
}
return cfg
},
},
{
receiver: "fluentforward",
},
{
receiver: "googlecloudspanner",
},
{
receiver: "hostmetrics",
},
{
receiver: "influxdb",
},
{
receiver: "jaeger",
},
{
receiver: "jmx",
skipLifecyle: true, // Requires a running instance with JMX
},
{
receiver: "journald",
skipLifecyle: runtime.GOOS != "linux",
},
{
receiver: "kafka",
skipLifecyle: true, // TODO: It needs access to internals to successful start.
},
{
receiver: "kafkametrics",
},
{
receiver: "k8s_cluster",
skipLifecyle: true, // Requires access to the k8s host and port in order to run
},
{
receiver: "kubeletstats",
skipLifecyle: true, // Requires access to certificates to auth against kubelet
},
{
receiver: "memcached",
},
{
receiver: "mongodbatlas",
},
Expand All @@ -67,6 +147,10 @@ func TestDefaultReceivers(t *testing.T) {
{
receiver: "otlp",
},
{
receiver: "podman_stats",
skipLifecyle: true, // Requires a running podman daemon
},
{
receiver: "prometheus",
getConfigFn: func() config.Receiver {
Expand All @@ -79,21 +163,82 @@ func TestDefaultReceivers(t *testing.T) {
return cfg
},
},
{
receiver: "prometheus_exec",
skipLifecyle: true, // Requires running a subproccess that can not be easily set across platforms
},
{
receiver: "receiver_creator",
},
{
receiver: "redis",
},
{
receiver: "sapm",
},
{
receiver: "signalfx",
},
{
receiver: "prometheus_simple",
},
{
receiver: "splunk_hec",
},
{
receiver: "statsd",
},
{
receiver: "wavefront",
skipLifecyle: true, // Depends on carbon receiver to be running correctly
},
{
receiver: "windowsperfcounters",
skipLifecyle: true, // Requires a running windows process
},
{
receiver: "zipkin",
},
{
receiver: "zookeeper",
skipLifecyle: true, // Panics due to nil pointer on shutdown with the default configuration
},
{
receiver: "syslog",
getConfigFn: func() config.Receiver {
cfg := rcvrFactories["syslog"].CreateDefaultConfig().(*syslogreceiver.SysLogConfig)
cfg.Input = stanza.InputConfig{
"tcp": map[string]interface{}{
"listen_address": "0.0.0.0:0",
},
"protocol": "rfc5424",
}
return cfg
},
},
{
receiver: "tcplog",
getConfigFn: func() config.Receiver {
cfg := rcvrFactories["tcplog"].CreateDefaultConfig().(*tcplogreceiver.TCPLogConfig)
cfg.Input = stanza.InputConfig{
"listen_address": "0.0.0.0:0",
}
return cfg
},
},
{
receiver: "udplog",
getConfigFn: func() config.Receiver {
cfg := rcvrFactories["udplog"].CreateDefaultConfig().(*udplogreceiver.UDPLogConfig)
cfg.Input = stanza.InputConfig{
"listen_address": "0.0.0.0:0",
}
return cfg
},
},
}

assert.Equal(t, len(tests)+28 /* not tested */, len(rcvrFactories))
assert.Len(t, tests, len(rcvrFactories), "All receivers must be added to the lifecycle suite")
for _, tt := range tests {
t.Run(string(tt.receiver), func(t *testing.T) {
factory, ok := rcvrFactories[tt.receiver]
Expand All @@ -102,7 +247,7 @@ func TestDefaultReceivers(t *testing.T) {
assert.Equal(t, config.NewComponentID(tt.receiver), factory.CreateDefaultConfig().ID())

if tt.skipLifecyle {
t.Log("Skipping lifecycle test", tt.receiver)
t.Skip("Skipping lifecycle test", tt.receiver)
return
}

Expand Down

0 comments on commit 3dfb709

Please sign in to comment.