Skip to content

Commit

Permalink
Added logging for invocations of SaveAccount!
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-skalicky committed Jul 15, 2024
1 parent ba16d76 commit c0fa45e
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 7 deletions.
1 change: 1 addition & 0 deletions management/server/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ func BuildManager(ctx context.Context, store Store, peersUpdateManager *PeersUpd
}

if shouldSave {
log.WithContext(ctx).Info("Saving account!")
err = store.SaveAccount(ctx, account)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions management/server/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ func (am *DefaultAccountManager) DeleteGroup(ctx context.Context, accountId, use
delete(account.Groups, groupID)

account.Network.IncSerial()
log.WithContext(ctx).Info("Saving account!")
if err = am.Store.SaveAccount(ctx, account); err != nil {
return err
}
Expand Down Expand Up @@ -402,6 +403,7 @@ func (am *DefaultAccountManager) GroupAddPeer(ctx context.Context, accountID, gr
}

account.Network.IncSerial()
log.WithContext(ctx).Info("Saving account!")
if err = am.Store.SaveAccount(ctx, account); err != nil {
return err
}
Expand Down Expand Up @@ -430,6 +432,7 @@ func (am *DefaultAccountManager) GroupDeletePeer(ctx context.Context, accountID,
for i, itemID := range group.Peers {
if itemID == peerID {
group.Peers = append(group.Peers[:i], group.Peers[i+1:]...)
log.WithContext(ctx).Info("Saving account!")
if err := am.Store.SaveAccount(ctx, account); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions management/server/integrated_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (am *DefaultAccountManager) UpdateIntegratedValidatorGroups(ctx context.Con
a.Settings.Extra = extra
}
extra.IntegratedValidatorGroups = groups
log.WithContext(ctx).Info("Saving account!")
return am.Store.SaveAccount(ctx, a)
}

Expand Down
4 changes: 4 additions & 0 deletions management/server/nameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -80,6 +81,7 @@ func (am *DefaultAccountManager) CreateNameServerGroup(ctx context.Context, acco
account.NameServerGroups[newNSGroup.ID] = newNSGroup

account.Network.IncSerial()
log.WithContext(ctx).Info("Saving account!")
err = am.Store.SaveAccount(ctx, account)
if err != nil {
return nil, err
Expand Down Expand Up @@ -115,6 +117,7 @@ func (am *DefaultAccountManager) SaveNameServerGroup(ctx context.Context, accoun
account.NameServerGroups[nsGroupToSave.ID] = nsGroupToSave

account.Network.IncSerial()
log.WithContext(ctx).Info("Saving account!")
err = am.Store.SaveAccount(ctx, account)
if err != nil {
return err
Expand Down Expand Up @@ -145,6 +148,7 @@ func (am *DefaultAccountManager) DeleteNameServerGroup(ctx context.Context, acco
delete(account.NameServerGroups, nsGroupID)

account.Network.IncSerial()
log.WithContext(ctx).Info("Saving account!")
err = am.Store.SaveAccount(ctx, account)
if err != nil {
return err
Expand Down
11 changes: 7 additions & 4 deletions management/server/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (am *DefaultAccountManager) UpdatePeer(ctx context.Context, accountID, user
}

account.UpdatePeer(peer)

log.WithContext(ctx).Info("Saving account!")
err = am.Store.SaveAccount(ctx, account)
if err != nil {
return nil, err
Expand Down Expand Up @@ -283,7 +283,7 @@ func (am *DefaultAccountManager) DeletePeer(ctx context.Context, accountID, peer
if err != nil {
return err
}

log.WithContext(ctx).Info("Saving account!")
err = am.Store.SaveAccount(ctx, account)
if err != nil {
return err
Expand Down Expand Up @@ -492,6 +492,7 @@ func (am *DefaultAccountManager) AddPeer(ctx context.Context, setupKey, userID s

account.Peers[newPeer.ID] = newPeer
account.Network.IncSerial()
log.WithContext(ctx).Info("Saving account!")
err = am.Store.SaveAccount(ctx, account)
if err != nil {
return nil, nil, nil, err
Expand Down Expand Up @@ -539,6 +540,7 @@ func (am *DefaultAccountManager) SyncPeer(ctx context.Context, sync PeerSync, ac

peer, updated := updatePeerMeta(peer, sync.Meta, account)
if updated {
log.WithContext(ctx).Info("Saving account!")
err = am.Store.SaveAccount(ctx, account)
if err != nil {
return nil, nil, nil, err
Expand Down Expand Up @@ -712,6 +714,7 @@ func (am *DefaultAccountManager) LoginPeer(ctx context.Context, login PeerLogin)
log.WithContext(ctx).Errorf("account %s should be stored but is not write locked", accountID)
return nil, nil, nil, status.Errorf(status.Internal, "account should be stored but is not write locked")
}
log.WithContext(ctx).Info("Saving account!")
err = am.Store.SaveAccount(ctx, account)
if err != nil {
return nil, nil, nil, err
Expand Down Expand Up @@ -795,7 +798,7 @@ func (am *DefaultAccountManager) checkAndUpdatePeerSSHKey(ctx context.Context, p

peer.SSHKey = newSSHKey
account.UpdatePeer(peer)

log.WithContext(ctx).Info("Saving account!")
err := am.Store.SaveAccount(ctx, account)
if err != nil {
return nil, err
Expand Down Expand Up @@ -840,7 +843,7 @@ func (am *DefaultAccountManager) UpdatePeerSSHKey(ctx context.Context, peerID st

peer.SSHKey = sshKey
account.UpdatePeer(peer)

log.WithContext(ctx).Info("Saving account!")
err = am.Store.SaveAccount(ctx, account)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions management/server/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ func (am *DefaultAccountManager) SavePolicy(ctx context.Context, accountID, user
exists := am.savePolicy(account, policy)

account.Network.IncSerial()
log.WithContext(ctx).Info("Saving account!")
if err = am.Store.SaveAccount(ctx, account); err != nil {
return err
}
Expand Down Expand Up @@ -385,6 +386,7 @@ func (am *DefaultAccountManager) DeletePolicy(ctx context.Context, accountID, po
}

account.Network.IncSerial()
log.WithContext(ctx).Info("Saving account!")
if err = am.Store.SaveAccount(ctx, account); err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion management/server/posture_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -75,7 +76,7 @@ func (am *DefaultAccountManager) SavePostureChecks(ctx context.Context, accountI
action = activity.PostureCheckUpdated
account.Network.IncSerial()
}

log.WithContext(ctx).Info("Saving account!")
if err = am.Store.SaveAccount(ctx, account); err != nil {
return err
}
Expand Down Expand Up @@ -111,6 +112,7 @@ func (am *DefaultAccountManager) DeletePostureChecks(ctx context.Context, accoun
return err
}

log.WithContext(ctx).Info("Saving account!")
if err = am.Store.SaveAccount(ctx, account); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions management/server/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"unicode/utf8"

"github.com/rs/xid"
log "github.com/sirupsen/logrus"

"github.com/netbirdio/netbird/management/domain"
"github.com/netbirdio/netbird/management/proto"
Expand Down Expand Up @@ -201,6 +202,7 @@ func (am *DefaultAccountManager) CreateRoute(ctx context.Context, accountID stri
account.Routes[newRoute.ID] = &newRoute

account.Network.IncSerial()
log.WithContext(ctx).Info("Saving account!")
if err = am.Store.SaveAccount(ctx, account); err != nil {
return nil, err
}
Expand Down Expand Up @@ -270,6 +272,7 @@ func (am *DefaultAccountManager) SaveRoute(ctx context.Context, accountID, userI
account.Routes[routeToSave.ID] = routeToSave

account.Network.IncSerial()
log.WithContext(ctx).Info("Saving account!")
if err = am.Store.SaveAccount(ctx, account); err != nil {
return err
}
Expand Down Expand Up @@ -298,6 +301,7 @@ func (am *DefaultAccountManager) DeleteRoute(ctx context.Context, accountID stri
delete(account.Routes, routeID)

account.Network.IncSerial()
log.WithContext(ctx).Info("Saving account!")
if err = am.Store.SaveAccount(ctx, account); err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions management/server/setupkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ func (am *DefaultAccountManager) CreateSetupKey(ctx context.Context, accountID s

setupKey := GenerateSetupKey(keyName, keyType, keyDuration, autoGroups, usageLimit, ephemeral)
account.SetupKeys[setupKey.Key] = setupKey
log.WithContext(ctx).Info("Saving account!")
err = am.Store.SaveAccount(ctx, account)
if err != nil {
return nil, status.Errorf(status.Internal, "failed adding account key")
Expand Down Expand Up @@ -287,6 +288,7 @@ func (am *DefaultAccountManager) SaveSetupKey(ctx context.Context, accountID str
newKey.UpdatedAt = time.Now().UTC()

account.SetupKeys[newKey.Key] = newKey
log.WithContext(ctx).Info("Saving account!")

if err = am.Store.SaveAccount(ctx, account); err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions management/server/sql_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ func NewSqliteStoreFromFileStore(ctx context.Context, fileStore *FileStore, data
}

for _, account := range fileStore.GetAllAccounts(ctx) {
log.WithContext(ctx).Info("Saving account!")
err := store.SaveAccount(ctx, account)
if err != nil {
return nil, err
Expand Down
10 changes: 8 additions & 2 deletions management/server/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (am *DefaultAccountManager) createServiceUser(ctx context.Context, accountI
newUser := NewUser(newUserID, role, true, nonDeletable, serviceUserName, autoGroups, UserIssuedAPI)
log.WithContext(ctx).Debugf("New User: %v", newUser)
account.Users[newUserID] = newUser

log.WithContext(ctx).Info("Saving account!")
err = am.Store.SaveAccount(ctx, account)
if err != nil {
return nil, err
Expand Down Expand Up @@ -344,6 +344,7 @@ func (am *DefaultAccountManager) inviteNewUser(ctx context.Context, accountID, u
CreatedAt: time.Now().UTC(),
}
account.Users[idpUser.ID] = newUser
log.WithContext(ctx).Info("Saving account!")

err = am.Store.SaveAccount(ctx, account)
if err != nil {
Expand Down Expand Up @@ -465,6 +466,7 @@ func (am *DefaultAccountManager) DeleteUser(ctx context.Context, accountID, init
}

am.deleteServiceUser(ctx, account, initiatorUserID, targetUser)
log.WithContext(ctx).Info("Saving account!")
return am.Store.SaveAccount(ctx, account)
}

Expand Down Expand Up @@ -509,6 +511,7 @@ func (am *DefaultAccountManager) deleteRegularUser(ctx context.Context, account
}

delete(account.Users, targetUserID)
log.WithContext(ctx).Info("Saving account!")
err = am.Store.SaveAccount(ctx, account)
if err != nil {
return err
Expand Down Expand Up @@ -614,6 +617,7 @@ func (am *DefaultAccountManager) CreatePAT(ctx context.Context, accountID string
}

targetUser.PATs[pat.ID] = &pat.PersonalAccessToken
log.WithContext(ctx).Info("Saving account!")

err = am.Store.SaveAccount(ctx, account)
if err != nil {
Expand Down Expand Up @@ -668,7 +672,7 @@ func (am *DefaultAccountManager) DeletePAT(ctx context.Context, accountID string
am.StoreEvent(ctx, initiatorUserID, targetUserID, accountID, activity.PersonalAccessTokenDeleted, meta)

delete(targetUser.PATs, tokenID)

log.WithContext(ctx).Info("Saving account!")
err = am.Store.SaveAccount(ctx, account)
if err != nil {
return status.Errorf(status.Internal, "Failed to save account: %s", err)
Expand Down Expand Up @@ -1001,6 +1005,7 @@ func (am *DefaultAccountManager) GetOrCreateAccountByUser(ctx context.Context, u
if err != nil {
return nil, err
}
log.WithContext(ctx).Info("Saving account!")
err = am.Store.SaveAccount(ctx, account)
if err != nil {
return nil, err
Expand All @@ -1015,6 +1020,7 @@ func (am *DefaultAccountManager) GetOrCreateAccountByUser(ctx context.Context, u

if lowerDomain != "" && account.Domain != lowerDomain && userObj.Role == UserRoleOwner {
account.Domain = lowerDomain
log.WithContext(ctx).Info("Saving account!")
err = am.Store.SaveAccount(ctx, account)
if err != nil {
return nil, status.Errorf(status.Internal, "failed updating account with domain")
Expand Down

0 comments on commit c0fa45e

Please sign in to comment.