diff --git a/README.md b/README.md index adab82c..7b53352 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ docker build . * `NSM_FROM_CONFIG_MAP` - If it's not empty then gets entries from the configmap * `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_LISTEN_ON` - pprof URL to ListenAndServe (default: "localhost:6060") # Testing diff --git a/internal/imports/imports_linux.go b/internal/imports/imports_linux.go index e748054..c3a897c 100644 --- a/internal/imports/imports_linux.go +++ b/internal/imports/imports_linux.go @@ -10,6 +10,7 @@ import ( _ "github.com/networkservicemesh/sdk/pkg/tools/log" _ "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" _ "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" + _ "github.com/networkservicemesh/sdk/pkg/tools/pprofutils" _ "github.com/sirupsen/logrus" _ "github.com/stretchr/testify/require" _ "go.uber.org/goleak" diff --git a/main.go b/main.go index 6e43f44..f78cd62 100644 --- a/main.go +++ b/main.go @@ -44,6 +44,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/log" "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" + "github.com/networkservicemesh/sdk/pkg/tools/pprofutils" ) // Config represents the configuration for cmd-map-ip-k8s application @@ -55,6 +56,8 @@ type Config struct { FromConfigMap string `default:"" desc:"If it's not empty then gets entries from the configmap" 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"` + PprofListenOn string `default:"localhost:6060" desc:"pprof URL to ListenAndServe" split_words:"true"` } func main() { @@ -113,6 +116,13 @@ func main() { }() } + // ******************************************************************************** + // Configure pprof + // ******************************************************************************** + if conf.PprofEnabled { + go pprofutils.ListenAndServe(ctx, conf.PprofListenOn) + } + // ******************************************************************************** // Create client-go // ********************************************************************************