diff --git a/README.md b/README.md index b1eb3a5..5e956a0 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ docker build . * `NSM_SIDECAR_REQUESTS_MEMORY` - Lower bound of the NSM sidecar requests memory limits (in k8s resource management units) (default: "40Mi") * `NSM_SIDECAR_REQUESTS_CPU` - Lower bound of the NSM sidecar requests CPU limits (in k8s resource management units) (default: "100m") * `NSM_KUBELET_QPS` - kubelet QPS config (default: "50") +* `NSM_PPROF_ENABLED` - is pprof enabled (default: "false") +* `NSM_PPROF_LISTEN_ON` - pprof URL to ListenAndServe (default: "localhost:6060") # Testing diff --git a/internal/config/config.go b/internal/config/config.go index f50e15c..fbdbc86 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -58,6 +58,8 @@ type Config struct { SidecarLimitsCPU string `default:"200m" desc:"Lower bound of the NSM sidecar CPU limit (in k8s resource management units)" split_words:"true"` SidecarRequestsMemory string `default:"40Mi" desc:"Lower bound of the NSM sidecar requests memory limits (in k8s resource management units)" split_words:"true"` SidecarRequestsCPU string `default:"100m" desc:"Lower bound of the NSM sidecar requests CPU limits (in k8s resource management units)" 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"` // QPS for 50 NSC KubeletQPS int `default:"50" desc:"kubelet QPS config" split_words:"true"` envs []corev1.EnvVar diff --git a/internal/imports/imports_linux.go b/internal/imports/imports_linux.go index 943a6f6..aafe7f9 100644 --- a/internal/imports/imports_linux.go +++ b/internal/imports/imports_linux.go @@ -18,6 +18,7 @@ import ( _ "github.com/networkservicemesh/sdk-k8s/pkg/tools/k8s" _ "github.com/networkservicemesh/sdk/pkg/tools/nsurl" _ "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" + _ "github.com/networkservicemesh/sdk/pkg/tools/pprofutils" _ "github.com/pkg/errors" _ "github.com/spiffe/go-spiffe/v2/spiffetls/tlsconfig" _ "github.com/spiffe/go-spiffe/v2/workloadapi" diff --git a/main.go b/main.go index 6e379ce..b65fc59 100644 --- a/main.go +++ b/main.go @@ -58,6 +58,7 @@ import ( kubeutils "github.com/networkservicemesh/sdk-k8s/pkg/tools/k8s" "github.com/networkservicemesh/sdk/pkg/tools/nsurl" "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" + "github.com/networkservicemesh/sdk/pkg/tools/pprofutils" ) var deserializer = serializer.NewCodecFactory(runtime.NewScheme()).UniversalDeserializer() @@ -438,6 +439,11 @@ func main() { }() } + // Configure pprof + if conf.PprofEnabled { + go pprofutils.ListenAndServe(ctx, conf.PprofListenOn) + } + if conf.WebhookMode == config.SelfregisterMode { unregister := registerSelf(ctx, conf, logger) defer func() {