-
Notifications
You must be signed in to change notification settings - Fork 143
/
chain_state_manager.go
343 lines (309 loc) · 13 KB
/
chain_state_manager.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/iotaledger/wasp/packages/isc"
)
type ChainStateManagerMetricsProvider struct {
// chain state / tips
chainActiveStateWant *prometheus.GaugeVec
chainActiveStateHave *prometheus.GaugeVec
chainConfirmedStateWant *prometheus.GaugeVec
chainConfirmedStateHave *prometheus.GaugeVec
chainConfirmedStateLag ChainStateLag
// state manager
cacheSize *prometheus.GaugeVec
blocksFetching *prometheus.GaugeVec
blocksPending *prometheus.GaugeVec
blocksCommitted *countAndMaxMetrics
requestsWaiting *prometheus.GaugeVec
cspHandlingDuration *prometheus.HistogramVec
cdsHandlingDuration *prometheus.HistogramVec
cbpHandlingDuration *prometheus.HistogramVec
fsdHandlingDuration *prometheus.HistogramVec
ttHandlingDuration *prometheus.HistogramVec
blockFetchDuration *prometheus.HistogramVec
pruningRunDuration *prometheus.HistogramVec
pruningSingleStateDuration *prometheus.HistogramVec
pruningStatesInRun *prometheus.HistogramVec
statesPruned *countAndMaxMetrics
}
//nolint:funlen
func newChainStateManagerMetricsProvider() *ChainStateManagerMetricsProvider {
return &ChainStateManagerMetricsProvider{
//
// chain state / tips.
//
chainActiveStateWant: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "iota_wasp",
Subsystem: "chain",
Name: "active_state_want",
Help: "We try to get blocks till this StateIndex for the active state.",
}, []string{labelNameChain}),
chainActiveStateHave: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "iota_wasp",
Subsystem: "chain",
Name: "active_state_have",
Help: "We received blocks till this StateIndex for the active state.",
}, []string{labelNameChain}),
chainConfirmedStateWant: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "iota_wasp",
Subsystem: "chain",
Name: "confirmed_state_want",
Help: "We try to get blocks till this StateIndex for the confirmed state.",
}, []string{labelNameChain}),
chainConfirmedStateHave: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "iota_wasp",
Subsystem: "chain",
Name: "confirmed_state_have",
Help: "We received blocks till this StateIndex for the confirmed state.",
}, []string{labelNameChain}),
//
// state manager
//
cacheSize: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "cache_size",
Help: "Number of blocks stored in cache",
}, []string{labelNameChain}),
blocksFetching: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "blocks_fetching",
Help: "Number of blocks the node is waiting from other nodes",
}, []string{labelNameChain}),
blocksPending: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "blocks_pending",
Help: "Number of blocks the node has fetched but hasn't committed, because the node doesn't have their ancestors",
}, []string{labelNameChain}),
blocksCommitted: newCountAndMaxMetrics(
prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "blocks_committed",
Help: "Number of blocks the node has committed to the store",
}, []string{labelNameChain}),
prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "max_blocks_index_committed",
Help: "Largest index of block committed to the store",
}, []string{labelNameChain}),
),
requestsWaiting: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "requests_waiting",
Help: "Number of requests from other components of the node waiting for response from the state manager. Note that StateDiff request is counted as two requests as it has to obtain two possibly different blocks.",
}, []string{labelNameChain}),
cspHandlingDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "consensus_state_proposal_duration",
Help: "The duration (s) from starting handling ConsensusStateProposal request till responding to the consensus",
Buckets: execTimeBuckets,
}, []string{labelNameChain}),
cdsHandlingDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "consensus_decided_state_duration",
Help: "The duration (s) from starting handling ConsensusDecidedState request till responding to the consensus",
Buckets: execTimeBuckets,
}, []string{labelNameChain}),
cbpHandlingDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "consensus_block_produced_duration",
Help: "The duration (s) from starting till finishing handling ConsensusBlockProduced, which includes responding to the consensus",
Buckets: execTimeBuckets,
}, []string{labelNameChain}),
fsdHandlingDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "chain_fetch_state_diff_duration",
Help: "The duration (s) from starting handling ChainFetchStateDiff request till responding to the chain",
Buckets: execTimeBuckets,
}, []string{labelNameChain}),
ttHandlingDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "timer_tick_duration",
Help: "The duration (s) from starting till finishing handling StateManagerTimerTick request",
Buckets: execTimeBuckets,
}, []string{labelNameChain}),
blockFetchDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "block_fetch_duration",
Help: "The duration (s) from starting fetching block from other till it is received in this node",
Buckets: execTimeBuckets,
}, []string{labelNameChain}),
pruningRunDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "pruning_run_duration",
Help: "The duration (s) from starting till finishing pruning run, which may include pruning several states from store",
Buckets: execTimeBuckets,
}, []string{labelNameChain}),
pruningSingleStateDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "pruning_single_state_duration",
Help: "The duration (s) from starting till finishing pruning single state from store",
Buckets: execTimeBuckets,
}, []string{labelNameChain}),
pruningStatesInRun: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "pruning_states_in_run",
Help: "Number of states pruned in single pruning run (should be 1 in normally running nodes)",
Buckets: recCountBuckets,
}, []string{labelNameChain}),
statesPruned: newCountAndMaxMetrics(
prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "sates_pruned",
Help: "Number of states pruned in total since starting the node",
}, []string{labelNameChain}),
prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "iota_wasp",
Subsystem: "state_manager",
Name: "max_state_index_pruned",
Help: "Largest index of state pruned from the store",
}, []string{labelNameChain}),
),
chainConfirmedStateLag: make(ChainStateLag),
}
}
func (p *ChainStateManagerMetricsProvider) register(reg prometheus.Registerer) {
reg.MustRegister(
p.chainActiveStateWant,
p.chainActiveStateHave,
p.chainConfirmedStateWant,
p.chainConfirmedStateHave,
)
reg.MustRegister(
p.cacheSize,
p.blocksFetching,
p.blocksPending,
p.requestsWaiting,
p.cspHandlingDuration,
p.cdsHandlingDuration,
p.cbpHandlingDuration,
p.fsdHandlingDuration,
p.ttHandlingDuration,
p.blockFetchDuration,
p.pruningRunDuration,
p.pruningSingleStateDuration,
p.pruningStatesInRun,
)
reg.MustRegister(p.blocksCommitted.collectors()...)
reg.MustRegister(p.statesPruned.collectors()...)
}
func (p *ChainStateManagerMetricsProvider) createForChain(chainID isc.ChainID) *ChainStateManagerMetrics {
labels := getChainLabels(chainID)
// init values so they appear in prometheus
p.chainActiveStateWant.With(labels)
p.chainActiveStateHave.With(labels)
p.chainConfirmedStateWant.With(labels)
p.chainConfirmedStateHave.With(labels)
p.cacheSize.With(labels)
p.blocksFetching.With(labels)
p.blocksPending.With(labels)
p.blocksCommitted.with(labels)
p.requestsWaiting.With(labels)
p.cspHandlingDuration.With(labels)
p.cdsHandlingDuration.With(labels)
p.cbpHandlingDuration.With(labels)
p.fsdHandlingDuration.With(labels)
p.ttHandlingDuration.With(labels)
p.blockFetchDuration.With(labels)
p.pruningRunDuration.With(labels)
p.pruningSingleStateDuration.With(labels)
p.pruningStatesInRun.With(labels)
p.statesPruned.with(labels)
return &ChainStateManagerMetrics{
chainID: chainID,
collectors: p,
labels: labels,
}
}
func (p *ChainStateManagerMetricsProvider) MaxChainConfirmedStateLag() uint32 {
return p.chainConfirmedStateLag.MaxLag()
}
type ChainStateManagerMetrics struct {
chainID isc.ChainID
labels prometheus.Labels
collectors *ChainStateManagerMetricsProvider
}
func (m *ChainStateManagerMetrics) SetChainActiveStateWant(stateIndex uint32) {
m.collectors.chainActiveStateWant.With(m.labels).Set(float64(stateIndex))
}
func (m *ChainStateManagerMetrics) SetChainActiveStateHave(stateIndex uint32) {
m.collectors.chainActiveStateHave.With(m.labels).Set(float64(stateIndex))
}
func (m *ChainStateManagerMetrics) SetChainConfirmedStateWant(stateIndex uint32) {
m.collectors.chainConfirmedStateWant.With(m.labels).Set(float64(stateIndex))
m.collectors.chainConfirmedStateLag.Want(m.chainID, stateIndex)
}
func (m *ChainStateManagerMetrics) SetChainConfirmedStateHave(stateIndex uint32) {
m.collectors.chainConfirmedStateHave.With(m.labels).Set(float64(stateIndex))
m.collectors.chainConfirmedStateLag.Have(m.chainID, stateIndex)
}
func (m *ChainStateManagerMetrics) SetCacheSize(size int) {
m.collectors.cacheSize.With(m.labels).Set(float64(size))
}
func (m *ChainStateManagerMetrics) IncBlocksFetching() {
m.collectors.blocksFetching.With(m.labels).Inc()
}
func (m *ChainStateManagerMetrics) DecBlocksFetching() {
m.collectors.blocksFetching.With(m.labels).Dec()
}
func (m *ChainStateManagerMetrics) IncBlocksPending() {
m.collectors.blocksPending.With(m.labels).Inc()
}
func (m *ChainStateManagerMetrics) DecBlocksPending() {
m.collectors.blocksPending.With(m.labels).Dec()
}
func (m *ChainStateManagerMetrics) BlockIndexCommitted(blockIndex uint32) {
m.collectors.blocksCommitted.countValue(m.labels, float64(blockIndex))
}
func (m *ChainStateManagerMetrics) IncRequestsWaiting() {
m.collectors.requestsWaiting.With(m.labels).Inc()
}
func (m *ChainStateManagerMetrics) SubRequestsWaiting(count int) {
m.collectors.requestsWaiting.With(m.labels).Sub(float64(count))
}
func (m *ChainStateManagerMetrics) SetRequestsWaiting(count int) {
m.collectors.requestsWaiting.With(m.labels).Set(float64(count))
}
func (m *ChainStateManagerMetrics) ConsensusStateProposalHandled(duration time.Duration) {
m.collectors.cspHandlingDuration.With(m.labels).Observe(duration.Seconds())
}
func (m *ChainStateManagerMetrics) ConsensusDecidedStateHandled(duration time.Duration) {
m.collectors.cdsHandlingDuration.With(m.labels).Observe(duration.Seconds())
}
func (m *ChainStateManagerMetrics) ConsensusBlockProducedHandled(duration time.Duration) {
m.collectors.cbpHandlingDuration.With(m.labels).Observe(duration.Seconds())
}
func (m *ChainStateManagerMetrics) ChainFetchStateDiffHandled(duration time.Duration) {
m.collectors.fsdHandlingDuration.With(m.labels).Observe(duration.Seconds())
}
func (m *ChainStateManagerMetrics) StateManagerTimerTickHandled(duration time.Duration) {
m.collectors.ttHandlingDuration.With(m.labels).Observe(duration.Seconds())
}
func (m *ChainStateManagerMetrics) StateManagerBlockFetched(duration time.Duration) {
m.collectors.blockFetchDuration.With(m.labels).Observe(duration.Seconds())
}
func (m *ChainStateManagerMetrics) StatePruned(duration time.Duration, stateIndex uint32) {
m.collectors.pruningSingleStateDuration.With(m.labels).Observe(duration.Seconds())
m.collectors.statesPruned.countValue(m.labels, float64(stateIndex))
}
func (m *ChainStateManagerMetrics) PruningCompleted(duration time.Duration, statesPruned int) {
m.collectors.pruningRunDuration.With(m.labels).Observe(duration.Seconds())
m.collectors.pruningStatesInRun.With(m.labels).Observe(float64(statesPruned))
}