@@ -11,6 +11,7 @@ import (
1111 "errors"
1212 "os"
1313 "path/filepath"
14+ "strings"
1415 "sync"
1516 "testing"
1617 "time"
@@ -264,6 +265,22 @@ func (t *EventTime[T]) Time() time.Time {
264265 return t .time
265266}
266267
268+ func countHealthCheckExtensionStatuses (status * status.AggregateStatus ) uint {
269+ extensions , ok := status .ComponentStatusMap ["extensions" ]
270+ if ! ok {
271+ return 0
272+ }
273+
274+ count := uint (0 )
275+ for key := range extensions .ComponentStatusMap {
276+ if strings .HasPrefix (key , "extension:healthcheckv2/" ) {
277+ count ++
278+ }
279+ }
280+
281+ return count
282+ }
283+
267284func TestOTelManager_Run (t * testing.T ) {
268285 wd , erWd := os .Getwd ()
269286 require .NoError (t , erWd , "cannot get working directory" )
@@ -273,14 +290,16 @@ func TestOTelManager_Run(t *testing.T) {
273290
274291 for _ , tc := range []struct {
275292 name string
276- exec * testExecution
293+ exec func () ( collectorExecution , error )
277294 restarter collectorRecoveryTimer
278295 skipListeningErrors bool
279296 testFn func (t * testing.T , m * OTelManager , e * EventListener , exec * testExecution )
280297 }{
281298 {
282- name : "embedded collector config updates" ,
283- exec : & testExecution {exec : newExecutionEmbedded ()},
299+ name : "embedded collector config updates" ,
300+ exec : func () (collectorExecution , error ) {
301+ return newExecutionEmbedded (), nil
302+ },
284303 restarter : newRestarterNoop (),
285304 testFn : func (t * testing.T , m * OTelManager , e * EventListener , exec * testExecution ) {
286305 // ensure that it got healthy
@@ -302,8 +321,10 @@ func TestOTelManager_Run(t *testing.T) {
302321 },
303322 },
304323 {
305- name : "subprocess collector config updates" ,
306- exec : & testExecution {exec : newSubprocessExecution (logp .DebugLevel , testBinary )},
324+ name : "subprocess collector config updates" ,
325+ exec : func () (collectorExecution , error ) {
326+ return newSubprocessExecution (logp .DebugLevel , testBinary )
327+ },
307328 restarter : newRecoveryBackoff (100 * time .Nanosecond , 10 * time .Second , time .Minute ),
308329 testFn : func (t * testing.T , m * OTelManager , e * EventListener , exec * testExecution ) {
309330 // ensure that it got healthy
@@ -326,8 +347,10 @@ func TestOTelManager_Run(t *testing.T) {
326347 },
327348 },
328349 {
329- name : "embedded collector stopped gracefully outside manager" ,
330- exec : & testExecution {exec : newExecutionEmbedded ()},
350+ name : "embedded collector stopped gracefully outside manager" ,
351+ exec : func () (collectorExecution , error ) {
352+ return newExecutionEmbedded (), nil
353+ },
331354 restarter : newRestarterNoop (),
332355 testFn : func (t * testing.T , m * OTelManager , e * EventListener , exec * testExecution ) {
333356 // ensure that it got healthy
@@ -350,8 +373,10 @@ func TestOTelManager_Run(t *testing.T) {
350373 },
351374 },
352375 {
353- name : "subprocess collector stopped gracefully outside manager" ,
354- exec : & testExecution {exec : newSubprocessExecution (logp .DebugLevel , testBinary )},
376+ name : "subprocess collector stopped gracefully outside manager" ,
377+ exec : func () (collectorExecution , error ) {
378+ return newSubprocessExecution (logp .DebugLevel , testBinary )
379+ },
355380 restarter : newRecoveryBackoff (100 * time .Nanosecond , 10 * time .Second , time .Minute ),
356381 testFn : func (t * testing.T , m * OTelManager , e * EventListener , exec * testExecution ) {
357382 // ensure that it got healthy
@@ -365,6 +390,7 @@ func TestOTelManager_Run(t *testing.T) {
365390 require .NotNil (t , exec .handle , "exec handle should not be nil" )
366391 exec .handle .Stop (t .Context ())
367392 e .EnsureHealthy (t , updateTime )
393+ assert .EqualValues (t , 1 , countHealthCheckExtensionStatuses (e .getStatus ()), "health check extension status count should be 1" )
368394
369395 // no configuration should stop the runner
370396 updateTime = time .Now ()
@@ -375,15 +401,18 @@ func TestOTelManager_Run(t *testing.T) {
375401 },
376402 },
377403 {
378- name : "subprocess collector killed outside manager" ,
379- exec : & testExecution {exec : newSubprocessExecution (logp .DebugLevel , testBinary )},
404+ name : "subprocess collector killed outside manager" ,
405+ exec : func () (collectorExecution , error ) {
406+ return newSubprocessExecution (logp .DebugLevel , testBinary )
407+ },
380408 restarter : newRecoveryBackoff (100 * time .Nanosecond , 10 * time .Second , time .Minute ),
381409 testFn : func (t * testing.T , m * OTelManager , e * EventListener , exec * testExecution ) {
382410 // ensure that it got healthy
383411 cfg := confmap .NewFromStringMap (testConfig )
384412 updateTime := time .Now ()
385413 m .Update (cfg , nil )
386414 e .EnsureHealthy (t , updateTime )
415+ assert .EqualValues (t , 1 , countHealthCheckExtensionStatuses (e .getStatus ()), "health check extension status count should be 1" )
387416
388417 var oldPHandle * procHandle
389418 // repeatedly kill the collector
@@ -401,6 +430,7 @@ func TestOTelManager_Run(t *testing.T) {
401430 // the collector should restart and report healthy
402431 updateTime = time .Now ()
403432 e .EnsureHealthy (t , updateTime )
433+ assert .EqualValues (t , 1 , countHealthCheckExtensionStatuses (e .getStatus ()), "health check extension status count should be 1" )
404434 }
405435
406436 seenRecoveredTimes := m .recoveryRetries .Load ()
@@ -414,8 +444,10 @@ func TestOTelManager_Run(t *testing.T) {
414444 },
415445 },
416446 {
417- name : "subprocess collector panics" ,
418- exec : & testExecution {exec : newSubprocessExecution (logp .DebugLevel , testBinary )},
447+ name : "subprocess collector panics" ,
448+ exec : func () (collectorExecution , error ) {
449+ return newSubprocessExecution (logp .DebugLevel , testBinary )
450+ },
419451 restarter : newRecoveryBackoff (100 * time .Nanosecond , 10 * time .Second , time .Minute ),
420452 testFn : func (t * testing.T , m * OTelManager , e * EventListener , exec * testExecution ) {
421453 err := os .Setenv ("TEST_SUPERVISED_COLLECTOR_PANIC" , (3 * time .Second ).String ())
@@ -448,8 +480,10 @@ func TestOTelManager_Run(t *testing.T) {
448480 },
449481 },
450482 {
451- name : "embedded collector invalid config" ,
452- exec : & testExecution {exec : newExecutionEmbedded ()},
483+ name : "embedded collector invalid config" ,
484+ exec : func () (collectorExecution , error ) {
485+ return newExecutionEmbedded (), nil
486+ },
453487 restarter : newRestarterNoop (),
454488 skipListeningErrors : true ,
455489 testFn : func (t * testing.T , m * OTelManager , e * EventListener , exec * testExecution ) {
@@ -487,8 +521,10 @@ func TestOTelManager_Run(t *testing.T) {
487521 },
488522 },
489523 {
490- name : "subprocess collector invalid config" ,
491- exec : & testExecution {exec : newSubprocessExecution (logp .DebugLevel , testBinary )},
524+ name : "subprocess collector invalid config" ,
525+ exec : func () (collectorExecution , error ) {
526+ return newSubprocessExecution (logp .DebugLevel , testBinary )
527+ },
492528 restarter : newRecoveryBackoff (100 * time .Nanosecond , 10 * time .Second , time .Minute ),
493529 skipListeningErrors : true ,
494530 testFn : func (t * testing.T , m * OTelManager , e * EventListener , exec * testExecution ) {
@@ -531,6 +567,11 @@ func TestOTelManager_Run(t *testing.T) {
531567 defer cancel ()
532568 l , _ := loggertest .New ("otel" )
533569 base , obs := loggertest .New ("otel" )
570+
571+ executionMode , err := tc .exec ()
572+ require .NoError (t , err , "failed to create execution mode" )
573+ testExecutionMode := & testExecution {exec : executionMode }
574+
534575 m := & OTelManager {
535576 logger : l ,
536577 baseLogger : base ,
@@ -540,7 +581,7 @@ func TestOTelManager_Run(t *testing.T) {
540581 componentStateCh : make (chan []runtime.ComponentComponentState , 1 ),
541582 doneChan : make (chan struct {}),
542583 recoveryTimer : tc .restarter ,
543- execution : tc . exec ,
584+ execution : testExecutionMode ,
544585 }
545586
546587 eListener := & EventListener {}
@@ -573,7 +614,7 @@ func TestOTelManager_Run(t *testing.T) {
573614 runErr = m .Run (ctx )
574615 }()
575616
576- tc .testFn (t , m , eListener , tc . exec )
617+ tc .testFn (t , m , eListener , testExecutionMode )
577618
578619 cancel ()
579620 runWg .Wait ()
0 commit comments