From 88fea80bac7e7bcd437d51bf9fea6241ba07ea13 Mon Sep 17 00:00:00 2001 From: naveen <172697+naveensrinivasan@users.noreply.github.com> Date: Tue, 9 Nov 2021 19:58:31 +0000 Subject: [PATCH 1/3] Included pprof for profiling the application. Included pprof for profiling the application. Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com> --- cmd/rekor-server/app/root.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/cmd/rekor-server/app/root.go b/cmd/rekor-server/app/root.go index af606de96..b1084b9c7 100644 --- a/cmd/rekor-server/app/root.go +++ b/cmd/rekor-server/app/root.go @@ -17,6 +17,8 @@ package app import ( "fmt" + "net/http" + "net/http/pprof" "os" "runtime/debug" @@ -27,9 +29,12 @@ import ( "github.com/sigstore/rekor/pkg/log" ) -var cfgFile string -var logType string -var logRangeMap LogRanges +var ( + cfgFile string + logType string + enablePprof bool + logRangeMap LogRanges +) // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ @@ -57,6 +62,7 @@ func init() { rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.rekor-server.yaml)") rootCmd.PersistentFlags().StringVar(&logType, "log_type", "dev", "logger type to use (dev/prod)") + rootCmd.PersistentFlags().BoolVar(&enablePprof, "enable_pprof", false, "enable pprof for profiling") rootCmd.PersistentFlags().String("trillian_log_server.address", "127.0.0.1", "Trillian log server address") rootCmd.PersistentFlags().Uint16("trillian_log_server.port", 8090, "Trillian log server port") @@ -88,6 +94,21 @@ func init() { if GitVersion != "devel" { return } + log.Logger.Debugf("pprof enabled %v", enablePprof) + // Enable pprof + if enablePprof { + go func() { + mux := http.NewServeMux() + + mux.HandleFunc("/debug/pprof/", pprof.Index) + mux.HandleFunc("/debug/pprof/{action}", pprof.Index) + mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) + + if err := http.ListenAndServe(":6060", mux); err != nil { + log.Logger.Fatalf("Error when starting or running http server: %v", err) + } + }() + } bi, ok := debug.ReadBuildInfo() if !ok { From 50bbf2e9ef577a85147652b0b61dd878eafd5431 Mon Sep 17 00:00:00 2001 From: Naveen <172697+naveensrinivasan@users.noreply.github.com> Date: Wed, 10 Nov 2021 18:27:21 -0600 Subject: [PATCH 2/3] Update cmd/rekor-server/app/root.go Co-authored-by: Bob Callaway --- cmd/rekor-server/app/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/rekor-server/app/root.go b/cmd/rekor-server/app/root.go index b1084b9c7..d15b29438 100644 --- a/cmd/rekor-server/app/root.go +++ b/cmd/rekor-server/app/root.go @@ -62,7 +62,7 @@ func init() { rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.rekor-server.yaml)") rootCmd.PersistentFlags().StringVar(&logType, "log_type", "dev", "logger type to use (dev/prod)") - rootCmd.PersistentFlags().BoolVar(&enablePprof, "enable_pprof", false, "enable pprof for profiling") + rootCmd.PersistentFlags().BoolVar(&enablePprof, "enable_pprof", false, "enable pprof for profiling on port 6060") rootCmd.PersistentFlags().String("trillian_log_server.address", "127.0.0.1", "Trillian log server address") rootCmd.PersistentFlags().Uint16("trillian_log_server.port", 8090, "Trillian log server port") From e5e27547e4355a496c2fcb5d54668733f06abe4f Mon Sep 17 00:00:00 2001 From: Naveen <172697+naveensrinivasan@users.noreply.github.com> Date: Wed, 10 Nov 2021 18:27:40 -0600 Subject: [PATCH 3/3] Update cmd/rekor-server/app/root.go Co-authored-by: Bob Callaway --- cmd/rekor-server/app/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/rekor-server/app/root.go b/cmd/rekor-server/app/root.go index d15b29438..92aa60bdc 100644 --- a/cmd/rekor-server/app/root.go +++ b/cmd/rekor-server/app/root.go @@ -104,7 +104,7 @@ func init() { mux.HandleFunc("/debug/pprof/{action}", pprof.Index) mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) - if err := http.ListenAndServe(":6060", mux); err != nil { + if err := http.ListenAndServe(":6060", mux); err != nil && err != http.ErrServerClosed { log.Logger.Fatalf("Error when starting or running http server: %v", err) } }()