Merge pull request #2482 from flant/profiling-endpoint
feat: enable profiling endpoints
This commit is contained in:
commit
6da5187b47
@ -151,6 +151,8 @@ type Web struct {
|
|||||||
// Telemetry is the config format for telemetry including the HTTP server config.
|
// Telemetry is the config format for telemetry including the HTTP server config.
|
||||||
type Telemetry struct {
|
type Telemetry struct {
|
||||||
HTTP string `json:"http"`
|
HTTP string `json:"http"`
|
||||||
|
// EnableProfiling makes profiling endpoints available via web interface host:port/debug/pprof/
|
||||||
|
EnableProfiling bool `json:"enableProfiling"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GRPC is the config for the gRPC API.
|
// GRPC is the config for the gRPC API.
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@ -368,6 +369,10 @@ func runServe(options serveOptions) error {
|
|||||||
return fmt.Errorf("listening (%s) on %s: %v", name, c.Telemetry.HTTP, err)
|
return fmt.Errorf("listening (%s) on %s: %v", name, c.Telemetry.HTTP, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.Telemetry.EnableProfiling {
|
||||||
|
pprofHandler(telemetryRouter)
|
||||||
|
}
|
||||||
|
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Handler: telemetryRouter,
|
Handler: telemetryRouter,
|
||||||
}
|
}
|
||||||
@ -550,3 +555,11 @@ func applyConfigOverrides(options serveOptions, config *Config) {
|
|||||||
config.Frontend.Dir = os.Getenv("DEX_FRONTEND_DIR")
|
config.Frontend.Dir = os.Getenv("DEX_FRONTEND_DIR")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func pprofHandler(router *http.ServeMux) {
|
||||||
|
router.HandleFunc("/debug/pprof/", pprof.Index)
|
||||||
|
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
|
||||||
|
router.HandleFunc("/debug/pprof/profile", pprof.Profile)
|
||||||
|
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
|
||||||
|
router.HandleFunc("/debug/pprof/trace", pprof.Trace)
|
||||||
|
}
|
||||||
|
@ -63,6 +63,7 @@ web:
|
|||||||
# Configuration for telemetry
|
# Configuration for telemetry
|
||||||
telemetry:
|
telemetry:
|
||||||
http: 0.0.0.0:5558
|
http: 0.0.0.0:5558
|
||||||
|
# enableProfiling: true
|
||||||
|
|
||||||
# Uncomment this block to enable the gRPC API. This values MUST be different
|
# Uncomment this block to enable the gRPC API. This values MUST be different
|
||||||
# from the HTTP endpoints.
|
# from the HTTP endpoints.
|
||||||
|
Reference in New Issue
Block a user