Skip to content

Commit

Permalink
Merge pull request #81 from Ex4amp1e/add-pprof-enable-conf
Browse files Browse the repository at this point in the history
Add configuration for turning profiling on/off
  • Loading branch information
denis-tingaikin authored Aug 15, 2024
2 parents 9b9c169 + 0c456d7 commit 6f970f1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/imports/imports_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down Expand Up @@ -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() {
Expand All @@ -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).
Expand Down

0 comments on commit 6f970f1

Please sign in to comment.