From 49c8d571b224117e6242c7dbada3666f51b523c3 Mon Sep 17 00:00:00 2001 From: mlsmaycon Date: Tue, 23 Jun 2026 13:04:41 +0200 Subject: [PATCH] Add enhanced logging for account peer updates and debugging --- .../network_map/controller/controller.go | 13 +++++++++++-- management/server/peer.go | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/management/internals/controllers/network_map/controller/controller.go b/management/internals/controllers/network_map/controller/controller.go index d271c499d..81c544141 100644 --- a/management/internals/controllers/network_map/controller/controller.go +++ b/management/internals/controllers/network_map/controller/controller.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "os" + "runtime/debug" "slices" "strconv" "sync" @@ -177,6 +178,10 @@ func (c *Controller) sendUpdateAccountPeers(ctx context.Context, accountID strin return fmt.Errorf("failed to get account zones: %v", err) } + if reason.Operation == types.UpdateOperationUpdate && reason.Resource == types.UpdateResourceUser { + log.WithContext(ctx).Tracef("got an user update, stack: %s", debug.Stack()) + } + for _, peer := range account.Peers { if !c.peersUpdateManager.HasChannel(peer.ID) { log.WithContext(ctx).Tracef("peer %s doesn't have a channel, skipping network map update", peer.ID) @@ -251,7 +256,7 @@ func (c *Controller) UpdateAffectedPeers(ctx context.Context, accountID string, } func (c *Controller) sendUpdateForAffectedPeers(ctx context.Context, accountID string, peerIDs []string) error { - log.WithContext(ctx).Tracef("sendUpdateForAffectedPeers: account %s, %d affected peers: %v (caller: %s)", accountID, len(peerIDs), peerIDs, util.GetCallerName()) + log.WithContext(ctx).Tracef("sendUpdateForAffectedPeers: account %s, %d affected peers (caller: %s)", accountID, len(peerIDs), util.GetCallerName()) if !c.hasConnectedPeers(peerIDs) { log.WithContext(ctx).Tracef("sendUpdateForAffectedPeers: no connected peers among %v, skipping", peerIDs) @@ -497,7 +502,11 @@ func (c *Controller) BufferUpdateAffectedPeers(ctx context.Context, accountID st c.accountManagerMetrics.CountUpdateAccountPeersTriggered(string(reason.Resource), string(reason.Operation)) } - log.WithContext(ctx).Tracef("buffer updating %d affected peers for account %s from %s", len(peerIDs), accountID, util.GetCallerName()) + log.WithContext(ctx).Tracef("buffer updating %d affected peers for account %s from %s with reason %s/%s", len(peerIDs), accountID, util.GetCallerName(), reason.Operation, reason.Resource) + + if reason.Operation == types.UpdateOperationUpdate && reason.Resource == types.UpdateResourceUser { + log.WithContext(ctx).Tracef("got an user update, stack: %s", debug.Stack()) + } bufUpd, _ := c.affectedPeerUpdateLocks.LoadOrStore(accountID, &bufferAffectedUpdate{ peerIDs: make(map[string]struct{}), diff --git a/management/server/peer.go b/management/server/peer.go index 91fafa830..86637980e 100644 --- a/management/server/peer.go +++ b/management/server/peer.go @@ -11,6 +11,7 @@ import ( "strings" "time" + "github.com/netbirdio/netbird/util" "github.com/rs/xid" log "github.com/sirupsen/logrus" "golang.org/x/exp/maps" @@ -1477,6 +1478,7 @@ func (am *DefaultAccountManager) GetPeer(ctx context.Context, accountID, peerID, // UpdateAccountPeers updates all peers that belong to an account. // Should be called when changes have to be synced to peers. func (am *DefaultAccountManager) UpdateAccountPeers(ctx context.Context, accountID string, reason types.UpdateReason) { + log.WithContext(ctx).Tracef("update account peers for account %s from caller: %s with reason %s/%s", accountID, util.GetCallerName(), reason.Operation, reason.Resource) _ = am.networkMapController.UpdateAccountPeers(ctx, accountID, reason) } @@ -1575,6 +1577,7 @@ func (am *DefaultAccountManager) resolveAffectedPeersForPeerChanges(ctx context. } func (am *DefaultAccountManager) BufferUpdateAccountPeers(ctx context.Context, accountID string, reason types.UpdateReason) { + log.WithContext(ctx).Tracef("buffering update account peers for account %s from caller: %s with reason %s/%s", accountID, util.GetCallerName(), reason.Operation, reason.Resource) _ = am.networkMapController.BufferUpdateAccountPeers(ctx, accountID, reason) }