Skip to content

Commit

Permalink
Add configuration for turning profiling on/off.
Browse files Browse the repository at this point in the history
Signed-off-by: Vitaliy Guschin <vitaliy.guschin@spirent.com>
  • Loading branch information
Vitaliy Guschin committed May 23, 2024
1 parent 683d253 commit 9cfb7c7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
6 changes: 5 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ linters-settings:
dupl:
threshold: 150
funlen:
lines: 120
lines: 130
statements: 60
goconst:
min-len: 2
Expand All @@ -57,6 +57,10 @@ linters-settings:
simple: true
range-loops: true
for-loops: false
gosec:
excludes:
- G108
- G114
gocritic:
enabled-checks:
- appendAssign
Expand Down
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_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_KUBELET_QPS` - kubelet config settings (default: "205")
* `NSM_ENABLE_PROFILER` - Enable pprof package HTTP server for profiling runtime data.
* `NSM_PROFILER_HTTP_PORT` - Profiling server HTTP port providing data in the format expected by the pprof visualization tool.

# Testing

Expand Down
20 changes: 19 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package main
import (
"context"
"crypto/tls"
"fmt"
"net/url"
"os"
"os/signal"
Expand Down Expand Up @@ -52,6 +53,9 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
"github.com/networkservicemesh/sdk/pkg/tools/log"
"github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger"

"net/http"
_ "net/http/pprof"
)

// Config is configuration for cmd-registry-memory
Expand All @@ -70,7 +74,9 @@ type Config struct {
// FWD Refreshes: 1 refresh per sec. * 5 fwds
// NSC Refreshes: 4 finds (in 1 refresh) per sec. * 40 nscs
// Total: = 205
KubeletQPS int `default:"205" desc:"kubelet config settings" split_words:"true"`
KubeletQPS int `default:"205" desc:"kubelet config settings" split_words:"true"`
EnableProfiler bool `default:"false" desc:"Enable pprof package HTTP server for profiling runtime data. The handled paths all begin with /debug/pprof/." split_words:"true"`
ProfilerHTTPPort uint16 `default:"6060" desc:"Profiling server HTTP port providing data in the format expected by the pprof visualization tool." split_words:"true"`
}

func main() {
Expand Down Expand Up @@ -113,6 +119,18 @@ func main() {
logrus.SetLevel(l)
log.FromContext(ctx).Infof("Config: %#v", config)

// Enable profiling server
if config.EnableProfiler {
go func() {
log.FromContext(ctx).Infof("Profiler is enabled. Starting HTTP server on %d", config.ProfilerHTTPPort)

address := fmt.Sprintf("localhost:%d", config.ProfilerHTTPPort)
if err = http.ListenAndServe(address, nil); err != nil {
log.FromContext(ctx).Errorf("Failed to start profiler: %s", err.Error())
}
}()
}

// Configure Open Telemetry
if opentelemetry.IsEnabled() {
collectorAddress := config.OpenTelemetryEndpoint
Expand Down
31 changes: 0 additions & 31 deletions pkg/internal/imports/imports_linux.go

This file was deleted.

0 comments on commit 9cfb7c7

Please sign in to comment.