From 0c456d7a39bc93f43b15cb7e533d497a2e59c5db Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov Date: Thu, 15 Aug 2024 12:20:18 +0500 Subject: [PATCH] Added pprof config Signed-off-by: Vladislav Byrgazov --- README.md | 2 ++ internal/config/config.go | 4 +++- internal/imports/imports_linux.go | 1 + main.go | 8 +++++++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d95e809..176f799 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ This driver mounts a directory containing a Network Service API socket as an eph * `NSM_SOCKET_DIR` - Path to the NSM API socket directory * `NSM_CSI_SOCKET_PATH` - Path to the CSI socket (default: "/nsm-csi/csi.sock") * `NSM_VERSION` - Version (default: "undefined") +* `NSM_PPROF_ENABLED` - is pprof enabled (default: "false") +* `NSM_PPROF_LISTEN_ON` - pprof URL to ListenAndServe (default: "localhost:6060") ## How it Works diff --git a/internal/config/config.go b/internal/config/config.go index 33ed9fb..f6ef140 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,4 +1,4 @@ -// Copyright (c) 2023 Cisco and/or its affiliates. +// Copyright (c) 2023-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -28,6 +28,8 @@ type Config struct { SocketDir string `default:"" desc:"Path to the NSM API socket directory" split_words:"true"` CSISocketPath string `default:"/nsm-csi/csi.sock" desc:"Path to the CSI socket" split_words:"true"` Version string `default:"undefined" desc:"Version"` + PprofEnabled bool `default:"false" desc:"is pprof enabled" split_words:"true"` + PprofListenOn string `default:"localhost:6060" desc:"pprof URL to ListenAndServe" split_words:"true"` } // IsValid - check if configuration is valid diff --git a/internal/imports/imports_linux.go b/internal/imports/imports_linux.go index 707dece..b7883d3 100644 --- a/internal/imports/imports_linux.go +++ b/internal/imports/imports_linux.go @@ -8,6 +8,7 @@ import ( _ "github.com/container-storage-interface/spec/lib/go/csi" _ "github.com/kelseyhightower/envconfig" _ "github.com/networkservicemesh/sdk/pkg/tools/log" + _ "github.com/networkservicemesh/sdk/pkg/tools/pprofutils" _ "github.com/pkg/errors" _ "github.com/spiffe/spiffe-csi/pkg/mount" _ "github.com/stretchr/testify/assert" diff --git a/main.go b/main.go index 0f1b073..3f46de2 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,4 @@ -// Copyright (c) 2023 Cisco and/or its affiliates. +// Copyright (c) 2023-2024 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -26,6 +26,7 @@ import ( "github.com/networkservicemesh/cmd-csi-driver/pkg/logkeys" "github.com/networkservicemesh/cmd-csi-driver/pkg/server" "github.com/networkservicemesh/sdk/pkg/tools/log" + "github.com/networkservicemesh/sdk/pkg/tools/pprofutils" ) func main() { @@ -42,6 +43,11 @@ func main() { logger.Fatalf("error processing rootConf from env: %+v", err) } + // Configure pprof + if c.PprofEnabled { + go pprofutils.ListenAndServe(ctx, c.PprofListenOn) + } + logger.WithField(logkeys.Version, c.Version). WithField(logkeys.NodeID, c.NodeName). WithField(logkeys.NSMSocketDir, c.SocketDir).