add trace logs for skip network update

Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
bcmmbaga 2024-10-21 12:09:48 +03:00
parent ced28c4376
commit 006524756c
No known key found for this signature in database
GPG Key ID: 511EED5C928AD547
10 changed files with 45 additions and 0 deletions

View File

@ -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)
}
}

View File

@ -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

View File

@ -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

View File

@ -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())

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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 {