diff --git a/README.md b/README.md index 4f13ad3a..83efc158 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ docker build . * `NSM_FORWARDER_NETWORK_SERVICE_NAME` - the default service name for forwarder discovering (default: "forwarder") * `NSM_OPEN_TELEMETRY_ENDPOINT` - OpenTelemetry Collector Endpoint (default: "otel-collector.observability.svc.cluster.local:4317") * `NSM_METRICS_EXPORT_INTERVAL` - interval between mertics exports (default: "10s") +* `NSM_PPROF_ENABLED` - is pprof enabled (default: "false") +* `NSM_PPROF_PORT` - pprof port (default: "6060") # Testing diff --git a/internal/config/config.go b/internal/config/config.go index 3a0e8c32..b8d77893 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -37,4 +37,6 @@ type Config struct { ForwarderNetworkServiceName string `default:"forwarder" desc:"the default service name for forwarder discovering" split_words:"true"` OpenTelemetryEndpoint string `default:"otel-collector.observability.svc.cluster.local:4317" desc:"OpenTelemetry Collector Endpoint" split_words:"true"` MetricsExportInterval time.Duration `default:"10s" desc:"interval between mertics exports" split_words:"true"` + PprofEnabled bool `default:"false" desc:"is pprof enabled" split_words:"true"` + PprofPort uint16 `default:"6060" desc:"pprof port" split_words:"true"` } diff --git a/internal/imports/imports_linux.go b/internal/imports/imports_linux.go index 7aedaeb5..cf6a4c7c 100644 --- a/internal/imports/imports_linux.go +++ b/internal/imports/imports_linux.go @@ -38,6 +38,7 @@ import ( _ "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" _ "github.com/networkservicemesh/sdk/pkg/tools/monitorconnection/authorize" _ "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" + _ "github.com/networkservicemesh/sdk/pkg/tools/pprof" _ "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt" _ "github.com/networkservicemesh/sdk/pkg/tools/spire" _ "github.com/networkservicemesh/sdk/pkg/tools/token" diff --git a/main.go b/main.go index 7e945672..4f8b50a5 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020-2023 Cisco and/or its affiliates. -// // Copyright (c) 2021-2023 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2024 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,6 +33,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/pprof" ) func main() { @@ -88,6 +89,11 @@ func main() { }() } + // Configure pprof + if cfg.PprofEnabled { + go pprof.Init(ctx, cfg.PprofPort) + } + err = manager.RunNsmgr(ctx, cfg) if err != nil { log.FromContext(ctx).Fatalf("error executing rootCmd: %v", err)