diff --git a/README.md b/README.md index edecd8e6..c615c300 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ docker build . * `NSM_DIAL_TIMEOUT` - Timeout for the dial the next endpoint * `NSM_OPEN_TELEMETRY_ENDPOINT` - OpenTelemetry Collector Endpoint * `NSM_METRICS_EXPORT_INTERVAL` - interval between mertics exports +* `NSM_PPROF_ENABLED` - is pprof enabled (default: "false") +* `NSM_PPROF_PORT` - pprof port (default: "6060") * `NSM_TUNNEL_IP` - IP to use for tunnels * `NSM_VXLAN_PORT` - VXLAN port to use * `NSM_VPP_API_SOCKET` - filename of socket to connect to existing VPP instance. diff --git a/internal/config/config.go b/internal/config/config.go index 9e9c5498..2fca9df6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -47,6 +47,8 @@ type Config struct { DialTimeout time.Duration `default:"750ms" desc:"Timeout for the dial the next endpoint" split_words:"true"` OpenTelemetryEndpoint string `default:"otel-collector.observability.svc.cluster.local:4317" desc:"OpenTelemetry Collector Endpoint" split_words:"true"` MetricsExportInterval time.Duration `default:"10s" desc:"interval between mertics exports" split_words:"true"` + PprofEnabled bool `default:"false" desc:"is pprof enabled" split_words:"true"` + PprofPort uint16 `default:"6060" desc:"pprof port" split_words:"true"` TunnelIP net.IP `desc:"IP to use for tunnels" split_words:"true"` VxlanPort uint16 `default:"0" desc:"VXLAN port to use" split_words:"true"` diff --git a/internal/imports/imports_linux.go b/internal/imports/imports_linux.go index 6c94703b..9beadc89 100644 --- a/internal/imports/imports_linux.go +++ b/internal/imports/imports_linux.go @@ -85,6 +85,7 @@ import ( _ "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" _ "github.com/networkservicemesh/sdk/pkg/tools/monitorconnection/authorize" _ "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" + _ "github.com/networkservicemesh/sdk/pkg/tools/pprof" _ "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt" _ "github.com/networkservicemesh/sdk/pkg/tools/spire" _ "github.com/networkservicemesh/sdk/pkg/tools/token" diff --git a/main.go b/main.go index dcea1705..68ab48c7 100644 --- a/main.go +++ b/main.go @@ -59,6 +59,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" authmonitor "github.com/networkservicemesh/sdk/pkg/tools/monitorconnection/authorize" "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" + "github.com/networkservicemesh/sdk/pkg/tools/pprof" "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt" "github.com/networkservicemesh/sdk/pkg/tools/token" "github.com/networkservicemesh/sdk/pkg/tools/tracing" @@ -149,6 +150,13 @@ func main() { }() } + // ******************************************************************************** + // Configure pprof + // ******************************************************************************** + if cfg.PprofEnabled { + go pprof.Init(ctx, cfg.PprofPort) + } + // ******************************************************************************** log.FromContext(ctx).Infof("executing phase 2: run vpp and get a connection to it (time since start: %s)", time.Since(starttime)) // ********************************************************************************