Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions client/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"google.golang.org/grpc/credentials/insecure"

"github.com/netbirdio/netbird/client/internal/profilemanager"
_ "github.com/netbirdio/netbird/util/pprof"
)

const (
Expand Down
1 change: 1 addition & 0 deletions management/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/spf13/cobra"

nbconfig "github.com/netbirdio/netbird/management/internals/server/config"
_ "github.com/netbirdio/netbird/util/pprof"
"github.com/netbirdio/netbird/version"
)

Expand Down
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: 0 additions & 33 deletions relay/cmd/pprof.go

This file was deleted.

1 change: 1 addition & 0 deletions relay/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/netbirdio/netbird/shared/relay/auth"
"github.com/netbirdio/netbird/signal/metrics"
"github.com/netbirdio/netbird/util"
_ "github.com/netbirdio/netbird/util/pprof"
)

type Config struct {
Expand Down
1 change: 1 addition & 0 deletions signal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/spf13/cobra"

_ "github.com/netbirdio/netbird/util/pprof"
"github.com/netbirdio/netbird/version"
)

Expand Down
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
3 changes: 2 additions & 1 deletion signal/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main

import (
"github.com/netbirdio/netbird/signal/cmd"
"os"

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

func main() {
Expand Down
4 changes: 2 additions & 2 deletions client/cmd/pprof.go → util/pprof/pprof.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build pprof
// +build pprof

package cmd
package pprof

import (
"net/http"
Expand All @@ -19,7 +19,7 @@ func init() {
func pprofAddr() string {

Copy link
Copy Markdown
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:6969"
return "localhost:6060"
}

return listenAddr
Expand Down
8 changes: 8 additions & 0 deletions util/pprof/pprof_off.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !pprof

package pprof

/*
Allow package build even without pprof tag.
Otherwise, Go complains that "build constraints exlude all Go files"
*/
Comment thread
ujaandas marked this conversation as resolved.