-
Notifications
You must be signed in to change notification settings - Fork 178
/
access.go
155 lines (133 loc) · 4.98 KB
/
access.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/onflow/flow-go/module"
"github.com/onflow/flow-go/module/counters"
)
type AccessCollectorOpts func(*AccessCollector)
func WithTransactionMetrics(m module.TransactionMetrics) AccessCollectorOpts {
return func(ac *AccessCollector) {
ac.TransactionMetrics = m
}
}
func WithBackendScriptsMetrics(m module.BackendScriptsMetrics) AccessCollectorOpts {
return func(ac *AccessCollector) {
ac.BackendScriptsMetrics = m
}
}
func WithRestMetrics(m module.RestMetrics) AccessCollectorOpts {
return func(ac *AccessCollector) {
ac.RestMetrics = m
}
}
type AccessCollector struct {
module.RestMetrics
module.TransactionMetrics
module.BackendScriptsMetrics
connectionReused prometheus.Counter
connectionsInPool *prometheus.GaugeVec
connectionAdded prometheus.Counter
connectionEstablished prometheus.Counter
connectionInvalidated prometheus.Counter
connectionUpdated prometheus.Counter
connectionEvicted prometheus.Counter
lastFullBlockHeight prometheus.Gauge
maxReceiptHeight prometheus.Gauge
// used to skip heights that are lower than the current max height
maxReceiptHeightValue counters.StrictMonotonousCounter
}
var _ module.AccessMetrics = (*AccessCollector)(nil)
func NewAccessCollector(opts ...AccessCollectorOpts) *AccessCollector {
ac := &AccessCollector{
connectionReused: promauto.NewCounter(prometheus.CounterOpts{
Name: "connection_reused",
Namespace: namespaceAccess,
Subsystem: subsystemConnectionPool,
Help: "counter for the number of times connections get reused",
}),
connectionsInPool: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "connections_in_pool",
Namespace: namespaceAccess,
Subsystem: subsystemConnectionPool,
Help: "counter for the number of connections in the pool against max number tne pool can hold",
}, []string{"result"}),
connectionAdded: promauto.NewCounter(prometheus.CounterOpts{
Name: "connection_added",
Namespace: namespaceAccess,
Subsystem: subsystemConnectionPool,
Help: "counter for the number of times connections are added to the pool",
}),
connectionEstablished: promauto.NewCounter(prometheus.CounterOpts{
Name: "connection_established",
Namespace: namespaceAccess,
Subsystem: subsystemConnectionPool,
Help: "counter for the number of times connections are established",
}),
connectionInvalidated: promauto.NewCounter(prometheus.CounterOpts{
Name: "connection_invalidated",
Namespace: namespaceAccess,
Subsystem: subsystemConnectionPool,
Help: "counter for the number of times connections are invalidated",
}),
connectionUpdated: promauto.NewCounter(prometheus.CounterOpts{
Name: "connection_updated",
Namespace: namespaceAccess,
Subsystem: subsystemConnectionPool,
Help: "counter for the number of times existing connections from the pool are updated",
}),
connectionEvicted: promauto.NewCounter(prometheus.CounterOpts{
Name: "connection_evicted",
Namespace: namespaceAccess,
Subsystem: subsystemConnectionPool,
Help: "counter for the number of times a cached connection is evicted from the connection pool",
}),
lastFullBlockHeight: promauto.NewGauge(prometheus.GaugeOpts{
Name: "last_full_finalized_block_height",
Namespace: namespaceAccess,
Subsystem: subsystemIngestion,
Help: "gauge to track the highest consecutive finalized block height with all collections indexed",
}),
maxReceiptHeight: promauto.NewGauge(prometheus.GaugeOpts{
Name: "max_receipt_height",
Namespace: namespaceAccess,
Subsystem: subsystemIngestion,
Help: "gauge to track the maximum block height of execution receipts received",
}),
maxReceiptHeightValue: counters.NewMonotonousCounter(0),
}
for _, opt := range opts {
opt(ac)
}
return ac
}
func (ac *AccessCollector) ConnectionFromPoolReused() {
ac.connectionReused.Inc()
}
func (ac *AccessCollector) TotalConnectionsInPool(connectionCount uint, connectionPoolSize uint) {
ac.connectionsInPool.WithLabelValues("connections").Set(float64(connectionCount))
ac.connectionsInPool.WithLabelValues("pool_size").Set(float64(connectionPoolSize))
}
func (ac *AccessCollector) ConnectionAddedToPool() {
ac.connectionAdded.Inc()
}
func (ac *AccessCollector) NewConnectionEstablished() {
ac.connectionEstablished.Inc()
}
func (ac *AccessCollector) ConnectionFromPoolInvalidated() {
ac.connectionInvalidated.Inc()
}
func (ac *AccessCollector) ConnectionFromPoolUpdated() {
ac.connectionUpdated.Inc()
}
func (ac *AccessCollector) ConnectionFromPoolEvicted() {
ac.connectionEvicted.Inc()
}
func (ac *AccessCollector) UpdateLastFullBlockHeight(height uint64) {
ac.lastFullBlockHeight.Set(float64(height))
}
func (ac *AccessCollector) UpdateExecutionReceiptMaxHeight(height uint64) {
if ac.maxReceiptHeightValue.Set(height) {
ac.maxReceiptHeight.Set(float64(height))
}
}