@@ -18,6 +18,7 @@ package service
18
18
19
19
import (
20
20
"context"
21
+ "errors"
21
22
"flag"
22
23
"fmt"
23
24
"os"
@@ -32,6 +33,7 @@ import (
32
33
"go.opentelemetry.io/collector/config/configcheck"
33
34
"go.opentelemetry.io/collector/config/configloader"
34
35
"go.opentelemetry.io/collector/config/configtelemetry"
36
+ "go.opentelemetry.io/collector/config/experimental/configsource"
35
37
"go.opentelemetry.io/collector/consumer/consumererror"
36
38
"go.opentelemetry.io/collector/internal/collector/telemetry"
37
39
"go.opentelemetry.io/collector/service/internal/builder"
@@ -254,6 +256,24 @@ func (app *Application) setupConfigurationComponents(ctx context.Context) error
254
256
}
255
257
256
258
app .service = service
259
+
260
+ // If provider is watchable start a goroutine watching for updates.
261
+ if watchable , ok := app .parserProvider .(parserprovider.Watchable ); ok {
262
+ go func () {
263
+ err := watchable .WatchForUpdate ()
264
+ switch {
265
+ // TODO: Move configsource.ErrSessionClosed to providerparser package to avoid depending on configsource.
266
+ case errors .Is (err , configsource .ErrSessionClosed ):
267
+ // This is the case of shutdown of the whole application, nothing to do.
268
+ app .logger .Info ("Config WatchForUpdate closed" , zap .Error (err ))
269
+ return
270
+ default :
271
+ app .logger .Warn ("Config WatchForUpdated exited" , zap .Error (err ))
272
+ app .reloadService (context .Background ())
273
+ }
274
+ }()
275
+ }
276
+
257
277
return nil
258
278
}
259
279
@@ -291,6 +311,12 @@ func (app *Application) execute(ctx context.Context) error {
291
311
runtime .KeepAlive (ballast )
292
312
app .logger .Info ("Starting shutdown..." )
293
313
314
+ if closable , ok := app .parserProvider .(parserprovider.Closeable ); ok {
315
+ if err := closable .Close (ctx ); err != nil {
316
+ errs = append (errs , fmt .Errorf ("failed to close config: %w" , err ))
317
+ }
318
+ }
319
+
294
320
if app .service != nil {
295
321
if err := app .service .Shutdown (ctx ); err != nil {
296
322
errs = append (errs , fmt .Errorf ("failed to shutdown service: %w" , err ))
@@ -319,10 +345,16 @@ func (app *Application) createMemoryBallast() ([]byte, uint64) {
319
345
return nil , 0
320
346
}
321
347
322
- // updateService shutdowns the current app.service and setups a new one according
348
+ // reloadService shutdowns the current app.service and setups a new one according
323
349
// to the latest configuration. It requires that app.parserProvider and app.factories
324
350
// are properly populated to finish successfully.
325
- func (app * Application ) updateService (ctx context.Context ) error {
351
+ func (app * Application ) reloadService (ctx context.Context ) error {
352
+ if closeable , ok := app .parserProvider .(parserprovider.Closeable ); ok {
353
+ if err := closeable .Close (ctx ); err != nil {
354
+ return fmt .Errorf ("failed close current config provider: %w" , err )
355
+ }
356
+ }
357
+
326
358
if app .service != nil {
327
359
retiringService := app .service
328
360
app .service = nil
0 commit comments