@@ -36,6 +36,9 @@ func toPdata(r *runnerState) pcommon.Map {
3636// This is used for grouping and managing statuses of multiple runners
3737type RunnerReporter interface {
3838 GetReporterForRunner (id string ) status.StatusReporter
39+
40+ // UpdateStatus updates the group status of a runnerReporter
41+ UpdateStatus (status status.Status , msg string )
3942}
4043
4144type reporter struct {
@@ -81,22 +84,40 @@ func (r *reporter) updateStatusForRunner(id string, state status.Status, msg str
8184 }
8285 }
8386
84- // report status to parent reporter
85- r .UpdateStatus ()
87+ // report aggregated status for all sub-components
88+ evt := r .calculateOtelStatus ()
89+ r .emitDummyStatus (evt )
90+ componentstatus .ReportStatus (r .host , evt )
8691}
8792
88- func (r * reporter ) UpdateStatus () {
89- evt := r .calculateOtelStatus ()
93+ // UpdateStatus reports the overall status of the group.
94+ // This is useful to report any failures encountered before a runner is initialized.
95+ // Note: This will override all sub-reporter statuses if any
96+ func (r * reporter ) UpdateStatus (status status.Status , msg string ) {
97+ otelStatus := beatStatusToOtelStatus (status )
98+ if otelStatus == componentstatus .StatusNone {
99+ return
100+ }
101+ var eventBuilderOpts []componentstatus.EventBuilderOption
102+ if componentstatus .StatusIsError (otelStatus ) {
103+ eventBuilderOpts = append (eventBuilderOpts , componentstatus .WithError (errors .New (msg )))
104+ }
105+ evt := componentstatus .NewEvent (otelStatus , eventBuilderOpts ... )
106+ r .emitDummyStatus (evt )
107+ componentstatus .ReportStatus (r .host , evt )
108+ }
109+
110+ func (r * reporter ) emitDummyStatus (evt * componentstatus.Event ) {
90111 oppositeStatus := getOppositeStatus (evt .Status ())
91112 if oppositeStatus != componentstatus .StatusNone {
92113 // emit a dummy event first to ensure the otel core framework acknowledges the change
93114 // workaround for https://github.com/open-telemetry/opentelemetry-collector/issues/14282
94115 dummyEvt := componentstatus .NewEvent (oppositeStatus )
95116 componentstatus .ReportStatus (r .host , dummyEvt )
96117 }
97- componentstatus .ReportStatus (r .host , evt )
98118}
99119
120+ // calculateOtelStatus aggregates the statuses of all runners
100121func (r * reporter ) calculateOtelStatus () * componentstatus.Event {
101122 var evt * componentstatus.Event
102123 s , msg := r .calculateAggregateState ()
0 commit comments