From caa1e07fc9ce07ccf440f6be1fea7c6ba728d3e9 Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov Date: Thu, 15 Aug 2024 13:08:56 +0500 Subject: [PATCH] Added pprof config Signed-off-by: Vladislav Byrgazov --- README.md | 2 ++ internal/pkg/imports/imports_linux.go | 1 + main.go | 12 +++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b8853cd..cd6194c 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ docker build . * `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_RULES_CONFIG_PATH` - Path to a configmap with iptables rules +* `NSM_PPROF_ENABLED` - is pprof enabled (default: "false") +* `NSM_PPROF_LISTEN_ON` - pprof URL to ListenAndServe (default: "localhost:6060") # Testing diff --git a/internal/pkg/imports/imports_linux.go b/internal/pkg/imports/imports_linux.go index 7058e3b..5417612 100644 --- a/internal/pkg/imports/imports_linux.go +++ b/internal/pkg/imports/imports_linux.go @@ -33,6 +33,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/token" _ "github.com/networkservicemesh/sdk/pkg/tools/tracing" diff --git a/main.go b/main.go index 3e2576a..b99a1af 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,6 @@ // Copyright (c) 2022-2023 Xored Software Inc and others. // -// Copyright (c) 2023 Cisco Software Inc and others. +// Copyright (c) 2023-2024 Cisco Software Inc and others. // // Copyright (c) 2024 Nordix Foundation. // @@ -37,6 +37,7 @@ import ( nested "github.com/antonfisher/nested-logrus-formatter" "github.com/edwarnicke/grpcfd" "github.com/kelseyhightower/envconfig" + "github.com/networkservicemesh/sdk/pkg/tools/pprofutils" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spiffe/go-spiffe/v2/spiffetls/tlsconfig" @@ -92,6 +93,8 @@ type Config struct { 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"` RulesConfigPath string `default:"" desc:"Path to a configmap with iptables rules" 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"` } // Process prints and processes env to config @@ -186,6 +189,13 @@ func main() { }() } + // ******************************************************************************** + // Configure pprof + // ******************************************************************************** + if config.PprofEnabled { + go pprofutils.ListenAndServe(ctx, config.PprofListenOn) + } + // ******************************************************************************** log.FromContext(ctx).Infof("executing phase 2: retrieving svid, check spire agent logs if this is the last line you see") // ********************************************************************************