Skip to content

Commit

Permalink
Merge pull request #211 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 612cd3a + 0de0beb commit 6051272
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ docker run --privileged --rm $(docker build -q --target test .)
* `NSM_METRICS_EXPORT_INTERVAL` - interval between mertics exports
* `NSM_PREFIX` - CIDR Prefix to allocate CIDR prefixes for clients
* `NSM_CLIENT_PREFIX_LEN` - Default len of clients prefix
* `NSM_PPROF_ENABLED` - is pprof enabled (default: "false")
* `NSM_PPROF_LISTEN_ON` - pprof URL to ListenAndServe (default: "localhost:6060")

# Debugging

Expand Down
1 change: 1 addition & 0 deletions imports/imports_linux.go

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

10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/log"
"github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger"
"github.com/networkservicemesh/sdk/pkg/tools/opentelemetry"
"github.com/networkservicemesh/sdk/pkg/tools/pprofutils"
"github.com/networkservicemesh/sdk/pkg/tools/tracing"
)

Expand All @@ -51,6 +52,8 @@ type Config struct {
MetricsExportInterval time.Duration `default:"10s" desc:"interval between mertics exports" split_words:"true"`
Prefix string `default:"169.254.0.0/16" desc:"CIDR Prefix to allocate CIDR prefixes for clients" split_words:"true"`
ClientPrefixLen uint8 `default:"24" desc:"Default len of clients prefix" 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() {
Expand Down Expand Up @@ -109,6 +112,13 @@ func main() {
}()
}

// ********************************************************************************
// Configure pprof
// ********************************************************************************
if config.PprofEnabled {
go pprofutils.ListenAndServe(ctx, config.PprofListenOn)
}

source, err := workloadapi.NewX509Source(ctx)
if err != nil {
logrus.Fatalf("error getting x509 source: %+v", err)
Expand Down

0 comments on commit 6051272

Please sign in to comment.