From 2402dc8489eef7d1aee06068a96e6626035bdf05 Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov <58589910+Ex4amp1e@users.noreply.github.com> Date: Thu, 8 Aug 2024 19:43:24 +0500 Subject: [PATCH] Add configuration for turning profiling on/off (#693) * Add configuration for turning profiling on/off Signed-off-by: Vladislav Byrgazov * Add additional profiling http handlers Signed-off-by: Vladislav Byrgazov * Enable profiling using networkservicemesh/sdk/pkg/tools/pprof Signed-off-by: Vladislav Byrgazov * Generated imports Signed-off-by: Vladislav Byrgazov --------- Signed-off-by: Vladislav Byrgazov Co-authored-by: Vladislav Byrgazov --- README.md | 2 ++ internal/config/config.go | 2 ++ internal/imports/imports_linux.go | 1 + main.go | 10 ++++++++-- 4 files changed, 13 insertions(+), 2 deletions(-) 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)