From b01f90013032125e0505891581df5af862f1b048 Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov Date: Wed, 14 Aug 2024 12:48:36 +0500 Subject: [PATCH] Updated pprof config Signed-off-by: Vladislav Byrgazov --- .golangci.yml | 2 +- README.md | 2 ++ internal/imports/imports_linux.go | 1 + main.go | 10 +++++++++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 6ff53fc..5ef3bd5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -36,7 +36,7 @@ linters-settings: dupl: threshold: 150 funlen: - Lines: 120 + Lines: 140 Statements: 50 goconst: min-len: 2 diff --git a/README.md b/README.md index 5493d87..ea0f0d9 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ docker build . * `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") # Testing diff --git a/internal/imports/imports_linux.go b/internal/imports/imports_linux.go index c105508..7d023f7 100644 --- a/internal/imports/imports_linux.go +++ b/internal/imports/imports_linux.go @@ -17,6 +17,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" diff --git a/main.go b/main.go index 5bd1c62..dc04462 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. // @@ -56,6 +56,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/listenonurl" "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-nsmgr-proxy @@ -71,6 +72,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() { @@ -128,6 +131,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 {