Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Included pprof for profiling the application. #485

Merged
merged 3 commits into from
Nov 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions cmd/rekor-server/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package app

import (
"fmt"
"net/http"
"net/http/pprof"
"os"
"runtime/debug"

Expand All @@ -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{
Expand Down Expand Up @@ -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 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")
Expand Down Expand Up @@ -88,6 +94,21 @@ func init() {
if GitVersion != "devel" {
return
}
log.Logger.Debugf("pprof enabled %v", enablePprof)
// Enable pprof
if enablePprof {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to check if the user has requested port 6060 for the main rekor endpoint and give a helpful error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I would pass on this because this flag has to be turned on and the default rekor endpoint port has to be set to 6060. The odds of that happening are less IMO. Also, we have included the docs in the command line it could help someone debug.

Thoughts?

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 && err != http.ErrServerClosed {
log.Logger.Fatalf("Error when starting or running http server: %v", err)
}
}()
}

bi, ok := debug.ReadBuildInfo()
if !ok {
Expand Down