Skip to content

Commit

Permalink
Metrics reset.
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-myles authored and ice-ares committed Nov 3, 2023
1 parent 5c9276d commit 35626e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
currentAdoption = m.getAdoption(ctx, m.db, workerNumber)
workers = cfg.Workers
batchSize = cfg.BatchSize
metrics balanceRecalculationMetrics
metrics = new(balanceRecalculationMetrics)
userKeys, userBackupKeys, userHistoryKeys, referralKeys = make([]string, 0, batchSize), make([]string, 0, batchSize), make([]string, 0, batchSize), make([]string, 0, 2*batchSize)
userResults, backupUserResults, referralResults = make([]*user, 0, batchSize), make([]*backupUserUpdated, 0, batchSize), make([]*referral, 0, 2*batchSize)
t0Referrals, tMinus1Referrals = make(map[int64]*referral, batchSize), make(map[int64]*referral, batchSize)
Expand Down Expand Up @@ -203,9 +203,10 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
metrics.IterationsNum = int64(totalBatches)
metrics.EndedAt = time.Now()
metrics.Worker = workerNumber
if err := m.insertBalanceRecalculationMetrics(ctx, &metrics); err != nil {
if err := m.insertBalanceRecalculationMetrics(ctx, metrics); err != nil {
log.Error(err, "can't insert balance recalculation metrics for worker:", workerNumber)
}
metrics.reset()
}
if totalBatches != 0 && iteration > 2 {
shouldSynchronizeBalanceFunc = m.telemetry.shouldSynchronizeBalanceFunc(uint64(workerNumber), totalBatches, iteration)
Expand Down
15 changes: 15 additions & 0 deletions miner/recalculate_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,18 @@ func (m *miner) insertBalanceRecalculationMetrics(ctx context.Context, brm *bala

return errors.Wrapf(err, "failed to insert metrics for worker:%v, params:%#v", brm.Worker, brm)
}

func (b *balanceRecalculationMetrics) reset() {
b.EndedAt = nil
b.AffectedUsers = 0
b.IterationsNum = 0
b.T1BalancePositive = 0
b.T1BalanceNegative = 0
b.T2BalancePositive = 0
b.T2BalanceNegative = 0
b.T1ActiveCountsPositive = 0
b.T1ActiveCountsNegative = 0
b.T2ActiveCountsPositive = 0
b.T2ActiveCountsNegative = 0
b.StartedAt = time.Now()
}

0 comments on commit 35626e4

Please sign in to comment.