From 573c24c967cde96cd14f01e34f8665847e5226a9 Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov Date: Thu, 15 Aug 2024 13:42:06 +0500 Subject: [PATCH] Added pprof config Signed-off-by: Vladislav Byrgazov --- .golangci.yml | 2 +- README.md | 2 ++ internal/pkg/imports/imports_linux.go | 1 + main.go | 12 ++++++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 70f6111..4b047d1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -30,7 +30,7 @@ linters-settings: goimports: local-prefixes: github.com/networkservicemesh gocyclo: - min-complexity: 15 + min-complexity: 20 maligned: suggest-new: true dupl: diff --git a/README.md b/README.md index 2165344..5c3560d 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ docker build . * `NSM_LOG_LEVEL` - Log level (default: "INFO") * `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_LISTEN_ON` - pprof URL to ListenAndServe (default: "localhost:6060") # Testing diff --git a/internal/pkg/imports/imports_linux.go b/internal/pkg/imports/imports_linux.go index 7e32771..2151d0b 100644 --- a/internal/pkg/imports/imports_linux.go +++ b/internal/pkg/imports/imports_linux.go @@ -46,6 +46,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/spiffejwt" _ "github.com/networkservicemesh/sdk/pkg/tools/spire" _ "github.com/networkservicemesh/sdk/pkg/tools/token" diff --git a/main.go b/main.go index 4085a36..f535553 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,8 @@ // // Copyright (c) 2024 OpenInfra Foundation Europe. All rights reserved. // +// Copyright (c) 2024 Pragmagic Inc. and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -75,6 +77,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/spiffejwt" "github.com/networkservicemesh/sdk/pkg/tools/token" "github.com/networkservicemesh/sdk/pkg/tools/tracing" @@ -99,6 +102,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"` } // Process prints and processes env to config @@ -181,6 +186,13 @@ func main() { }() } + // ******************************************************************************** + // Configure pprof + // ******************************************************************************** + if config.PprofEnabled { + go pprofutils.ListenAndServe(ctx, config.PprofListenOn) + } + // ******************************************************************************** log.FromContext(ctx).Infof("executing phase 2: retrieving svid, check spire agent logs if this is the last line you see") // ********************************************************************************