From 006524756c0edd66f94f64fd4cac35c23ff44c9a Mon Sep 17 00:00:00 2001 From: bcmmbaga Date: Mon, 21 Oct 2024 12:09:48 +0300 Subject: [PATCH] add trace logs for skip network update Signed-off-by: bcmmbaga --- management/server/account.go | 2 ++ management/server/dns.go | 2 ++ management/server/group.go | 6 ++++++ management/server/nameserver.go | 7 +++++++ management/server/peer.go | 6 ++++++ management/server/policy.go | 2 ++ management/server/posture_checks.go | 3 +++ management/server/route.go | 6 ++++++ management/server/updatechannel.go | 5 +++++ management/server/user.go | 6 ++++++ 10 files changed, 45 insertions(+) diff --git a/management/server/account.go b/management/server/account.go index d99664750..3cb10ce0f 100644 --- a/management/server/account.go +++ b/management/server/account.go @@ -1955,6 +1955,8 @@ func (am *DefaultAccountManager) syncJWTGroups(ctx context.Context, accountID st if areGroupChangesAffectPeers(account, addNewGroups) || areGroupChangesAffectPeers(account, removeOldGroups) { log.WithContext(ctx).Tracef("user %s: JWT group membership changed, updating account peers", claims.UserId) am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for account: %s", accountID) } } diff --git a/management/server/dns.go b/management/server/dns.go index 256b8b125..545fe64e2 100644 --- a/management/server/dns.go +++ b/management/server/dns.go @@ -147,6 +147,8 @@ func (am *DefaultAccountManager) SaveDNSSettings(ctx context.Context, accountID if anyGroupHasPeers(account, addedGroups) || anyGroupHasPeers(account, removedGroups) { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for account dns settings: %s", accountID) } return nil diff --git a/management/server/group.go b/management/server/group.go index 91c06a3c0..7f3b441b3 100644 --- a/management/server/group.go +++ b/management/server/group.go @@ -133,6 +133,8 @@ func (am *DefaultAccountManager) SaveGroups(ctx context.Context, accountID, user if areGroupChangesAffectPeers(account, newGroupIDs) { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for group: %v", newGroupIDs) } for _, storeEvent := range eventsToStore { @@ -341,6 +343,8 @@ func (am *DefaultAccountManager) GroupAddPeer(ctx context.Context, accountID, gr if areGroupChangesAffectPeers(account, []string{group.ID}) { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for group: %s", groupID) } return nil @@ -373,6 +377,8 @@ func (am *DefaultAccountManager) GroupDeletePeer(ctx context.Context, accountID, if areGroupChangesAffectPeers(account, []string{group.ID}) { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for group: %s", groupID) } return nil diff --git a/management/server/nameserver.go b/management/server/nameserver.go index 751ca12bc..7818b43ba 100644 --- a/management/server/nameserver.go +++ b/management/server/nameserver.go @@ -8,6 +8,7 @@ import ( "github.com/miekg/dns" "github.com/rs/xid" + log "github.com/sirupsen/logrus" nbdns "github.com/netbirdio/netbird/dns" "github.com/netbirdio/netbird/management/server/activity" @@ -72,6 +73,8 @@ func (am *DefaultAccountManager) CreateNameServerGroup(ctx context.Context, acco if anyGroupHasPeers(account, newNSGroup.Groups) { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for ns group: %s", newNSGroup.ID) } am.StoreEvent(ctx, userID, newNSGroup.ID, accountID, activity.NameserverGroupCreated, newNSGroup.EventMeta()) @@ -107,6 +110,8 @@ func (am *DefaultAccountManager) SaveNameServerGroup(ctx context.Context, accoun if anyGroupHasPeers(account, nsGroupToSave.Groups) || anyGroupHasPeers(account, oldNSGroup.Groups) { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for ns group: %s", nsGroupToSave.ID) } am.StoreEvent(ctx, userID, nsGroupToSave.ID, accountID, activity.NameserverGroupUpdated, nsGroupToSave.EventMeta()) @@ -137,6 +142,8 @@ func (am *DefaultAccountManager) DeleteNameServerGroup(ctx context.Context, acco if anyGroupHasPeers(account, nsGroup.Groups) { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for peer: %s", nsGroupID) } am.StoreEvent(ctx, userID, nsGroup.ID, accountID, activity.NameserverGroupDeleted, nsGroup.EventMeta()) diff --git a/management/server/peer.go b/management/server/peer.go index a85e8c6b2..03681c128 100644 --- a/management/server/peer.go +++ b/management/server/peer.go @@ -232,6 +232,8 @@ func (am *DefaultAccountManager) UpdatePeer(ctx context.Context, accountID, user expired, _ := peer.LoginExpired(account.Settings.PeerLoginExpiration) if peerLabelUpdated || (expired && peer.LoginExpirationEnabled) { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for peer: %s", update.ID) } return peer, nil @@ -310,6 +312,8 @@ func (am *DefaultAccountManager) DeletePeer(ctx context.Context, accountID, peer if updateAccountPeers { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for peer: %s", peerID) } return nil @@ -555,6 +559,8 @@ func (am *DefaultAccountManager) AddPeer(ctx context.Context, setupKey, userID s if areGroupChangesAffectPeers(account, groupsToAdd) { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for peer: %s", newPeer.ID) } approvedPeersMap, err := am.GetValidatedPeers(account) diff --git a/management/server/policy.go b/management/server/policy.go index 95bae8973..5ccc28847 100644 --- a/management/server/policy.go +++ b/management/server/policy.go @@ -378,6 +378,8 @@ func (am *DefaultAccountManager) SavePolicy(ctx context.Context, accountID, user if updateAccountPeers { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for policy: %s", policy.ID) } return nil diff --git a/management/server/posture_checks.go b/management/server/posture_checks.go index ca4946703..49cfcc3ff 100644 --- a/management/server/posture_checks.go +++ b/management/server/posture_checks.go @@ -8,6 +8,7 @@ import ( nbpeer "github.com/netbirdio/netbird/management/server/peer" "github.com/netbirdio/netbird/management/server/posture" "github.com/netbirdio/netbird/management/server/status" + log "github.com/sirupsen/logrus" ) const ( @@ -71,6 +72,8 @@ func (am *DefaultAccountManager) SavePostureChecks(ctx context.Context, accountI isLinked, linkedPolicy := isPostureCheckLinkedToPolicy(account, postureChecks.ID) if exists && isLinked && anyGroupHasPeers(account, linkedPolicy.ruleGroups()) { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for posture checks: %s", postureChecks.ID) } return nil diff --git a/management/server/route.go b/management/server/route.go index 1cf00b37c..adc45016d 100644 --- a/management/server/route.go +++ b/management/server/route.go @@ -239,6 +239,8 @@ func (am *DefaultAccountManager) CreateRoute(ctx context.Context, accountID stri if isRouteChangeAffectPeers(account, &newRoute) { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for route: %s", newRoute.ID) } am.StoreEvent(ctx, userID, string(newRoute.ID), accountID, activity.RouteCreated, newRoute.EventMeta()) @@ -325,6 +327,8 @@ func (am *DefaultAccountManager) SaveRoute(ctx context.Context, accountID, userI if isRouteChangeAffectPeers(account, oldRoute) || isRouteChangeAffectPeers(account, routeToSave) { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for route: %s", routeToSave.ID) } am.StoreEvent(ctx, userID, string(routeToSave.ID), accountID, activity.RouteUpdated, routeToSave.EventMeta()) @@ -357,6 +361,8 @@ func (am *DefaultAccountManager) DeleteRoute(ctx context.Context, accountID stri if isRouteChangeAffectPeers(account, routy) { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for route: %s", routy.ID) } return nil diff --git a/management/server/updatechannel.go b/management/server/updatechannel.go index 5f636820b..68ca760fc 100644 --- a/management/server/updatechannel.go +++ b/management/server/updatechannel.go @@ -226,6 +226,11 @@ func (p *PeersUpdateManager) handlePeerMessageUpdate(ctx context.Context, peerID // isNewPeerUpdateMessage checks if the given current update message is a new update that should be sent. func isNewPeerUpdateMessage(lastSentUpdate, currUpdateToSend *UpdateMessage) (bool, error) { if lastSentUpdate.Update.NetworkMap.GetSerial() > currUpdateToSend.Update.NetworkMap.GetSerial() { + log.Tracef("new network map serial: %d not greater than last sent: %d, skip sending update", + lastSentUpdate.Update.NetworkMap.GetSerial(), + currUpdateToSend.Update.NetworkMap.GetSerial(), + ) + return false, nil } diff --git a/management/server/user.go b/management/server/user.go index e40fc67eb..17e9f0e75 100644 --- a/management/server/user.go +++ b/management/server/user.go @@ -485,6 +485,8 @@ func (am *DefaultAccountManager) deleteRegularUser(ctx context.Context, account am.StoreEvent(ctx, initiatorUserID, targetUserID, account.Id, activity.UserDeleted, meta) if updateAccountPeers { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for user: %s", targetUserID) } return nil @@ -826,6 +828,8 @@ func (am *DefaultAccountManager) SaveOrAddUsers(ctx context.Context, accountID, if areUsersLinkedToPeers(account, userIDs) && account.Settings.GroupsPropagationEnabled { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for user: %v", userIDs) } for _, storeEvent := range eventsToStore { @@ -1225,6 +1229,8 @@ func (am *DefaultAccountManager) DeleteRegularUsers(ctx context.Context, account if updateAccountPeers { am.updateAccountPeers(ctx, account) + } else { + log.WithContext(ctx).Tracef("Skipping account peers update for user: %v", targetUserIDs) } for targetUserID, meta := range deletedUsersMeta {