From 1f6ec1d9f53e793215dcd62e13f9a7296bf62bba Mon Sep 17 00:00:00 2001 From: Deluan Date: Wed, 15 Mar 2023 10:56:13 -0400 Subject: [PATCH] Add pprof endpoint, disabled by default --- cmd/root.go | 4 ++++ conf/configuration.go | 2 ++ 2 files changed, 6 insertions(+) diff --git a/cmd/root.go b/cmd/root.go index 35a5743f..f3a4af5b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,6 +8,7 @@ import ( "strings" "time" + "github.com/go-chi/chi/v5/middleware" "github.com/navidrome/navidrome/conf" "github.com/navidrome/navidrome/consts" "github.com/navidrome/navidrome/core" @@ -96,6 +97,9 @@ func startServer(ctx context.Context) func() error { core.WriteInitialMetrics() a.MountRouter("Prometheus metrics", conf.Server.Prometheus.MetricsPath, promhttp.Handler()) } + if conf.Server.DevEnableProfiler { + a.MountRouter("Profiling", "/debug", middleware.Profiler()) + } if strings.HasPrefix(conf.Server.UILoginBackgroundURL, "/") { a.MountRouter("Background images", consts.DefaultUILoginBackgroundURL, backgrounds.NewHandler()) } diff --git a/conf/configuration.go b/conf/configuration.go index 7525b16e..5112e6ea 100644 --- a/conf/configuration.go +++ b/conf/configuration.go @@ -83,6 +83,7 @@ type configOptions struct { // DevFlags. These are used to enable/disable debugging and incomplete features DevLogSourceLine bool DevLogLevels map[string]string + DevEnableProfiler bool DevAutoCreateAdminPassword string DevAutoLoginUsername string DevActivityPanel bool @@ -303,6 +304,7 @@ func init() { // DevFlags. These are used to enable/disable debugging and incomplete features viper.SetDefault("devlogsourceline", false) + viper.SetDefault("devenableprofiler", false) viper.SetDefault("devautocreateadminpassword", "") viper.SetDefault("devautologinusername", "") viper.SetDefault("devactivitypanel", true)