diff --git a/tests/general/container_test.go b/tests/general/container_test.go index a0046f6ddb..b43836effb 100644 --- a/tests/general/container_test.go +++ b/tests/general/container_test.go @@ -218,27 +218,78 @@ service: // This test also exercises collectd binary usage and managed config writing func TestNonDefaultGIDCanAccessJavaInAgentBundle(t *testing.T) { testutils.SkipIfNotContainerTest(t) - testutils.AssertAllMetricsReceived(t, "activemq.yaml", "activemq_config.yaml", nil, - []testutils.CollectorBuilder{ - func(collector testutils.Collector) testutils.Collector { - cc := collector.(*testutils.CollectorContainer) - cc.Container = cc.Container.WithUser("splunk-otel-collector:234567890") - return collector - }, + tc := testutils.NewTestcase(t) + defer tc.PrintLogsOnFailure() + defer tc.ShutdownOTLPReceiverSink() + + _, shutdown := tc.SplunkOtelCollectorContainer("activemq_config.yaml", + func(c testutils.Collector) testutils.Collector { + cc := c.(*testutils.CollectorContainer) + cc.Container = cc.Container.WithUser("splunk-otel-collector:234567890") + return cc }, ) + defer shutdown() + require.EventuallyWithT(t, func(tt *assert.CollectT) { + if len(tc.OTLPReceiverSink.AllMetrics()) == 0 { + assert.Fail(tt, "No metrics collected") + return + } + + metricsFound := map[string]struct{}{} + for _, m := range tc.OTLPReceiverSink.AllMetrics() { + for i := 0; i < m.ResourceMetrics().Len(); i++ { + rm := m.ResourceMetrics().At(i) + for j := 0; j < rm.ScopeMetrics().Len(); j++ { + sm := rm.ScopeMetrics().At(j) + for k := 0; k < sm.Metrics().Len(); k++ { + metric := sm.Metrics().At(k) + + if metric.Name() == "counter.amq.TotalConnectionsCount" || metric.Name() == "jmx_memory.committed" { + metricsFound[metric.Name()] = struct{}{} + } + } + } + } + } + assert.Equal(tt, 2, len(metricsFound)) + }, 30*time.Second, 1*time.Second) } func TestNonDefaultGIDCanAccessPythonInAgentBundle(t *testing.T) { testutils.SkipIfNotContainerTest(t) - testutils.AssertAllMetricsReceived(t, "solr.yaml", "solr_config.yaml", - nil, - []testutils.CollectorBuilder{ - func(collector testutils.Collector) testutils.Collector { - cc := collector.(*testutils.CollectorContainer) - cc.Container = cc.Container.WithUser("splunk-otel-collector:234567890") - return collector - }, + tc := testutils.NewTestcase(t) + defer tc.PrintLogsOnFailure() + defer tc.ShutdownOTLPReceiverSink() + + _, shutdown := tc.SplunkOtelCollectorContainer("solr_config.yaml", + func(c testutils.Collector) testutils.Collector { + cc := c.(*testutils.CollectorContainer) + cc.Container = cc.Container.WithUser("splunk-otel-collector:234567890") + return cc }, ) + defer shutdown() + + require.EventuallyWithT(t, func(tt *assert.CollectT) { + if len(tc.OTLPReceiverSink.AllMetrics()) == 0 { + assert.Fail(tt, "No metrics collected") + return + } + metricsFound := map[string]struct{}{} + m := tc.OTLPReceiverSink.AllMetrics()[len(tc.OTLPReceiverSink.AllMetrics())-1] + for i := 0; i < m.ResourceMetrics().Len(); i++ { + rm := m.ResourceMetrics().At(i) + for j := 0; j < rm.ScopeMetrics().Len(); j++ { + sm := rm.ScopeMetrics().At(j) + for k := 0; k < sm.Metrics().Len(); k++ { + metric := sm.Metrics().At(k) + if metric.Name() == "counter.solr.http_2xx_responses" { + metricsFound[metric.Name()] = struct{}{} + } + } + } + } + assert.Equal(tt, 1, len(metricsFound)) + }, 30*time.Second, 1*time.Second) } diff --git a/tests/general/testdata/resource_metrics/activemq.yaml b/tests/general/testdata/resource_metrics/activemq.yaml deleted file mode 100644 index 5b2a00b2fd..0000000000 --- a/tests/general/testdata/resource_metrics/activemq.yaml +++ /dev/null @@ -1,7 +0,0 @@ -resource_metrics: - - scope_metrics: - - metrics: - - name: counter.amq.TotalConnectionsCount - type: IntMonotonicCumulativeSum - - name: jmx_memory.committed - type: IntGauge diff --git a/tests/general/testdata/resource_metrics/solr.yaml b/tests/general/testdata/resource_metrics/solr.yaml deleted file mode 100644 index f73566c7ec..0000000000 --- a/tests/general/testdata/resource_metrics/solr.yaml +++ /dev/null @@ -1,5 +0,0 @@ -resource_metrics: - - scope_metrics: - - metrics: - - name: counter.solr.http_2xx_responses - type: IntMonotonicCumulativeSum