From b55b87cdb3faa5f80eb8d9e6413e81503ee624c6 Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov Date: Thu, 15 Aug 2024 12:44:27 +0500 Subject: [PATCH] Added pprof config Signed-off-by: Vladislav Byrgazov --- .golangci.yml | 2 +- README.md | 2 ++ internal/imports/imports_linux.go | 1 + main.go | 12 +++++++++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index eeb7dfdd..0257f365 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -30,7 +30,7 @@ linters-settings: goimports: local-prefixes: github.com/networkservicemesh gocyclo: - min-complexity: 15 + min-complexity: 20 maligned: suggest-new: true dupl: diff --git a/README.md b/README.md index 69167e48..2dfdce67 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ Also it works as a device plugin server providing resources for the client pods. * `NSM_METRICS_EXPORT_INTERVAL` - interval between mertics exports * `NSM_OPEN_TELEMETRY_ENDPOINT` - OpenTelemetry Collector Endpoint * `NSM_REGISTRY_CLIENT_POLICIES` - paths to files and directories that contain registry client policies +* `NSM_PPROF_ENABLED` - is pprof enabled (default: "false") +* `NSM_PPROF_LISTEN_ON` - pprof URL to ListenAndServe (default: "localhost:6060") ## Config file diff --git a/internal/imports/imports_linux.go b/internal/imports/imports_linux.go index 2fd1f59a..cdefbcf1 100644 --- a/internal/imports/imports_linux.go +++ b/internal/imports/imports_linux.go @@ -38,6 +38,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/pprofutils" _ "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 8e340ea7..3eec8fa2 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,6 @@ // Copyright (c) 2020-2022 Doc.ai and/or its affiliates. // -// Copyright (c) 2023 Cisco and/or its affiliates. +// Copyright (c) 2023-2024 Cisco and/or its affiliates. // // Copyright (c) 2024 OpenInfra Foundation Europe. All rights reserved. // @@ -62,6 +62,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" monitorauthorize "github.com/networkservicemesh/sdk/pkg/tools/monitorconnection/authorize" "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" @@ -89,6 +90,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() { @@ -168,6 +171,13 @@ func main() { }() } + // ******************************************************************************** + // Configure pprof + // ******************************************************************************** + if config.PprofEnabled { + go pprofutils.ListenAndServe(ctx, config.PprofListenOn) + } + // ******************************************************************************** log.FromContext(ctx).Infof("executing phase 2: get SR-IOV config from file (time since start: %s)", time.Since(starttime)) // ********************************************************************************