From d22ab08b3aa091c257b188e75c786fee4c94bcac Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov Date: Thu, 15 Aug 2024 13:57:33 +0500 Subject: [PATCH] Added pprof config Signed-off-by: Vladislav Byrgazov --- .golangci.yml | 4 ++-- README.md | 2 ++ internal/imports/imports_linux.go | 1 + main.go | 13 ++++++++++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 240f77c..2a177dc 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -30,13 +30,13 @@ linters-settings: goimports: local-prefixes: github.com/networkservicemesh gocyclo: - min-complexity: 20 + min-complexity: 25 maligned: suggest-new: true dupl: threshold: 150 funlen: - Lines: 230 + Lines: 250 Statements: 110 goconst: min-len: 2 diff --git a/README.md b/README.md index b8f780b..58a5d17 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ docker build . * `NSM_LIVENESS_CHECK_ENABLED` - Dataplane liveness check enabled/disabled (default: "true") * `NSM_LIVENESS_CHECK_INTERVAL` - Dataplane liveness check interval (default: "1200ms") * `NSM_LIVENESS_CHECK_TIMEOUT` - Dataplane liveness check timeout (default: "1s") +* `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 db1e55a..458e977 100644 --- a/internal/imports/imports_linux.go +++ b/internal/imports/imports_linux.go @@ -27,6 +27,7 @@ import ( _ "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" _ "github.com/networkservicemesh/sdk/pkg/tools/nsurl" _ "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 331dddc..a558dc3 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,6 @@ // Copyright (c) 2021-2022 Doc.ai 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. // @@ -63,6 +63,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" "github.com/networkservicemesh/sdk/pkg/tools/nsurl" "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" @@ -84,6 +85,9 @@ type Config struct { LivenessCheckEnabled bool `default:"true" desc:"Dataplane liveness check enabled/disabled" split_words:"true"` LivenessCheckInterval time.Duration `default:"1200ms" desc:"Dataplane liveness check interval" split_words:"true"` LivenessCheckTimeout time.Duration `default:"1s" desc:"Dataplane liveness check timeout" 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() { @@ -153,6 +157,13 @@ func main() { }() } + // ******************************************************************************** + // Configure pprof + // ******************************************************************************** + if config.PprofEnabled { + go pprofutils.ListenAndServe(ctx, config.PprofListenOn) + } + // ******************************************************************************** log.FromContext(ctx).Infof("executing phase 2: run vpp and get a connection to it (time since start: %s)", time.Since(starttime)) // ********************************************************************************