Skip to content

Commit 5323068

Browse files
committed
fix
1 parent 8fce604 commit 5323068

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

plugins/inputs/prometheus/start.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -307,32 +307,35 @@ func Start(configFilePath string, receiver storage.Appendable, shutDownChan chan
307307
)
308308
}
309309

310-
// Set up a separate zap logger for the certWatcher (just this part, not the entire file)
311-
zapLogger, err := zap.NewProduction() // or zap.NewDevelopment() depending on your needs
310+
zapLogger, err := zap.NewProduction()
312311
if err != nil {
313-
level.Error(logger).Log("msg", "Failed to create zap logger", "err", err)
314-
return
312+
zapLogger = zap.NewNop()
315313
}
316314

317-
// Create the certWatcher with the new zap logger
318315
certWatcher, err := tls.NewCertWatcher(DefaultTLSCertFilePath, DefaultTLSKeyFilePath, DefaultTLSCaFilePath, zapLogger)
319316
if err != nil {
320317
level.Error(logger).Log("msg", "Failed to initialize cert watcher", "err", err)
321318
} else {
322319
certWatcher.RegisterCallback(func() {
323320
level.Info(logger).Log("msg", "Certificate files changed, restarting target allocator manager")
324-
// Shutdown and restart the Target Allocator manager
325321
taManager.Shutdown()
326-
// Reload the Target Allocator manager's configuration and start it again
327322
taManager = createTargetAllocatorManager(configFilePath, log.With(logger, "component", "ta manager"), logLevel, scrapeManager, discoveryManagerScrape)
328-
// Ensure it's enabled before running
323+
taManager.AttachReloadConfigHandler(
324+
func(prometheusConfig *config.Config) {
325+
relabelScrapeConfigs(prometheusConfig, logger)
326+
},
327+
)
329328
if taManager.enabled {
330329
if err := taManager.Run(); err != nil {
331330
level.Error(logger).Log("msg", "Error restarting target allocator manager", "err", err)
332331
}
333332
}
334333
})
335-
go certWatcher.Start(context.Background())
334+
go func() {
335+
if err := certWatcher.Start(context.Background()); err != nil {
336+
level.Error(logger).Log("msg", "Failed to start cert watcher", "err", err)
337+
}
338+
}()
336339
}
337340

338341
if err := g.Run(); err != nil {

0 commit comments

Comments
 (0)