Skip to content
Open
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
33 changes: 33 additions & 0 deletions management/cmd/pprof.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//go:build pprof
// +build pprof

package cmd

import (
"net/http"
_ "net/http/pprof"
"os"

log "github.com/sirupsen/logrus"
)

func init() {
addr := pprofAddr()
go pprof(addr)
}

func pprofAddr() string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be better to centralize the duplicated functions into a shared package

listenAddr := os.Getenv("NB_PPROF_ADDR")
if listenAddr == "" {
return "localhost:6060"
}

return listenAddr
}

func pprof(listenAddr string) {
log.Infof("listening pprof on: %s\n", listenAddr)
if err := http.ListenAndServe(listenAddr, nil); err != nil {
log.Fatalf("Failed to start pprof: %v", err)
}
}
7 changes: 0 additions & 7 deletions management/main.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package main

import (
"log"
"net/http"
// nolint:gosec
_ "net/http/pprof"
"os"

"github.com/netbirdio/netbird/management/cmd"
)

func main() {
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
if err := cmd.Execute(); err != nil {
os.Exit(1)
}
Expand Down
33 changes: 33 additions & 0 deletions signal/cmd/pprof.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//go:build pprof
// +build pprof

package cmd

import (
"net/http"
_ "net/http/pprof"
"os"

log "github.com/sirupsen/logrus"
)

func init() {
addr := pprofAddr()
go pprof(addr)
}

func pprofAddr() string {
listenAddr := os.Getenv("NB_PPROF_ADDR")
if listenAddr == "" {
return "localhost:6060"
}

return listenAddr
}

func pprof(listenAddr string) {
log.Infof("listening pprof on: %s\n", listenAddr)
if err := http.ListenAndServe(listenAddr, nil); err != nil {
log.Fatalf("Failed to start pprof: %v", err)
}
}
14 changes: 1 addition & 13 deletions signal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"fmt"
"net"
"net/http"
// nolint:gosec
_ "net/http/pprof"

"time"

"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
Expand Down Expand Up @@ -92,8 +91,6 @@ var (
RunE: func(cmd *cobra.Command, args []string) error {
flag.Parse()

startPprof()

opts, certManager, tlsConfig, err := getTLSConfigurations()
if err != nil {
return err
Expand Down Expand Up @@ -194,15 +191,6 @@ var (
}
)

func startPprof() {
go func() {
log.Debugf("Starting pprof server on 127.0.0.1:6060")
if err := http.ListenAndServe("127.0.0.1:6060", nil); err != nil {
log.Fatalf("pprof server failed: %v", err)
}
}()
}

func getTLSConfigurations() ([]grpc.ServerOption, *autocert.Manager, *tls.Config, error) {
var (
err error
Expand Down