Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable profiling using networkservicemesh/sdk/pkg/tools/pprof
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Byrgazov <vladislav.byrgazov@xored.com>
Vladislav Byrgazov committed Aug 8, 2024
1 parent 2f0ae30 commit e128a25
Showing 3 changed files with 4 additions and 23 deletions.
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ type Config struct {
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 string `default:"6060" desc:"pprof port" split_words:"true"`
PprofPort uint16 `default:"6060" desc:"pprof port" split_words:"true"`

TunnelIP net.IP `desc:"IP to use for tunnels" split_words:"true"`
VxlanPort uint16 `default:"0" desc:"VXLAN port to use" split_words:"true"`
3 changes: 1 addition & 2 deletions internal/imports/imports_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 2 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
@@ -22,8 +22,6 @@ package main
import (
"context"
"crypto/tls"
"net/http"
"net/http/pprof"
"os"
"os/signal"
"path"
@@ -61,6 +59,7 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger"
authmonitor "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/token"
"github.com/networkservicemesh/sdk/pkg/tools/tracing"
@@ -155,24 +154,7 @@ func main() {
// Configure pprof
// ********************************************************************************
if cfg.PprofEnabled {
log.FromContext(ctx).Infof("Profiler is enabled. Listening on %s", cfg.PprofPort)
mux := http.NewServeMux()
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
server := &http.Server{
Addr: "localhost:" + cfg.PprofPort,
Handler: mux,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
go func() {
if err = server.ListenAndServe(); err != nil {
log.FromContext(ctx).Errorf("Failed to start profiler: %s", err.Error())
}
}()
go pprof.Init(ctx, cfg.PprofPort)
}

// ********************************************************************************

0 comments on commit e128a25

Please sign in to comment.