Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration for turning profiling on/off #92

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
@@ -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.
//
Expand Down Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions internal/imports/imports_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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))
// ********************************************************************************
Expand Down
Loading