@@ -40,20 +40,18 @@ import (
40
40
41
41
// Application represents a collector application
42
42
type Application struct {
43
- info ApplicationStartInfo
44
- rootCmd * cobra.Command
45
- v * viper.Viper
46
- logger * zap.Logger
47
- exporters builder.Exporters
48
- builtReceivers builder.Receivers
49
- builtPipelines builder.BuiltPipelines
43
+ info ApplicationStartInfo
44
+ rootCmd * cobra.Command
45
+ v * viper.Viper
46
+ logger * zap.Logger
47
+ builtExporters builder.Exporters
48
+ builtReceivers builder.Receivers
49
+ builtPipelines builder.BuiltPipelines
50
+ builtExtensions builder.Extensions
50
51
51
52
factories config.Factories
52
53
config * configmodels.Config
53
54
54
- extensionsList []component.ServiceExtension
55
- extensionsMap map [configmodels.Extension ]component.ServiceExtension
56
-
57
55
// stopTestChan is used to terminate the application in end to end tests.
58
56
stopTestChan chan struct {}
59
57
// readyChan is used in tests to indicate that the application is ready.
@@ -184,7 +182,7 @@ func (app *Application) GetFactory(kind component.Kind, componentType string) co
184
182
}
185
183
186
184
func (app * Application ) GetExtensions () map [configmodels.Extension ]component.ServiceExtension {
187
- return app .extensionsMap
185
+ return app .builtExtensions . GetServiceExtensions ()
188
186
}
189
187
190
188
func (app * Application ) init () error {
@@ -262,37 +260,13 @@ func (app *Application) setupConfigurationComponents(ctx context.Context, factor
262
260
}
263
261
264
262
func (app * Application ) setupExtensions (ctx context.Context ) error {
265
- app .extensionsMap = make (map [configmodels.Extension ]component.ServiceExtension )
266
- for _ , extName := range app .config .Service .Extensions {
267
- extCfg , exists := app .config .Extensions [extName ]
268
- if ! exists {
269
- return errors .Errorf ("extension %q is not configured" , extName )
270
- }
271
-
272
- factory , exists := app .factories .Extensions [extCfg .Type ()]
273
- if ! exists {
274
- return errors .Errorf ("extension factory for type %q is not configured" , extCfg .Type ())
275
- }
276
-
277
- ext , err := factory .CreateExtension (ctx , component.ExtensionCreateParams {Logger : app .logger }, extCfg )
278
- if err != nil {
279
- return errors .Wrapf (err , "failed to create extension %q" , extName )
280
- }
281
-
282
- // Check if the factory really created the extension.
283
- if ext == nil {
284
- return errors .Errorf ("factory for %q produced a nil extension" , extName )
285
- }
286
-
287
- if err := ext .Start (ctx , app ); err != nil {
288
- return errors .Wrapf (err , "error starting extension %q" , extName )
289
- }
290
-
291
- app .extensionsList = append (app .extensionsList , ext )
292
- app .extensionsMap [extCfg ] = ext
263
+ var err error
264
+ app .builtExtensions , err = builder .NewExtensionsBuilder (app .logger , app .config , app .factories .Extensions ).Build ()
265
+ if err != nil {
266
+ return errors .Wrap (err , "cannot build builtExtensions" )
293
267
}
294
-
295
- return nil
268
+ app . logger . Info ( "Starting extensions..." )
269
+ return app . builtExtensions . StartAll ( ctx , app )
296
270
}
297
271
298
272
func (app * Application ) setupPipelines (ctx context.Context ) error {
@@ -301,19 +275,20 @@ func (app *Application) setupPipelines(ctx context.Context) error {
301
275
302
276
// First create exporters.
303
277
var err error
304
- app .exporters , err = builder .NewExportersBuilder (app .logger , app .config , app .factories .Exporters ).Build ()
278
+ app .builtExporters , err = builder .NewExportersBuilder (app .logger , app .config , app .factories .Exporters ).Build ()
305
279
if err != nil {
306
- return errors .Wrap (err , "cannot build exporters " )
280
+ return errors .Wrap (err , "cannot build builtExporters " )
307
281
}
308
282
app .logger .Info ("Starting exporters..." )
309
- err = app .exporters .StartAll (ctx , app )
283
+
284
+ err = app .builtExporters .StartAll (ctx , app )
310
285
if err != nil {
311
- return errors .Wrap (err , "cannot start exporters " )
286
+ return errors .Wrap (err , "cannot start builtExporters " )
312
287
}
313
288
314
289
// Create pipelines and their processors and plug exporters to the
315
290
// end of the pipelines.
316
- app .builtPipelines , err = builder .NewPipelinesBuilder (app .logger , app .config , app .exporters , app .factories .Processors ).Build ()
291
+ app .builtPipelines , err = builder .NewPipelinesBuilder (app .logger , app .config , app .builtExporters , app .factories .Processors ).Build ()
317
292
if err != nil {
318
293
return errors .Wrap (err , "cannot build pipelines" )
319
294
}
@@ -339,43 +314,6 @@ func (app *Application) setupPipelines(ctx context.Context) error {
339
314
return nil
340
315
}
341
316
342
- func (app * Application ) notifyPipelineReady () error {
343
- for i , ext := range app .extensionsList {
344
- if pw , ok := ext .(component.PipelineWatcher ); ok {
345
- if err := pw .Ready (); err != nil {
346
- return errors .Wrapf (
347
- err ,
348
- "error notifying extension %q that the pipeline was started" ,
349
- app .config .Service .Extensions [i ],
350
- )
351
- }
352
- }
353
- }
354
-
355
- return nil
356
- }
357
-
358
- func (app * Application ) notifyPipelineNotReady () error {
359
- // Notify extensions in reverse order.
360
- var errs []error
361
- for i := len (app .extensionsList ) - 1 ; i >= 0 ; i -- {
362
- ext := app .extensionsList [i ]
363
- if pw , ok := ext .(component.PipelineWatcher ); ok {
364
- if err := pw .NotReady (); err != nil {
365
- errs = append (errs , errors .Wrapf (err ,
366
- "error notifying extension %q that the pipeline was shutdown" ,
367
- app .config .Service .Extensions [i ]))
368
- }
369
- }
370
- }
371
-
372
- if len (errs ) != 0 {
373
- return componenterror .CombineErrors (errs )
374
- }
375
-
376
- return nil
377
- }
378
-
379
317
func (app * Application ) shutdownPipelines (ctx context.Context ) error {
380
318
// Shutdown order is the reverse of building: first receivers, then flushing pipelines
381
319
// giving senders a chance to send all their data. This may take time, the allowed
@@ -395,8 +333,8 @@ func (app *Application) shutdownPipelines(ctx context.Context) error {
395
333
errs = append (errs , errors .Wrap (err , "failed to shutdown processors" ))
396
334
}
397
335
398
- app .logger .Info ("Shutting down exporters..." )
399
- err = app .exporters .ShutdownAll (ctx )
336
+ app .logger .Info ("Stopping exporters..." )
337
+ err = app .builtExporters .ShutdownAll (ctx )
400
338
if err != nil {
401
339
errs = append (errs , errors .Wrap (err , "failed to shutdown exporters" ))
402
340
}
@@ -409,21 +347,11 @@ func (app *Application) shutdownPipelines(ctx context.Context) error {
409
347
}
410
348
411
349
func (app * Application ) shutdownExtensions (ctx context.Context ) error {
412
- // Shutdown extensions in reverse order.
413
- var errs []error
414
- for i := len (app .extensionsList ) - 1 ; i >= 0 ; i -- {
415
- ext := app .extensionsList [i ]
416
- if err := ext .Shutdown (ctx ); err != nil {
417
- errs = append (errs , errors .Wrapf (err ,
418
- "error shutting down extension %q" ,
419
- app .config .Service .Extensions [i ]))
420
- }
421
- }
422
-
423
- if len (errs ) != 0 {
424
- return componenterror .CombineErrors (errs )
350
+ app .logger .Info ("Stopping extensions..." )
351
+ err := app .builtExtensions .ShutdownAll (ctx )
352
+ if err != nil {
353
+ return errors .Wrap (err , "failed to shutdown extensions" )
425
354
}
426
-
427
355
return nil
428
356
}
429
357
@@ -450,7 +378,7 @@ func (app *Application) execute(ctx context.Context, factory ConfigFactory) erro
450
378
return err
451
379
}
452
380
453
- err = app .notifyPipelineReady ()
381
+ err = app .builtExtensions . NotifyPipelineReady ()
454
382
if err != nil {
455
383
return err
456
384
}
@@ -465,7 +393,7 @@ func (app *Application) execute(ctx context.Context, factory ConfigFactory) erro
465
393
runtime .KeepAlive (ballast )
466
394
app .logger .Info ("Starting shutdown..." )
467
395
468
- err = app .notifyPipelineNotReady ()
396
+ err = app .builtExtensions . NotifyPipelineNotReady ()
469
397
if err != nil {
470
398
errs = append (errs , errors .Wrap (err , "failed to notify that pipeline is not ready" ))
471
399
}
0 commit comments