-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmetrics.go
137 lines (114 loc) · 4.15 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package async_geyser
import (
"context"
"time"
"github.com/code-payments/code-server/pkg/metrics"
"github.com/code-payments/code-server/pkg/solana"
)
const (
subscriptionStatusEventName = "GeyserConsumerSubscriptionPollingCheck"
eventWorkerStatusEventName = "GeyserConsumerWorkerPollingCheck"
eventQueueStatusEventName = "GeyserConsumerQueuePollingCheck"
backupWorkerStatusEventName = "GeyserBackupWorkerPollingCheck"
backupQueueStatusEventName = "GeyserBackupQueuePollingCheck"
programUpdateWorkerName = "ProgramUpdate"
slotUpdateWorkerName = "SlotUpdate"
externalDepositWorkerName = "ExternalDeposit"
timelockStateWorkerName = "TimelockState"
messagingWorkerName = "Messaging"
)
func (p *service) metricsGaugeWorker(ctx context.Context) error {
delay := time.Second
for {
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(delay):
start := time.Now()
p.recordSubscriptionStatusPollingEvent(ctx)
p.recordEventWorkerStatusPollingEvent(ctx)
p.recordEventQueueStatusPollingEvent(ctx)
p.recordBackupWorkerStatusPollingEvent(ctx)
p.recordBackupQueueStatusPollingEvent(ctx)
delay = time.Second - time.Since(start)
}
}
}
func (p *service) recordSubscriptionStatusPollingEvent(ctx context.Context) {
currentFinalizedSlot, _ := p.data.GetBlockchainSlot(ctx, solana.CommitmentFinalized)
p.metricStatusLock.RLock()
defer p.metricStatusLock.RUnlock()
metrics.RecordEvent(ctx, subscriptionStatusEventName, map[string]interface{}{
"event_type": programUpdateWorkerName,
"is_active": p.programUpdateSubscriptionStatus,
})
var slotsBehind uint64
if currentFinalizedSlot > p.highestObservedRootedSlot {
slotsBehind = currentFinalizedSlot - p.highestObservedRootedSlot
}
kvPairs := map[string]interface{}{
"event_type": slotUpdateWorkerName,
"is_active": p.slotUpdateSubscriptionStatus,
}
if p.highestObservedRootedSlot > 0 {
kvPairs["highest_observed_slot"] = p.highestObservedRootedSlot
if currentFinalizedSlot > 0 {
kvPairs["slots_behind"] = slotsBehind
}
}
metrics.RecordEvent(ctx, subscriptionStatusEventName, kvPairs)
}
func (p *service) recordEventWorkerStatusPollingEvent(ctx context.Context) {
p.metricStatusLock.Lock()
defer p.metricStatusLock.Unlock()
var eventsProcessed int
var numActive int
for _, workerMetrics := range p.programUpdateWorkerMetrics {
if workerMetrics.active {
numActive += 1
}
eventsProcessed += workerMetrics.eventsProcessed
workerMetrics.eventsProcessed = 0
}
metrics.RecordEvent(ctx, eventWorkerStatusEventName, map[string]interface{}{
"event_type": programUpdateWorkerName,
"active_count": numActive,
"total_count": len(p.programUpdateWorkerMetrics),
"events_processed": eventsProcessed,
})
}
func (p *service) recordEventQueueStatusPollingEvent(ctx context.Context) {
metrics.RecordEvent(ctx, eventQueueStatusEventName, map[string]interface{}{
"event_type": programUpdateWorkerName,
"current_size": len(p.programUpdatesChan),
"max_size": p.conf.programUpdateQueueSize.Get(ctx),
})
}
func (p *service) recordBackupWorkerStatusPollingEvent(ctx context.Context) {
p.metricStatusLock.Lock()
defer p.metricStatusLock.Unlock()
metrics.RecordEvent(ctx, backupWorkerStatusEventName, map[string]interface{}{
"worker_type": timelockStateWorkerName,
"is_active": p.backupTimelockStateWorkerStatus,
"unlocked_timelock_accounts_synced": p.unlockedTimelockAccountsSynced,
})
p.unlockedTimelockAccountsSynced = false
metrics.RecordEvent(ctx, backupWorkerStatusEventName, map[string]interface{}{
"worker_type": externalDepositWorkerName,
"is_active": p.backupExternalDepositWorkerStatus,
})
metrics.RecordEvent(ctx, backupWorkerStatusEventName, map[string]interface{}{
"worker_type": messagingWorkerName,
"is_active": p.backupMessagingWorkerStatus,
})
}
func (p *service) recordBackupQueueStatusPollingEvent(ctx context.Context) {
count, err := p.data.GetAccountInfoCountRequiringDepositSync(ctx)
if err != nil {
return
}
metrics.RecordEvent(ctx, backupQueueStatusEventName, map[string]interface{}{
"worker_type": externalDepositWorkerName,
"current_size": count,
})
}