diff --git a/.golangci.yml b/.golangci.yml index d545860..56cddf1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -36,7 +36,7 @@ linters-settings: dupl: threshold: 150 funlen: - Lines: 110 + Lines: 130 Statements: 50 goconst: min-len: 2 diff --git a/README.md b/README.md index 8d0805f..b47ab6e 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,5 @@ * `NSM_LOG_LEVEL` - Log level (default: "INFO") * `NSM_OPEN_TELEMETRY_ENDPOINT` - OpenTelemetry Collector Endpoint (default: "otel-collector.observability.svc.cluster.local:4317") * `NSM_METRICS_EXPORT_INTERVAL` - interval between mertics exports (default: "10s") +* `NSM_PPROF_ENABLED` - is pprof enabled (default: "false") +* `NSM_PPROF_LISTEN_ON` - pprof URL to ListenAndServe (default: "localhost:6060") diff --git a/main.go b/main.go index 8354774..ba87b43 100644 --- a/main.go +++ b/main.go @@ -53,6 +53,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/grpcutils" "github.com/networkservicemesh/sdk/pkg/tools/log" "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" + "github.com/networkservicemesh/sdk/pkg/tools/pprofutils" ) // Config is configuration for cmd-registry-memory @@ -66,6 +67,8 @@ type Config struct { LogLevel string `default:"INFO" desc:"Log level" 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() { @@ -122,6 +125,11 @@ func main() { }() } + // Configure pprof + if config.PprofEnabled { + go pprofutils.ListenAndServe(ctx, config.PprofListenOn) + } + // Get a X509Source source, err := workloadapi.NewX509Source(ctx) if err != nil { diff --git a/pkg/imports/imports_linux.go b/pkg/imports/imports_linux.go index 41731b4..444dc9c 100644 --- a/pkg/imports/imports_linux.go +++ b/pkg/imports/imports_linux.go @@ -23,6 +23,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/networkservicemesh/sdk/pkg/tools/spiffejwt" _ "github.com/networkservicemesh/sdk/pkg/tools/spire" _ "github.com/networkservicemesh/sdk/pkg/tools/token"