Fix the issue that the debug server with port 5001 run twice

When configuring bugsnag, bugsnag will fork the process, resulting the port 5001 listened twice. The PR fix this error by moving the initialization of prometheus server after the configuration of bugsnag

Signed-off-by: Honglin Feng <tifayuki@gmail.com>
(cherry picked from commit 5a6a2d6ae06453136f5e1cfb5e9efa20c27085d9)
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
Signed-off-by: David van der Spek <vanderspek.david@gmail.com>
This commit is contained in:
Feng Honglin 2023-05-03 18:35:05 +02:00 committed by David van der Spek
parent 4adbb690c1
commit f0fdaff0a5

View file

@ -100,33 +100,17 @@ var ServeCmd = &cobra.Command{
cmd.Usage() cmd.Usage()
os.Exit(1) os.Exit(1)
} }
if config.HTTP.Debug.Addr != "" {
go func(addr string) {
logrus.Infof("debug server listening %v", addr)
if err := http.ListenAndServe(addr, nil); err != nil {
logrus.Fatalf("error listening on debug interface: %v", err)
}
}(config.HTTP.Debug.Addr)
}
registry, err := NewRegistry(ctx, config) registry, err := NewRegistry(ctx, config)
if err != nil { if err != nil {
logrus.Fatalln(err) logrus.Fatalln(err)
} }
if config.HTTP.Debug.Prometheus.Enabled { configureDebugServer(config)
path := config.HTTP.Debug.Prometheus.Path
if path == "" {
path = "/metrics"
}
logrus.Info("providing prometheus metrics on ", path)
http.Handle(path, metrics.Handler())
}
if err = registry.ListenAndServe(); err != nil { if err = registry.ListenAndServe(); err != nil {
logrus.Fatalln(err) logrus.Fatalln(err)
} }
}, },
} }
@ -318,6 +302,29 @@ func (registry *Registry) ListenAndServe() error {
} }
} }
func configureDebugServer(config *configuration.Configuration) {
if config.HTTP.Debug.Addr != "" {
go func(addr string) {
log.Infof("debug server listening %v", addr)
if err := http.ListenAndServe(addr, nil); err != nil {
log.Fatalf("error listening on debug interface: %v", err)
}
}(config.HTTP.Debug.Addr)
configurePrometheus(config)
}
}
func configurePrometheus(config *configuration.Configuration) {
if config.HTTP.Debug.Prometheus.Enabled {
path := config.HTTP.Debug.Prometheus.Path
if path == "" {
path = "/metrics"
}
log.Info("providing prometheus metrics on ", path)
http.Handle(path, metrics.Handler())
}
}
func configureReporting(app *handlers.App) http.Handler { func configureReporting(app *handlers.App) http.Handler {
var handler http.Handler = app var handler http.Handler = app