mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-21 15:43:12 +01:00
[management] Add transaction metrics and exclude getAccount time from peers update (#2904)
This commit is contained in:
parent
78fab877c0
commit
52ea2e84e9
@ -988,6 +988,12 @@ func (am *DefaultAccountManager) GetPeer(ctx context.Context, accountID, peerID,
|
|||||||
// updateAccountPeers updates all peers that belong to an account.
|
// updateAccountPeers updates all peers that belong to an account.
|
||||||
// Should be called when changes have to be synced to peers.
|
// Should be called when changes have to be synced to peers.
|
||||||
func (am *DefaultAccountManager) updateAccountPeers(ctx context.Context, accountID string) {
|
func (am *DefaultAccountManager) updateAccountPeers(ctx context.Context, accountID string) {
|
||||||
|
account, err := am.requestBuffer.GetAccountWithBackpressure(ctx, accountID)
|
||||||
|
if err != nil {
|
||||||
|
log.WithContext(ctx).Errorf("failed to send out updates to peers: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
if am.metrics != nil {
|
if am.metrics != nil {
|
||||||
@ -995,11 +1001,6 @@ func (am *DefaultAccountManager) updateAccountPeers(ctx context.Context, account
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
account, err := am.requestBuffer.GetAccountWithBackpressure(ctx, accountID)
|
|
||||||
if err != nil {
|
|
||||||
log.WithContext(ctx).Errorf("failed to send out updates to peers: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
peers := account.GetPeers()
|
peers := account.GetPeers()
|
||||||
|
|
||||||
approvedPeersMap, err := am.GetValidatedPeers(account)
|
approvedPeersMap, err := am.GetValidatedPeers(account)
|
||||||
|
@ -1123,6 +1123,7 @@ func (s *SqlStore) IncrementNetworkSerial(ctx context.Context, lockStrength Lock
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlStore) ExecuteInTransaction(ctx context.Context, operation func(store Store) error) error {
|
func (s *SqlStore) ExecuteInTransaction(ctx context.Context, operation func(store Store) error) error {
|
||||||
|
startTime := time.Now()
|
||||||
tx := s.db.Begin()
|
tx := s.db.Begin()
|
||||||
if tx.Error != nil {
|
if tx.Error != nil {
|
||||||
return tx.Error
|
return tx.Error
|
||||||
@ -1133,7 +1134,15 @@ func (s *SqlStore) ExecuteInTransaction(ctx context.Context, operation func(stor
|
|||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return tx.Commit().Error
|
|
||||||
|
err = tx.Commit().Error
|
||||||
|
|
||||||
|
log.WithContext(ctx).Tracef("transaction took %v", time.Since(startTime))
|
||||||
|
if s.metrics != nil {
|
||||||
|
s.metrics.StoreMetrics().CountTransactionDuration(time.Since(startTime))
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlStore) withTx(tx *gorm.DB) Store {
|
func (s *SqlStore) withTx(tx *gorm.DB) Store {
|
||||||
|
@ -13,6 +13,7 @@ type StoreMetrics struct {
|
|||||||
globalLockAcquisitionDurationMs metric.Int64Histogram
|
globalLockAcquisitionDurationMs metric.Int64Histogram
|
||||||
persistenceDurationMicro metric.Int64Histogram
|
persistenceDurationMicro metric.Int64Histogram
|
||||||
persistenceDurationMs metric.Int64Histogram
|
persistenceDurationMs metric.Int64Histogram
|
||||||
|
transactionDurationMs metric.Int64Histogram
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,11 +41,17 @@ func NewStoreMetrics(ctx context.Context, meter metric.Meter) (*StoreMetrics, er
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transactionDurationMs, err := meter.Int64Histogram("management.store.transaction.duration.ms")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &StoreMetrics{
|
return &StoreMetrics{
|
||||||
globalLockAcquisitionDurationMicro: globalLockAcquisitionDurationMicro,
|
globalLockAcquisitionDurationMicro: globalLockAcquisitionDurationMicro,
|
||||||
globalLockAcquisitionDurationMs: globalLockAcquisitionDurationMs,
|
globalLockAcquisitionDurationMs: globalLockAcquisitionDurationMs,
|
||||||
persistenceDurationMicro: persistenceDurationMicro,
|
persistenceDurationMicro: persistenceDurationMicro,
|
||||||
persistenceDurationMs: persistenceDurationMs,
|
persistenceDurationMs: persistenceDurationMs,
|
||||||
|
transactionDurationMs: transactionDurationMs,
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@ -60,3 +67,8 @@ func (metrics *StoreMetrics) CountPersistenceDuration(duration time.Duration) {
|
|||||||
metrics.persistenceDurationMicro.Record(metrics.ctx, duration.Microseconds())
|
metrics.persistenceDurationMicro.Record(metrics.ctx, duration.Microseconds())
|
||||||
metrics.persistenceDurationMs.Record(metrics.ctx, duration.Milliseconds())
|
metrics.persistenceDurationMs.Record(metrics.ctx, duration.Milliseconds())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountTransactionDuration counts the duration of a store persistence operation
|
||||||
|
func (metrics *StoreMetrics) CountTransactionDuration(duration time.Duration) {
|
||||||
|
metrics.transactionDurationMs.Record(metrics.ctx, duration.Milliseconds())
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user