add option to start http server for profiling

pull/323/head
crapStone 2024-04-28 22:46:55 +02:00 zatwierdzone przez crapStone
rodzic ca9433e0ea
commit 52bc59aee9
3 zmienionych plików z 34 dodań i 4 usunięć

Wyświetl plik

@ -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 ###
// ############################

Wyświetl plik

@ -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())
}()
}

Wyświetl plik

@ -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)