diff --git a/tests/general/configproviders/env_test.go b/tests/general/configproviders/env_test.go index f81db89cfc..be527faccb 100644 --- a/tests/general/configproviders/env_test.go +++ b/tests/general/configproviders/env_test.go @@ -17,7 +17,11 @@ package tests import ( + "fmt" "testing" + "time" + + "github.com/stretchr/testify/assert" "github.com/signalfx/splunk-otel-collector/tests/testutils" ) @@ -41,14 +45,38 @@ service: receivers: [hostmetrics] exporters: [otlp] ` - testutils.AssertAllMetricsReceived( - t, "memory.yaml", "", nil, - []testutils.CollectorBuilder{ - func(collector testutils.Collector) testutils.Collector { - return collector.WithEnv( - map[string]string{"SOME_ENV_VAR": config}, - ).WithArgs("--config", "env:SOME_ENV_VAR") - }, - }, - ) + tc := testutils.NewTestcase(t) + defer tc.PrintLogsOnFailure() + defer tc.ShutdownOTLPReceiverSink() + + _, shutdown := tc.SplunkOtelCollector("", func(collector testutils.Collector) testutils.Collector { + return collector.WithEnv( + map[string]string{"SOME_ENV_VAR": config}, + ).WithArgs("--config", "env:SOME_ENV_VAR") + }) + defer shutdown() + + missingMetrics := map[string]struct{}{ + "system.memory.usage": {}, + } + + assert.EventuallyWithT(t, func(tt *assert.CollectT) { + for i := 0; i < len(tc.OTLPReceiverSink.AllMetrics()); i++ { + m := tc.OTLPReceiverSink.AllMetrics()[i] + for j := 0; j < m.ResourceMetrics().Len(); j++ { + rm := m.ResourceMetrics().At(j) + for k := 0; k < rm.ScopeMetrics().Len(); k++ { + sm := rm.ScopeMetrics().At(k) + for l := 0; l < sm.Metrics().Len(); l++ { + delete(missingMetrics, sm.Metrics().At(l).Name()) + } + } + } + } + msg := "Missing metrics:\n" + for k := range missingMetrics { + msg += fmt.Sprintf("- %q\n", k) + } + assert.Len(tt, missingMetrics, 0, msg) + }, 30*time.Second, 1*time.Second) } diff --git a/tests/general/configproviders/file_test.go b/tests/general/configproviders/file_test.go index 0836949e05..73801ae0db 100644 --- a/tests/general/configproviders/file_test.go +++ b/tests/general/configproviders/file_test.go @@ -17,28 +17,46 @@ package tests import ( - "path" - "path/filepath" + "fmt" "testing" + "time" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/signalfx/splunk-otel-collector/tests/testutils" ) func TestFileProvider(t *testing.T) { - t.Skip("Issues with test-containers networking, need to wait for -contrib to update the docker api version for us to update testcontainers-go locally") - testdataPath, err := filepath.Abs(path.Join(".", "testdata")) - require.NoError(t, err) - testutils.AssertAllMetricsReceived( - t, "memory.yaml", "", nil, - []testutils.CollectorBuilder{ - func(collector testutils.Collector) testutils.Collector { - if cc, ok := collector.(*testutils.CollectorContainer); ok { - collector = cc.WithMount(testdataPath, "/testdata") + tc := testutils.NewTestcase(t) + defer tc.PrintLogsOnFailure() + defer tc.ShutdownOTLPReceiverSink() + + _, shutdown := tc.SplunkOtelCollectorProcess("", func(collector testutils.Collector) testutils.Collector { + return collector.WithArgs("--config", "file:./testdata/file_config.yaml") + }) + defer shutdown() + + missingMetrics := map[string]struct{}{ + "system.memory.usage": {}, + } + + assert.EventuallyWithT(t, func(tt *assert.CollectT) { + for i := 0; i < len(tc.OTLPReceiverSink.AllMetrics()); i++ { + m := tc.OTLPReceiverSink.AllMetrics()[i] + for j := 0; j < m.ResourceMetrics().Len(); j++ { + rm := m.ResourceMetrics().At(j) + for k := 0; k < rm.ScopeMetrics().Len(); k++ { + sm := rm.ScopeMetrics().At(k) + for l := 0; l < sm.Metrics().Len(); l++ { + delete(missingMetrics, sm.Metrics().At(l).Name()) + } } - return collector.WithArgs("--config", "file:./testdata/file_config.yaml") - }, - }, - ) + } + } + msg := "Missing metrics:\n" + for k := range missingMetrics { + msg += fmt.Sprintf("- %q\n", k) + } + assert.Len(tt, missingMetrics, 0, msg) + }, 30*time.Second, 1*time.Second) } diff --git a/tests/general/configproviders/testdata/resource_metrics/memory.yaml b/tests/general/configproviders/testdata/resource_metrics/memory.yaml deleted file mode 100644 index 4133d027e6..0000000000 --- a/tests/general/configproviders/testdata/resource_metrics/memory.yaml +++ /dev/null @@ -1,8 +0,0 @@ -resource_metrics: - - scope_metrics: - - instrumentation_scope: - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/memoryscraper - version: - metrics: - - name: system.memory.usage - type: IntNonmonotonicCumulativeSum