From 22e96d6cb6df9e3c16ef1d13ff1221c12c0d0c42 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 --- README.md | 2 ++ internal/imports/imports_linux.go | 1 + main.go | 13 ++++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) 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..7f75b7d 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. // @@ -37,6 +37,7 @@ import ( "github.com/edwarnicke/debug" "github.com/edwarnicke/grpcfd" "github.com/kelseyhightower/envconfig" + "github.com/networkservicemesh/sdk/pkg/tools/pprofutils" "github.com/sirupsen/logrus" "github.com/spiffe/go-spiffe/v2/spiffetls/tlsconfig" "github.com/spiffe/go-spiffe/v2/workloadapi" @@ -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)) // ********************************************************************************