@@ -19,6 +19,7 @@ import (
19
19
"encoding/base64"
20
20
"fmt"
21
21
"os"
22
+ "runtime"
22
23
"sort"
23
24
"strconv"
24
25
"strings"
@@ -182,6 +183,19 @@ func (d *discoverer) discover(cfg *Config) (map[string]any, error) {
182
183
return nil , nil
183
184
}
184
185
186
+ err = d .performDiscovery (discoveryReceivers , discoveryObservers )
187
+ if err != nil {
188
+ return nil , err
189
+ }
190
+
191
+ discoveryConfig , err := d .discoveryConfig (cfg )
192
+ if err != nil {
193
+ return nil , fmt .Errorf ("failed constructing discovery config: %w" , err )
194
+ }
195
+ return discoveryConfig , nil
196
+ }
197
+
198
+ func (d * discoverer ) performDiscovery (discoveryReceivers map [component.ID ]otelcolreceiver.Logs , discoveryObservers map [component.ID ]otelcolextension.Extension ) error {
185
199
var cancels []context.CancelFunc
186
200
187
201
defer func () {
@@ -199,19 +213,35 @@ func (d *discoverer) discover(cfg *Config) (map[string]any, error) {
199
213
fmt .Sprintf ("%q startup failed. Won't proceed with %q-based discovery" , observerID , observerID .Type ()),
200
214
zap .Error (e ),
201
215
)
216
+ return e
202
217
}
218
+ defer func (obsID component.ID , obsExt otelcolextension.Extension ) {
219
+ ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
220
+ cancels = append (cancels , cancel )
221
+ if e := obsExt .Shutdown (ctx ); e != nil {
222
+ d .logger .Warn (fmt .Sprintf ("error shutting down observer %q" , obsID ), zap .Error (e ))
223
+ }
224
+ }(observerID , observer )
203
225
}
204
226
205
227
for receiverID , receiver := range discoveryReceivers {
206
228
d .logger .Debug (fmt .Sprintf ("starting receiver %q" , receiverID ))
207
229
ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
208
230
cancels = append (cancels , cancel )
209
- if err = receiver .Start (ctx , d ); err != nil {
231
+ if err : = receiver .Start (ctx , d ); err != nil {
210
232
d .logger .Warn (
211
233
fmt .Sprintf ("%q startup failed." , receiverID ),
212
234
zap .Error (err ),
213
235
)
236
+ return err
214
237
}
238
+ defer func (rcvID component.ID , rcv otelcolreceiver.Logs ) {
239
+ ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
240
+ cancels = append (cancels , cancel )
241
+ if e := rcv .Shutdown (ctx ); e != nil {
242
+ d .logger .Warn (fmt .Sprintf ("error shutting down receiver %q" , rcvID ), zap .Error (e ))
243
+ }
244
+ }(receiverID , receiver )
215
245
}
216
246
217
247
_ , _ = fmt .Fprintf (os .Stderr , "Discovering for next %s...\n " , d .duration )
@@ -221,26 +251,7 @@ func (d *discoverer) discover(cfg *Config) (map[string]any, error) {
221
251
}
222
252
_ , _ = fmt .Fprintf (os .Stderr , "Discovery complete.\n " )
223
253
224
- for receiverID , receiver := range discoveryReceivers {
225
- ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
226
- cancels = append (cancels , cancel )
227
- if e := receiver .Shutdown (ctx ); e != nil {
228
- d .logger .Warn (fmt .Sprintf ("error shutting down receiver %q" , receiverID ), zap .Error (e ))
229
- }
230
- }
231
- for observerID , observer := range discoveryObservers {
232
- ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
233
- cancels = append (cancels , cancel )
234
- if e := observer .Shutdown (ctx ); e != nil {
235
- d .logger .Warn (fmt .Sprintf ("error shutting down observer %q" , observerID ), zap .Error (e ))
236
- }
237
- }
238
-
239
- discoveryConfig , err := d .discoveryConfig (cfg )
240
- if err != nil {
241
- return nil , fmt .Errorf ("failed constructing discovery config: %w" , err )
242
- }
243
- return discoveryConfig , nil
254
+ return nil
244
255
}
245
256
246
257
func (d * discoverer ) createDiscoveryReceiversAndObservers (cfg * Config ) (map [component.ID ]otelcolreceiver.Logs , map [component.ID ]otelcolextension.Extension , error ) {
@@ -449,11 +460,15 @@ func (d *discoverer) updateReceiverForObserver(receiverID component.ID, receiver
449
460
450
461
func factoryForObserverType (extType component.Type ) (otelcolextension.Factory , error ) {
451
462
factories := map [component.Type ]otelcolextension.Factory {
452
- component .MustNewType ("docker_observer" ): dockerobserver .NewFactory (),
453
463
component .MustNewType ("host_observer" ): hostobserver .NewFactory (),
454
464
component .MustNewType ("k8s_observer" ): k8sobserver .NewFactory (),
455
465
component .MustNewType ("ecs_task_observer" ): ecstaskobserver .NewFactory (),
456
466
}
467
+ if runtime .GOOS != "windows" {
468
+ // Docker observer currently always crashes on Windows with the default configuration.
469
+ // The observer is being temporarily disabled until it is fixed upstream.
470
+ factories [component .MustNewType ("docker_observer" )] = dockerobserver .NewFactory ()
471
+ }
457
472
ef , ok := factories [extType ]
458
473
if ! ok {
459
474
return nil , fmt .Errorf ("unsupported discovery observer %q. Please remove its .discovery.yaml from your config directory" , extType )
0 commit comments