diff --git a/cli/flags.go b/cli/flags.go index 52e1c1c..f7a7dc8 100644 --- a/cli/flags.go +++ b/cli/flags.go @@ -139,6 +139,18 @@ var ( EnvVars: []string{"CONFIG_FILE"}, }, + &cli.BoolFlag{ + Name: "enable-profiling", + Usage: "enables the go http profiling endpoints", + EnvVars: []string{"ENABLE_PROFILING"}, + }, + &cli.StringFlag{ + Name: "profiling-address", + Usage: "specify ip address and port the profiling server should listen on", + EnvVars: []string{"PROFILING_ADDRESS"}, + Value: "localhost:9999", + }, + // ############################ // ### ACME Client Settings ### // ############################ diff --git a/server/profiling.go b/server/profiling.go new file mode 100644 index 0000000..7d1971f --- /dev/null +++ b/server/profiling.go @@ -0,0 +1,18 @@ +package server + +import ( + "log" + "net/http" + _ "net/http/pprof" +) + +func StartProfilingServer(listeningAddress string) { + server := &http.Server{ + Addr: listeningAddress, + Handler: http.DefaultServeMux, + } + + go func() { + log.Fatal(server.ListenAndServe()) + }() +} diff --git a/server/startup.go b/server/startup.go index 149a07d..fd89803 100644 --- a/server/startup.go +++ b/server/startup.go @@ -3,7 +3,6 @@ package server import ( "context" "crypto/tls" - "encoding/json" "fmt" "net" "net/http" @@ -43,9 +42,6 @@ func Serve(ctx *cli.Context) error { } log.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger().Level(logLevel) - foo, _ := json.Marshal(cfg) - log.Trace().RawJSON("config", foo).Msg("starting server with config") - listeningSSLAddress := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port) listeningHTTPAddress := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.HttpPort) @@ -133,6 +129,10 @@ func Serve(ctx *cli.Context) error { }() } + if ctx.IsSet("enable-profiling") { + StartProfilingServer(ctx.String("profiling-address")) + } + // Create ssl handler based on settings sslHandler := handler.Handler(cfg.Server, giteaClient, dnsLookupCache, canonicalDomainCache, redirectsCache)