Merge pull request #3895 from pluralsh/bug-fix-5001-server-rebase

Fix the issue that the debug server with port 5001 run twice
pull/3888/merge
Wang Yan 2023-05-05 13:21:55 +08:00 committed by GitHub
commit 8900e90699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 18 deletions

View File

@ -100,29 +100,12 @@ var ServeCmd = &cobra.Command{
cmd.Usage()
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)
if err != nil {
logrus.Fatalln(err)
}
if config.HTTP.Debug.Prometheus.Enabled {
path := config.HTTP.Debug.Prometheus.Path
if path == "" {
path = "/metrics"
}
logrus.Info("providing prometheus metrics on ", path)
http.Handle(path, metrics.Handler())
}
configureDebugServer(config)
if err = registry.ListenAndServe(); err != nil {
logrus.Fatalln(err)
@ -318,6 +301,29 @@ func (registry *Registry) ListenAndServe() error {
}
}
func configureDebugServer(config *configuration.Configuration) {
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)
configurePrometheus(config)
}
}
func configurePrometheus(config *configuration.Configuration) {
if config.HTTP.Debug.Prometheus.Enabled {
path := config.HTTP.Debug.Prometheus.Path
if path == "" {
path = "/metrics"
}
logrus.Info("providing prometheus metrics on ", path)
http.Handle(path, metrics.Handler())
}
}
func configureReporting(app *handlers.App) http.Handler {
var handler http.Handler = app