From 9332091014e8ac99f63877778962b6877ef21a52 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Tue, 14 Jan 2025 21:51:13 -0800 Subject: [PATCH] Move oracledb discovery test to checking metrics --- tests/receivers/oracledb/bundled_test.go | 108 ++++++++++++++---- .../testdata/resource_metrics/bundled.yaml | 63 ---------- 2 files changed, 83 insertions(+), 88 deletions(-) delete mode 100644 tests/receivers/oracledb/testdata/resource_metrics/bundled.yaml diff --git a/tests/receivers/oracledb/bundled_test.go b/tests/receivers/oracledb/bundled_test.go index c429ca1975..71961049de 100644 --- a/tests/receivers/oracledb/bundled_test.go +++ b/tests/receivers/oracledb/bundled_test.go @@ -19,7 +19,9 @@ package tests import ( "fmt" "testing" + "time" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/signalfx/splunk-otel-collector/tests/testutils" @@ -33,29 +35,85 @@ func TestOracledbDockerObserver(t *testing.T) { dockerSocket.Stop() }) - testutils.AssertAllMetricsReceived(t, "bundled.yaml", "otlp_exporter.yaml", - nil, []testutils.CollectorBuilder{ - func(c testutils.Collector) testutils.Collector { - cc := c.(*testutils.CollectorContainer) - cc.Container = cc.Container.WillWaitForLogs("Discovering for next") - return cc - }, - func(collector testutils.Collector) testutils.Collector { - return collector.WithEnv(map[string]string{ - "SPLUNK_DISCOVERY_DURATION": "20s", - // confirm that debug logging doesn't affect runtime - "SPLUNK_DISCOVERY_LOG_LEVEL": "debug", - "ORACLE_PASSWORD": "password", - }).WithArgs( - "--discovery", - "--set", "splunk.discovery.receivers.oracledb.config.username=otel", - "--set", "splunk.discovery.receivers.oracledb.config.password='${ORACLE_PASSWORD}'", - "--set", "splunk.discovery.receivers.oracledb.config.service=XE", - "--set", `splunk.discovery.extensions.k8s_observer.enabled=false`, - "--set", `splunk.discovery.extensions.host_observer.enabled=false`, - "--set", fmt.Sprintf("splunk.discovery.extensions.docker_observer.config.endpoint=tcp://%s", dockerSocket.ContainerEndpoint), - ) - }, - }, - ) + tc := testutils.NewTestcase(t) + defer tc.PrintLogsOnFailure() + defer tc.ShutdownOTLPReceiverSink() + + _, shutdown := tc.SplunkOtelCollectorContainer("otlp_exporter.yaml", func(c testutils.Collector) testutils.Collector { + cc := c.(*testutils.CollectorContainer) + cc.Container = cc.Container.WillWaitForLogs("Discovering for next") + return cc + }, + func(collector testutils.Collector) testutils.Collector { + return collector.WithEnv(map[string]string{ + "SPLUNK_DISCOVERY_DURATION": "20s", + // confirm that debug logging doesn't affect runtime + "SPLUNK_DISCOVERY_LOG_LEVEL": "debug", + "ORACLE_PASSWORD": "password", + }).WithArgs( + "--discovery", + "--set", "splunk.discovery.receivers.oracledb.config.username=otel", + "--set", "splunk.discovery.receivers.oracledb.config.password='${ORACLE_PASSWORD}'", + "--set", "splunk.discovery.receivers.oracledb.config.service=XE", + "--set", `splunk.discovery.extensions.k8s_observer.enabled=false`, + "--set", `splunk.discovery.extensions.host_observer.enabled=false`, + "--set", fmt.Sprintf("splunk.discovery.extensions.docker_observer.config.endpoint=tcp://%s", dockerSocket.ContainerEndpoint), + ) + }) + defer shutdown() + + metricNames := []string{ + "oracledb.cpu_time", + "oracledb.enqueue_deadlocks", + "oracledb.exchange_deadlocks", + "oracledb.executions", + "oracledb.hard_parses", + "oracledb.logical_reads", + "oracledb.parse_calls", + "oracledb.pga_memory", + "oracledb.physical_reads", + "oracledb.user_commits", + "oracledb.user_rollbacks", + "oracledb.sessions.usage", + "oracledb.processes.usage", + "oracledb.processes.limit", + "oracledb.sessions.usage", + "oracledb.sessions.limit", + "oracledb.enqueue_locks.usage", + "oracledb.enqueue_locks.limit", + "oracledb.enqueue_resources.usage", + "oracledb.enqueue_resources.limit", + "oracledb.transactions.usage", + "oracledb.transactions.limit", + "oracledb.dml_locks.usage", + "oracledb.dml_locks.limit", + "oracledb.tablespace_size.limit", + "oracledb.tablespace_size.usage", + } + + missingMetrics := make(map[string]any, len(metricNames)) + for _, m := range metricNames { + missingMetrics[m] = struct{}{} + } + + 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) + }, 1*time.Minute, 1*time.Second) + } diff --git a/tests/receivers/oracledb/testdata/resource_metrics/bundled.yaml b/tests/receivers/oracledb/testdata/resource_metrics/bundled.yaml deleted file mode 100644 index 1375770cc2..0000000000 --- a/tests/receivers/oracledb/testdata/resource_metrics/bundled.yaml +++ /dev/null @@ -1,63 +0,0 @@ -resource_metrics: - - attributes: - container.image.name: - container.name: - oracledb.instance.name: - scope_metrics: - - instrumentation_scope: - attributes: {} - name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/oracledbreceiver - version: - metrics: - - name: oracledb.cpu_time - type: DoubleMonotonicCumulativeSum - - name: oracledb.enqueue_deadlocks - type: IntMonotonicCumulativeSum - - name: oracledb.exchange_deadlocks - type: IntMonotonicCumulativeSum - - name: oracledb.executions - type: IntMonotonicCumulativeSum - - name: oracledb.hard_parses - type: IntMonotonicCumulativeSum - - name: oracledb.logical_reads - type: IntMonotonicCumulativeSum - - name: oracledb.parse_calls - type: IntMonotonicCumulativeSum - - name: oracledb.pga_memory - type: IntMonotonicCumulativeSum - - name: oracledb.physical_reads - type: IntMonotonicCumulativeSum - - name: oracledb.user_commits - type: IntMonotonicCumulativeSum - - name: oracledb.user_rollbacks - type: IntMonotonicCumulativeSum - - name: oracledb.sessions.usage - type: IntGauge - - name: oracledb.processes.usage - type: IntGauge - - name: oracledb.processes.limit - type: IntGauge - - name: oracledb.sessions.usage - type: IntGauge - - name: oracledb.sessions.limit - type: IntGauge - - name: oracledb.enqueue_locks.usage - type: IntGauge - - name: oracledb.enqueue_locks.limit - type: IntGauge - - name: oracledb.enqueue_resources.usage - type: IntGauge - - name: oracledb.enqueue_resources.limit - type: IntGauge - - name: oracledb.transactions.usage - type: IntGauge - - name: oracledb.transactions.limit - type: IntGauge - - name: oracledb.dml_locks.usage - type: IntGauge - - name: oracledb.dml_locks.limit - type: IntGauge - - name: oracledb.tablespace_size.limit - type: IntGauge - - name: oracledb.tablespace_size.usage - type: IntGauge \ No newline at end of file