Skip to content

Commit

Permalink
Merge pull request #257 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 16, 2024
2 parents 336afc5 + 492a62e commit af4d051
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ docker build .
* `NSM_FEDERATES_WITH` - Name of the federated domain (default: "k8s.nsm")
* `NSM_TRUST_DOMAIN` - Name of the trust domain (default: "docker.nsm")
* `NSM_LOG_LEVEL` - Log level (default: "INFO")
* `NSM_PPROF_ENABLED` - is pprof enabled (default: "false")
* `NSM_PPROF_LISTEN_ON` - pprof URL to ListenAndServe (default: "localhost:6060")

# Testing

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: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/interdomain"
"github.com/networkservicemesh/sdk/pkg/tools/log"
"github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger"
"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"
Expand Down Expand Up @@ -108,6 +109,8 @@ type Config struct {
FederatesWith string `default:"k8s.nsm" desc:"Name of the federated domain" split_words:"true"`
TrustDomain string `default:"docker.nsm" desc:"Name of the trust domain" split_words:"true"`
LogLevel string `default:"INFO" desc:"Log level" 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"`
}

// Process prints and processes env to config
Expand Down Expand Up @@ -174,6 +177,11 @@ func main() {
}
logrus.SetLevel(level)

// 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")
// ********************************************************************************
Expand Down

0 comments on commit af4d051

Please sign in to comment.