Skip to content

Commit

Permalink
remove trace calls
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek9686 committed Feb 11, 2025
1 parent 05154fa commit 7a3d0a4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
3 changes: 1 addition & 2 deletions functions/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/logic"
"github.com/gravitl/netmaker/models"
"github.com/gravitl/netmaker/utils"
"golang.org/x/exp/slog"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
Expand Down Expand Up @@ -646,7 +645,7 @@ func UpdateKeys() error {

func holePunchWgPort(proto, portToStun int) (pubIP net.IP, pubPort int, natType string) {
defer func() {
utils.TraceCaller()
//ncutils.TraceCaller()
slog.Debug("holePunchWgPort", "proto", proto, "PortToStun", portToStun, "PubIP", pubIP.String(), "PubPort", pubPort, "NatType", natType)
}()
server := config.GetServer(config.CurrServer)
Expand Down
2 changes: 1 addition & 1 deletion functions/fail_over.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func getPeerInfo() (models.HostPeerInfo, error) {
logger.Log(0, "status error calling ", endpoint.URL, errData.Message)
return models.HostPeerInfo{}, err
}
logger.Log(1, "failed to read from server during metrics publish", err.Error())
slog.Error("failed to read peer info resp", "error", err.Error())
return models.HostPeerInfo{}, err
}

Expand Down
1 change: 0 additions & 1 deletion functions/mqhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func DNSSync(client mqtt.Client, msg mqtt.Message) {

// HostPeerUpdate - mq handler for host peer update peers/host/<HOSTID>/<SERVERNAME>
func HostPeerUpdate(client mqtt.Client, msg mqtt.Message) {
fmt.Println("\n <==========> ###### HOST PEER UPDATE ###### <================> \n")
var peerUpdate models.HostPeerUpdate
var err error
if len(config.GetNodes()) == 0 {
Expand Down
22 changes: 0 additions & 22 deletions functions/mqpublish.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"net/http"
"runtime"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -217,29 +216,8 @@ func PublishHostUpdate(server string, hostAction models.HostMqAction) error {
}
return nil
}
func TraceCaller() {
// Skip 1 frame to get the caller of this function
pc, file, line, ok := runtime.Caller(2)
if !ok {
slog.Debug("Unable to get caller information")
return
}
tracePc, _, _, ok := runtime.Caller(1)
if !ok {
slog.Debug("Unable to get caller information")
return
}
traceFuncName := runtime.FuncForPC(tracePc).Name()
// Get function name from the program counter (pc)
funcName := runtime.FuncForPC(pc).Name()

// Print trace details
slog.Debug("## TRACE -> Called from function: ", "tracing-func", traceFuncName, "caller-func-name", funcName)
slog.Debug("## TRACE -> Caller File Info", "file", file, "line-no", line)
}

func callPublishMetrics(fallback bool) {
TraceCaller()
server := config.GetServer(config.CurrServer)
if server == nil {
slog.Warn("server config is nil")
Expand Down
1 change: 0 additions & 1 deletion functions/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var pMutex = sync.Mutex{} // used to mutex functions for pull

// Pull - pulls the latest config from the server, if manual it will overwrite
func Pull(restart bool) (models.HostPull, bool, bool, error) {
TraceCaller()
pMutex.Lock()
defer pMutex.Unlock()
resetInterface := false
Expand Down
21 changes: 21 additions & 0 deletions ncutils/netclientutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,3 +721,24 @@ func SetVerbosity(logLevel int) {
slog.SetDefault(logger)

}

func TraceCaller() {
// Skip 1 frame to get the caller of this function
pc, file, line, ok := runtime.Caller(2)
if !ok {
slog.Debug("Unable to get caller information")
return
}
tracePc, _, _, ok := runtime.Caller(1)
if !ok {
slog.Debug("Unable to get caller information")
return
}
traceFuncName := runtime.FuncForPC(tracePc).Name()
// Get function name from the program counter (pc)
funcName := runtime.FuncForPC(pc).Name()

// Print trace details
slog.Debug("## TRACE -> Called from function: ", "tracing-func-name", traceFuncName, "caller-func-name", funcName)
slog.Debug("## TRACE -> Caller File Info", "file", file, "line-no", line)
}

0 comments on commit 7a3d0a4

Please sign in to comment.