@@ -21,6 +21,9 @@ import (
21
21
"testing"
22
22
"time"
23
23
24
+ "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden"
25
+ "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest"
26
+ "github.com/stretchr/testify/assert"
24
27
"github.com/stretchr/testify/require"
25
28
"github.com/testcontainers/testcontainers-go"
26
29
@@ -237,18 +240,48 @@ service:
237
240
}
238
241
239
242
func TestStandaloneConfigD (t * testing.T ) {
240
- testutils .AssertAllMetricsReceived (
241
- t , "memory.yaml" , "empty-config.yaml" ,
242
- nil , []testutils.CollectorBuilder {
243
- func (c testutils.Collector ) testutils.Collector {
244
- configd , err := filepath .Abs (filepath .Join ("." , "testdata" , "standalone-config.d" ))
245
- require .NoError (t , err )
246
- if cc , ok := c .(* testutils.CollectorContainer ); ok {
247
- cc .Container = cc .Container .WithMount (testcontainers .BindMount (configd , "/opt/config.d" ))
248
- configd = "/opt/config.d"
249
- }
250
- return c .WithEnv (map [string ]string {"SPLUNK_CONFIG_DIR" : configd }).WithArgs ("--configd" )
251
- },
243
+ tc := testutils .NewTestcase (t )
244
+ defer tc .PrintLogsOnFailure ()
245
+ defer tc .ShutdownOTLPReceiverSink ()
246
+
247
+ _ , shutdown := tc .SplunkOtelCollectorContainer ("empty-config.yaml" ,
248
+ func (c testutils.Collector ) testutils.Collector {
249
+ configd , err := filepath .Abs (filepath .Join ("." , "testdata" , "standalone-config.d" ))
250
+ require .NoError (t , err )
251
+ if cc , ok := c .(* testutils.CollectorContainer ); ok {
252
+ cc .Container = cc .Container .WithMount (testcontainers .BindMount (configd , "/opt/config.d" ))
253
+ configd = "/opt/config.d"
254
+ }
255
+ return c .WithEnv (map [string ]string {"SPLUNK_CONFIG_DIR" : configd }).WithArgs ("--configd" )
252
256
},
253
257
)
258
+ defer shutdown ()
259
+
260
+ expected , err := golden .ReadMetrics (filepath .Join ("testdata" , "memory-expected.yaml" ))
261
+ require .NoError (t , err )
262
+ require .EventuallyWithT (t , func (tt * assert.CollectT ) {
263
+ if len (tc .OTLPReceiverSink .AllMetrics ()) == 0 {
264
+ assert .Fail (tt , "No metrics collected" )
265
+ return
266
+ }
267
+ err := pmetrictest .CompareMetrics (expected , tc .OTLPReceiverSink .AllMetrics ()[len (tc .OTLPReceiverSink .AllMetrics ())- 1 ],
268
+ pmetrictest .IgnoreResourceAttributeValue ("service.instance.id" ),
269
+ pmetrictest .IgnoreResourceAttributeValue ("net.host.port" ),
270
+ pmetrictest .IgnoreResourceAttributeValue ("net.host.name" ),
271
+ pmetrictest .IgnoreResourceAttributeValue ("server.address" ),
272
+ pmetrictest .IgnoreResourceAttributeValue ("container.name" ),
273
+ pmetrictest .IgnoreResourceAttributeValue ("server.port" ),
274
+ pmetrictest .IgnoreResourceAttributeValue ("service.name" ),
275
+ pmetrictest .IgnoreResourceAttributeValue ("service_instance_id" ),
276
+ pmetrictest .IgnoreResourceAttributeValue ("service_version" ),
277
+ pmetrictest .IgnoreTimestamp (),
278
+ pmetrictest .IgnoreStartTimestamp (),
279
+ pmetrictest .IgnoreMetricDataPointsOrder (),
280
+ pmetrictest .IgnoreScopeMetricsOrder (),
281
+ pmetrictest .IgnoreScopeVersion (),
282
+ pmetrictest .IgnoreResourceMetricsOrder (),
283
+ pmetrictest .IgnoreMetricValues (),
284
+ )
285
+ assert .NoError (tt , err )
286
+ }, 30 * time .Second , 1 * time .Second )
254
287
}
0 commit comments