-
Notifications
You must be signed in to change notification settings - Fork 178
/
execution_data_requester.go
110 lines (90 loc) · 3.67 KB
/
execution_data_requester.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
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/onflow/flow-go/module"
)
type ExecutionDataRequesterCollector struct {
fetchDuration prometheus.Histogram
downloadsInProgress prometheus.Gauge
outstandingNotifications prometheus.Gauge
highestNotificationHeight prometheus.Gauge
highestDownloadHeight prometheus.Gauge
downloadRetries prometheus.Counter
failedDownloads prometheus.Counter
}
func NewExecutionDataRequesterCollector() module.ExecutionDataRequesterMetrics {
fetchDuration := promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: namespaceStateSync,
Subsystem: subsystemExecutionDataRequester,
Name: "execution_requester_download_duration_ms",
Help: "the duration of execution data download operation",
Buckets: []float64{1, 100, 500, 1000, 2000, 5000},
})
downloadsInProgress := promauto.NewGauge(prometheus.GaugeOpts{
Namespace: namespaceStateSync,
Subsystem: subsystemExecutionDataRequester,
Name: "execution_requester_in_progress_downloads",
Help: "number of concurrently running execution data download operations",
})
outstandingNotifications := promauto.NewGauge(prometheus.GaugeOpts{
Namespace: namespaceStateSync,
Subsystem: subsystemExecutionDataRequester,
Name: "execution_requester_outstanding_notifications",
Help: "number of execution data received notifications waiting to be processed",
})
highestDownloadHeight := promauto.NewGauge(prometheus.GaugeOpts{
Namespace: namespaceStateSync,
Subsystem: subsystemExecutionDataRequester,
Name: "execution_requester_highest_download_height",
Help: "highest block height for which execution data has been received",
})
highestNotificationHeight := promauto.NewGauge(prometheus.GaugeOpts{
Namespace: namespaceStateSync,
Subsystem: subsystemExecutionDataRequester,
Name: "execution_requester_highest_notification_height",
Help: "highest block height for which execution data notifications have been sent",
})
downloadRetries := promauto.NewCounter(prometheus.CounterOpts{
Namespace: namespaceStateSync,
Subsystem: subsystemExecutionDataRequester,
Name: "execution_requester_download_retries_total",
Help: "number of execution data download retries",
})
failedDownloads := promauto.NewCounter(prometheus.CounterOpts{
Namespace: namespaceStateSync,
Subsystem: subsystemExecutionDataRequester,
Name: "execution_data_failed_downloads_total",
Help: "number of failed execution data downloads",
})
return &ExecutionDataRequesterCollector{
fetchDuration: fetchDuration,
downloadsInProgress: downloadsInProgress,
outstandingNotifications: outstandingNotifications,
highestDownloadHeight: highestDownloadHeight,
highestNotificationHeight: highestNotificationHeight,
downloadRetries: downloadRetries,
failedDownloads: failedDownloads,
}
}
func (ec *ExecutionDataRequesterCollector) ExecutionDataFetchStarted() {
ec.downloadsInProgress.Inc()
}
func (ec *ExecutionDataRequesterCollector) ExecutionDataFetchFinished(duration time.Duration, success bool, height uint64) {
ec.downloadsInProgress.Dec()
ec.fetchDuration.Observe(float64(duration.Milliseconds()))
if success {
ec.highestDownloadHeight.Set(float64(height))
ec.outstandingNotifications.Inc()
} else {
ec.failedDownloads.Inc()
}
}
func (ec *ExecutionDataRequesterCollector) NotificationSent(height uint64) {
ec.outstandingNotifications.Dec()
ec.highestNotificationHeight.Set(float64(height))
}
func (ec *ExecutionDataRequesterCollector) FetchRetried() {
ec.downloadRetries.Inc()
}