Skip to content

Commit eed91c1

Browse files
author
Jeff Yanta
committed
Fix Timelock oldest record metric
1 parent 02eed8a commit eed91c1

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

pkg/code/async/geyser/backup.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (p *service) backupTimelockStateWorker(serviceCtx context.Context, interval
3737

3838
delay := 0 * time.Second // Initially no delay, so we can run right after a deploy
3939
cursor := query.EmptyCursor
40-
oldestRecord := time.Now()
40+
oldestRecordTs := time.Now()
4141
for {
4242
select {
4343
case <-time.After(delay):
@@ -58,11 +58,12 @@ func (p *service) backupTimelockStateWorker(serviceCtx context.Context, interval
5858
)
5959
if err == timelock.ErrTimelockNotFound {
6060
p.metricStatusLock.Lock()
61-
p.oldestTimelockRecord = &oldestRecord
61+
copiedTs := oldestRecordTs
62+
p.oldestTimelockRecord = &copiedTs
6263
p.metricStatusLock.Unlock()
6364

6465
cursor = query.EmptyCursor
65-
oldestRecord = time.Now()
66+
oldestRecordTs = time.Now()
6667
return
6768
} else if err != nil {
6869
log.WithError(err).Warn("failed to get timelock records")
@@ -73,8 +74,8 @@ func (p *service) backupTimelockStateWorker(serviceCtx context.Context, interval
7374
for _, timelockRecord := range timelockRecords {
7475
wg.Add(1)
7576

76-
if timelockRecord.LastUpdatedAt.Before(oldestRecord) {
77-
oldestRecord = timelockRecord.LastUpdatedAt
77+
if timelockRecord.LastUpdatedAt.Before(oldestRecordTs) {
78+
oldestRecordTs = timelockRecord.LastUpdatedAt
7879
}
7980

8081
go func(timelockRecord *timelock.Record) {

pkg/code/async/geyser/metrics.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ func (p *service) recordBackupWorkerStatusPollingEvent(ctx context.Context) {
114114
"is_active": p.backupTimelockStateWorkerStatus,
115115
}
116116
if p.oldestTimelockRecord != nil {
117-
timelockMetrics["oldest_record_age"] = int(time.Since(*p.oldestTimelockRecord) / time.Second)
117+
oldestRecordAgeSeconds := time.Since(*p.oldestTimelockRecord) / time.Second
118+
timelockMetrics["oldest_record_age_s"] = int(oldestRecordAgeSeconds)
118119
p.oldestTimelockRecord = nil
119120
}
120121
metrics.RecordEvent(ctx, backupWorkerStatusEventName, timelockMetrics)

0 commit comments

Comments
 (0)