mirror of
https://github.com/versity/versitygw.git
synced 2026-09-04 23:26:57 +00:00
feat: add optional pprof debug endpoint
Fixes #359. This adds the pprof listening endpoint when configured. The option requires providing the listening port. Once enabled, pprof debug utilities are provided at this endpoint. For example, adding to following option: --pprof 127.0.0.1:9999 Creates a listener on localhost port 9999. You can then point a browser to http://localhost:9999/debug/pprof/ to get access to the debug utilities. Another useful case is to get goroutine stack traces live with the following: curl 'http://localhost:9999/debug/pprof/goroutine?debug=1'
This commit is contained in:
@@ -19,6 +19,8 @@ import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
@@ -44,6 +46,7 @@ var (
|
||||
accessLog string
|
||||
healthPath string
|
||||
debug bool
|
||||
pprof string
|
||||
quiet bool
|
||||
iamDir string
|
||||
ldapURL, ldapBindDN, ldapPassword string
|
||||
@@ -187,6 +190,12 @@ func initFlags() []cli.Flag {
|
||||
EnvVars: []string{"VGW_DEBUG"},
|
||||
Destination: &debug,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "pprof",
|
||||
Usage: "enable pprof debug on specified port",
|
||||
EnvVars: []string{"VGW_PPROF"},
|
||||
Destination: &pprof,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "quiet",
|
||||
Usage: "silence stdout request logging output",
|
||||
@@ -373,6 +382,14 @@ func runGateway(ctx context.Context, be backend.Backend) error {
|
||||
return fmt.Errorf("root user access and secret key must be provided")
|
||||
}
|
||||
|
||||
if pprof != "" {
|
||||
// listen on specified port for pprof debug
|
||||
// point browser to http://<ip:port>/debug/pprof/
|
||||
go func() {
|
||||
log.Fatal(http.ListenAndServe(pprof, nil))
|
||||
}()
|
||||
}
|
||||
|
||||
app := fiber.New(fiber.Config{
|
||||
AppName: "versitygw",
|
||||
ServerHeader: "VERSITYGW",
|
||||
|
||||
Reference in New Issue
Block a user