remove stopwatches

This commit is contained in:
Pascal Fischer
2024-04-29 14:57:57 +02:00
parent 3085383729
commit 02537e5536
6 changed files with 0 additions and 143 deletions

View File

@@ -388,12 +388,6 @@ func (a *Account) GetGroup(groupID string) *nbgroup.Group {
// GetPeerNetworkMap returns a group by ID if exists, nil otherwise
func (a *Account) GetPeerNetworkMap(peerID, dnsDomain string, validatedPeersMap map[string]struct{}) *NetworkMap {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("GetPeerNetworkMap took %s", duration)
}()
peer := a.Peers[peerID]
if peer == nil {
return &NetworkMap{
@@ -464,12 +458,6 @@ func (a *Account) GetExpiredPeers() []*nbpeer.Peer {
// If there is no peer that expires this function returns false and a duration of 0.
// This function only considers peers that haven't been expired yet and that are connected.
func (a *Account) GetNextPeerExpiration() (time.Duration, bool) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("GetNextPeerExpiration took %s", duration)
}()
peersWithExpiry := a.GetPeersWithExpiration()
if len(peersWithExpiry) == 0 {
return 0, false
@@ -526,11 +514,6 @@ func (a *Account) UpdateSettings(update *Settings) *Account {
// UpdatePeer saves new or replaces existing peer
func (a *Account) UpdatePeer(update *nbpeer.Peer) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("UpdatePeer took %s", duration)
}()
a.Peers[update.ID] = update
}
@@ -560,12 +543,6 @@ func (a *Account) DeletePeer(peerID string) {
// FindPeerByPubKey looks for a Peer by provided WireGuard public key in the Account or returns error if it wasn't found.
// It will return an object copy of the peer.
func (a *Account) FindPeerByPubKey(peerPubKey string) (*nbpeer.Peer, error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("FindPeerByPubKey took %s", duration)
}()
for _, peer := range a.Peers {
if peer.Key == peerPubKey {
return peer.Copy(), nil
@@ -1061,12 +1038,6 @@ func (am *DefaultAccountManager) peerLoginExpirationJob(accountID string) func()
}
func (am *DefaultAccountManager) checkAndSchedulePeerLoginExpiration(account *Account) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("checkAndSchedulePeerLoginExpiration took %s", duration)
}()
am.peerLoginExpiry.Cancel([]string{account.Id})
if nextRun, ok := account.GetNextPeerExpiration(); ok {
go am.peerLoginExpiry.Schedule(nextRun, account.Id, am.peerLoginExpirationJob(account.Id))
@@ -1867,12 +1838,6 @@ func (am *DefaultAccountManager) getAccountWithAuthorizationClaims(claims jwtcla
}
func (am *DefaultAccountManager) SyncAndMarkPeer(peerPubKey string, realIP net.IP) (*nbpeer.Peer, *NetworkMap, error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("SyncAndMarkPeer took %s", duration)
}()
accountID, err := am.Store.GetAccountIDByPeerPubKey(peerPubKey)
if err != nil {
return nil, nil, err

View File

@@ -106,12 +106,6 @@ func openDB(mmdbPath string) (*maxminddb.Reader, error) {
}
func (gl *Geolocation) Lookup(ip net.IP) (*Record, error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("(GeoLocation) Lookup took %s", duration)
}()
gl.mux.RLock()
defer gl.mux.RUnlock()

View File

@@ -121,12 +121,6 @@ func getRealIP(ctx context.Context) net.IP {
// Sync validates the existence of a connecting peer, sends an initial state (all available for the connecting peers) and
// notifies the connected peer of any updates (e.g. new peers under the same account)
func (s *GRPCServer) Sync(req *proto.EncryptedMessage, srv proto.ManagementService_SyncServer) error {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("Sync took %s", duration)
}()
reqStart := time.Now()
if s.appMetrics != nil {
s.appMetrics.GRPCMetrics().CountSyncRequest()
@@ -316,12 +310,6 @@ func (s *GRPCServer) parseRequest(req *proto.EncryptedMessage, parsed pb.Message
// In case it isn't, the endpoint checks whether setup key is provided within the request and tries to register a peer.
// In case of the successful registration login is also successful
func (s *GRPCServer) Login(ctx context.Context, req *proto.EncryptedMessage) (*proto.EncryptedMessage, error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("Login took %s", duration)
}()
reqStart := time.Now()
defer func() {
if s.appMetrics != nil {
@@ -530,12 +518,6 @@ func (s *GRPCServer) IsHealthy(ctx context.Context, req *proto.Empty) (*proto.Em
// sendInitialSync sends initial proto.SyncResponse to the peer requesting synchronization
func (s *GRPCServer) sendInitialSync(peerKey wgtypes.Key, peer *nbpeer.Peer, networkMap *NetworkMap, srv proto.ManagementService_SyncServer) error {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("sendInitialSync took %s", duration)
}()
// make secret time based TURN credentials optional
var turnCredentials *TURNCredentials
if s.config.TURNConfig.TimeBasedCredentials {

View File

@@ -2,7 +2,6 @@ package server
import (
"errors"
"time"
"github.com/google/martian/v3/log"
@@ -77,11 +76,5 @@ func (am *DefaultAccountManager) GroupValidation(accountId string, groups []stri
}
func (am *DefaultAccountManager) GetValidatedPeers(account *Account) (map[string]struct{}, error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("GetValidatedPeers took %s", duration)
}()
return am.integratedPeerValidator.GetValidatedPeers(account.Id, account.Groups, account.Peers, account.Settings.Extra)
}

View File

@@ -89,12 +89,6 @@ func (am *DefaultAccountManager) GetPeers(accountID, userID string) ([]*nbpeer.P
// MarkPeerConnected marks peer as connected (true) or disconnected (false)
func (am *DefaultAccountManager) MarkPeerConnected(peerPubKey string, connected bool, realIP net.IP, account *Account) error {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("MarkPeerConnected took %s", duration)
}()
peer, err := account.FindPeerByPubKey(peerPubKey)
if err != nil {
return err
@@ -511,12 +505,6 @@ func (am *DefaultAccountManager) AddPeer(setupKey, userID string, peer *nbpeer.P
// SyncPeer checks whether peer is eligible for receiving NetworkMap (authenticated) and returns its NetworkMap if eligible
func (am *DefaultAccountManager) SyncPeer(sync PeerSync, account *Account) (*nbpeer.Peer, *NetworkMap, error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("SyncPeer took %s", duration)
}()
peer, err := account.FindPeerByPubKey(sync.WireGuardPubKey)
if err != nil {
return nil, nil, status.Errorf(status.Unauthenticated, "peer is not registered")
@@ -670,12 +658,6 @@ func (am *DefaultAccountManager) LoginPeer(login PeerLogin) (*nbpeer.Peer, *Netw
}
func checkIfPeerOwnerIsBlocked(peer *nbpeer.Peer, account *Account) error {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("checkIfPeerOwnerIsBlocked took %s", duration)
}()
if peer.AddedWithSSOLogin() {
user, err := account.FindUser(peer.UserID)
if err != nil {
@@ -716,12 +698,6 @@ func updatePeerLastLogin(peer *nbpeer.Peer, account *Account) {
}
func (am *DefaultAccountManager) checkAndUpdatePeerSSHKey(peer *nbpeer.Peer, account *Account, newSSHKey string) (*nbpeer.Peer, error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("checkAndUpdatePeerSSHKey took %s", duration)
}()
if len(newSSHKey) == 0 {
log.Debugf("no new SSH key provided for peer %s, skipping update", peer.ID)
return peer, nil
@@ -845,12 +821,6 @@ func (am *DefaultAccountManager) GetPeer(accountID, peerID, userID string) (*nbp
}
func updatePeerMeta(peer *nbpeer.Peer, meta nbpeer.PeerSystemMeta, account *Account) (*nbpeer.Peer, bool) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("updatePeerMeta took %s", duration)
}()
if peer.UpdateMetaIfNew(meta) {
account.UpdatePeer(peer)
return peer, true
@@ -861,12 +831,6 @@ func updatePeerMeta(peer *nbpeer.Peer, meta nbpeer.PeerSystemMeta, account *Acco
// updateAccountPeers updates all peers that belong to an account.
// Should be called when changes have to be synced to peers.
func (am *DefaultAccountManager) updateAccountPeers(account *Account) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("updateAccountPeers took %s", duration)
}()
peers := account.GetPeers()
approvedPeersMap, err := am.GetValidatedPeers(account)

View File

@@ -128,12 +128,6 @@ func (s *SqliteStore) AcquireGlobalLock() (unlock func()) {
}
func (s *SqliteStore) AcquireAccountWriteLock(accountID string) (unlock func()) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("AcquireAccountWriteLock took %s", duration)
}()
log.Tracef("acquiring write lock for account %s", accountID)
start := time.Now()
@@ -150,12 +144,6 @@ func (s *SqliteStore) AcquireAccountWriteLock(accountID string) (unlock func())
}
func (s *SqliteStore) AcquireAccountReadLock(accountID string) (unlock func()) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("AcquireAccountReadLock took %s", duration)
}()
log.Tracef("acquiring read lock for account %s", accountID)
start := time.Now()
@@ -172,12 +160,6 @@ func (s *SqliteStore) AcquireAccountReadLock(accountID string) (unlock func()) {
}
func (s *SqliteStore) SaveAccount(account *Account) error {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("SaveAccount took %s", duration)
}()
start := time.Now()
for _, key := range account.SetupKeys {
@@ -297,12 +279,6 @@ func (s *SqliteStore) GetInstallationID() string {
}
func (s *SqliteStore) SavePeerStatus(accountID, peerID string, peerStatus nbpeer.PeerStatus) error {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("SavePeerStatus took %s", duration)
}()
var peer nbpeer.Peer
result := s.db.Model(&peer).
Where("account_id = ? AND id = ?", accountID, peerID).
@@ -317,12 +293,6 @@ func (s *SqliteStore) SavePeerStatus(accountID, peerID string, peerStatus nbpeer
}
func (s *SqliteStore) SavePeerLocation(accountID string, peerWithLocation *nbpeer.Peer) error {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("SavePeerLocation took %s", duration)
}()
location := peerWithLocation.Location
var peer nbpeer.Peer
@@ -425,12 +395,6 @@ func (s *SqliteStore) GetUserByTokenID(tokenID string) (*User, error) {
}
func (s *SqliteStore) GetAllAccounts() (all []*Account) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("GetAllAccounts took %s", duration)
}()
var accounts []Account
result := s.db.Find(&accounts)
if result.Error != nil {
@@ -447,11 +411,6 @@ func (s *SqliteStore) GetAllAccounts() (all []*Account) {
}
func (s *SqliteStore) GetAccount(accountID string) (*Account, error) {
startTime := time.Now()
defer func() {
duration := time.Since(startTime)
log.Debugf("GetAccount took %s", duration)
}()
var account Account
result := s.db.Model(&account).