Skip to content

Commit 0c8d4d1

Browse files
author
Vladislav Byrgazov
committed
Added pprof config
Signed-off-by: Vladislav Byrgazov <vladislav.byrgazov@xored.com>
1 parent c796359 commit 0c8d4d1

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ docker build .
3333
* `NSM_TARGET_PORT` - TCP/UDP target port
3434
* `NSM_PROTOCOL` - TCP or UDP protocol
3535
* `NSM_SELECTOR` - labels for the load balancer selector labels
36+
* `NSM_PPROF_ENABLED` - is pprof enabled (default: "false")
37+
* `NSM_PPROF_LISTEN_ON` - pprof URL to ListenAndServe (default: "localhost:6060")
3638

3739
# Testing
3840

internal/config/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2023 Cisco and/or its affiliates.
1+
// Copyright (c) 2023-2024 Cisco and/or its affiliates.
22
//
33
// Copyright (c) 2024 OpenInfra Foundation Europe. All rights reserved.
44
//
@@ -41,6 +41,8 @@ type Config struct {
4141
LogLevel string `default:"INFO" desc:"Log level" split_words:"true"`
4242
OpenTelemetryEndpoint string `default:"otel-collector.observability.svc.cluster.local:4317" desc:"OpenTelemetry Collector Endpoint" split_words:"true"`
4343
MetricsExportInterval time.Duration `default:"10s" desc:"interval between mertics exports" split_words:"true"`
44+
PprofEnabled bool `default:"false" desc:"is pprof enabled" split_words:"true"`
45+
PprofListenOn string `default:"localhost:6060" desc:"pprof URL to ListenAndServe" split_words:"true"`
4446

4547
Port uint16 `default:"" desc:"TCP/UDP service port" split_words:"true"`
4648
TargetPort uint16 `default:"" desc:"TCP/UDP target port" split_words:"true"`

internal/imports/imports_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
_ "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger"
2929
_ "github.com/networkservicemesh/sdk/pkg/tools/nsurl"
3030
_ "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry"
31+
_ "github.com/networkservicemesh/sdk/pkg/tools/pprofutils"
3132
_ "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt"
3233
_ "github.com/networkservicemesh/sdk/pkg/tools/token"
3334
_ "github.com/networkservicemesh/sdk/pkg/tools/tracing"

main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import (
6060
"github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger"
6161
"github.com/networkservicemesh/sdk/pkg/tools/nsurl"
6262
"github.com/networkservicemesh/sdk/pkg/tools/opentelemetry"
63+
"github.com/networkservicemesh/sdk/pkg/tools/pprofutils"
6364
"github.com/networkservicemesh/sdk/pkg/tools/spiffejwt"
6465
"github.com/networkservicemesh/sdk/pkg/tools/token"
6566
"github.com/networkservicemesh/sdk/pkg/tools/tracing"
@@ -128,6 +129,13 @@ func main() {
128129
}()
129130
}
130131

132+
// ********************************************************************************
133+
// Configure pprof
134+
// ********************************************************************************
135+
if c.PprofEnabled {
136+
go pprofutils.ListenAndServe(ctx, c.PprofListenOn)
137+
}
138+
131139
// ********************************************************************************
132140
log.FromContext(ctx).Infof("executing phase 2: run vpp and get a connection to it (time since start: %s)", time.Since(starttime))
133141
// ********************************************************************************

0 commit comments

Comments
 (0)