Skip to content

Commit

Permalink
Move oracledb discovery test to checking metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Jan 15, 2025
1 parent eb468ee commit 031b581
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 88 deletions.
108 changes: 83 additions & 25 deletions tests/receivers/oracledb/bundled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ package tests

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
"time"

"github.com/stretchr/testify/require"

Expand All @@ -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)

}
63 changes: 0 additions & 63 deletions tests/receivers/oracledb/testdata/resource_metrics/bundled.yaml

This file was deleted.

0 comments on commit 031b581

Please sign in to comment.