-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmetrics.go
71 lines (59 loc) · 1.95 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
package async_sequencer
import (
"context"
"time"
"github.com/code-payments/code-server/pkg/metrics"
"github.com/code-payments/code-server/pkg/code/common"
"github.com/code-payments/code-server/pkg/code/data/fulfillment"
)
const (
fulfillmentCountEventName = "FulfillmentCountPollingCheck"
subsidizerBalanceEventName = "SubsidizerBalancePollingCheck"
temporaryPrivateTransferScheduledEventName = "TemporaryPrivateTransferScheduled"
)
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()
for _, state := range []fulfillment.State{
fulfillment.StateUnknown,
fulfillment.StatePending,
fulfillment.StateFailed,
} {
countByType, err := p.data.GetFulfillmentCountForMetrics(ctx, state)
if err != nil {
continue
}
for fulfillmentType, count := range countByType {
recordFulfillmentCountEvent(ctx, fulfillmentType, state, count)
}
}
lamports, err := common.GetCurrentSubsidizerBalance(ctx, p.data)
if err == nil {
recordSubsidizerBalanceEvent(ctx, lamports)
}
delay = time.Second - time.Since(start)
}
}
}
func recordFulfillmentCountEvent(ctx context.Context, fulfillmentType fulfillment.Type, state fulfillment.State, count uint64) {
metrics.RecordEvent(ctx, fulfillmentCountEventName, map[string]interface{}{
"count": count,
"state": state.String(),
"type": fulfillmentType.String(),
})
}
func recordSubsidizerBalanceEvent(ctx context.Context, lamports uint64) {
metrics.RecordEvent(ctx, subsidizerBalanceEventName, map[string]interface{}{
"lamports": lamports,
})
}
func recordTemporaryPrivateTransferScheduledEvent(ctx context.Context, fulfillmentRecord *fulfillment.Record) {
metrics.RecordEvent(ctx, temporaryPrivateTransferScheduledEventName, map[string]interface{}{
"signature": *fulfillmentRecord.Signature,
})
}