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: Vladislav Byrgazov <vladislav.byrgazov@xored.com>
  • Loading branch information
Vladislav Byrgazov committed Jul 25, 2024
1 parent 2d2da79 commit 3f7aed6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ docker build .
* `NSM_DIAL_TIMEOUT` - Timeout for the dial the next endpoint
* `NSM_OPEN_TELEMETRY_ENDPOINT` - OpenTelemetry Collector Endpoint
* `NSM_METRICS_EXPORT_INTERVAL` - interval between mertics exports
* `NSM_PPROF_ENABLED` - is pprof enabled (default: "false")
* `NSM_PPROF_PORT` - pprof port (default: "6060")
* `NSM_TUNNEL_IP` - IP to use for tunnels
* `NSM_VXLAN_PORT` - VXLAN port to use
* `NSM_VPP_API_SOCKET` - filename of socket to connect to existing VPP instance.
Expand Down
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type Config struct {
DialTimeout time.Duration `default:"750ms" desc:"Timeout for the dial the next endpoint" 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"`
PprofPort string `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"`
Expand Down
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ package main
import (
"context"
"crypto/tls"
"net/http"
"net/http/pprof"
"os"
"os/signal"
"path"
Expand Down Expand Up @@ -149,6 +151,20 @@ func main() {
}()
}

// ********************************************************************************
// Configure pprof
// ********************************************************************************
if cfg.PprofEnabled {
go func() {
http.HandleFunc("/debug/pprof/", pprof.Index)
http.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
http.HandleFunc("/debug/pprof/profile", pprof.Profile)
http.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
http.HandleFunc("/debug/pprof/trace", pprof.Trace)
http.ListenAndServe("localhost:"+cfg.PprofPort, nil)

Check failure on line 164 in main.go

View workflow job for this annotation

GitHub Actions / golangci-lint / golangci-lint

Error return value of `http.ListenAndServe` is not checked (errcheck)
}()
}

// ********************************************************************************
log.FromContext(ctx).Infof("executing phase 2: run vpp and get a connection to it (time since start: %s)", time.Since(starttime))
// ********************************************************************************
Expand Down

0 comments on commit 3f7aed6

Please sign in to comment.