diff --git a/README.md b/README.md index 5ae002c..0ebb8da 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ docker build . * `NSM_TARGET_PORT` - TCP/UDP target port * `NSM_PROTOCOL` - TCP or UDP protocol * `NSM_SELECTOR` - labels for the load balancer selector labels +* `NSM_PPROF_ENABLED` - is pprof enabled (default: "false") +* `NSM_PPROF_LISTEN_ON` - pprof URL to ListenAndServe (default: "localhost:6060") # Testing diff --git a/internal/config/config.go b/internal/config/config.go index 3063315..88f7d3d 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. // // Copyright (c) 2024 OpenInfra Foundation Europe. All rights reserved. // @@ -41,6 +41,8 @@ type Config struct { LogLevel string `default:"INFO" desc:"Log level" 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"` + PprofListenOn string `default:"localhost:6060" desc:"pprof URL to ListenAndServe" split_words:"true"` Port uint16 `default:"" desc:"TCP/UDP service port" split_words:"true"` TargetPort uint16 `default:"" desc:"TCP/UDP target port" split_words:"true"` diff --git a/internal/imports/imports_linux.go b/internal/imports/imports_linux.go index 31a7977..c8a940b 100644 --- a/internal/imports/imports_linux.go +++ b/internal/imports/imports_linux.go @@ -28,6 +28,7 @@ import ( _ "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" _ "github.com/networkservicemesh/sdk/pkg/tools/nsurl" _ "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" + _ "github.com/networkservicemesh/sdk/pkg/tools/pprofutils" _ "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt" _ "github.com/networkservicemesh/sdk/pkg/tools/token" _ "github.com/networkservicemesh/sdk/pkg/tools/tracing" diff --git a/main.go b/main.go index 97796e5..17be1ea 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 // @@ -60,6 +60,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" "github.com/networkservicemesh/sdk/pkg/tools/nsurl" "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" + "github.com/networkservicemesh/sdk/pkg/tools/pprofutils" "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt" "github.com/networkservicemesh/sdk/pkg/tools/token" "github.com/networkservicemesh/sdk/pkg/tools/tracing" @@ -128,6 +129,13 @@ func main() { }() } + // ******************************************************************************** + // Configure pprof + // ******************************************************************************** + if c.PprofEnabled { + go pprofutils.ListenAndServe(ctx, c.PprofListenOn) + } + // ******************************************************************************** log.FromContext(ctx).Infof("executing phase 2: run vpp and get a connection to it (time since start: %s)", time.Since(starttime)) // ********************************************************************************