-
Notifications
You must be signed in to change notification settings - Fork 175
/
execution_state_indexer.go
97 lines (81 loc) · 3.36 KB
/
execution_state_indexer.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
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/onflow/flow-go/module"
)
var _ module.ExecutionStateIndexerMetrics = (*ExecutionStateIndexerCollector)(nil)
type ExecutionStateIndexerCollector struct {
indexDuration prometheus.Histogram
highestIndexedHeight prometheus.Gauge
indexedEvents prometheus.Counter
indexedRegisters prometheus.Counter
indexedTransactionResults prometheus.Counter
reindexedHeightCount prometheus.Counter
}
func NewExecutionStateIndexerCollector() module.ExecutionStateIndexerMetrics {
indexDuration := promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: namespaceAccess,
Subsystem: subsystemExecutionStateIndexer,
Name: "index_duration_ms",
Help: "the duration of execution state indexing operation",
Buckets: []float64{1, 5, 10, 50, 100},
})
highestIndexedHeight := promauto.NewGauge(prometheus.GaugeOpts{
Namespace: namespaceAccess,
Subsystem: subsystemExecutionStateIndexer,
Name: "highest_indexed_height",
Help: "highest block height that has been indexed",
})
indexedEvents := promauto.NewCounter(prometheus.CounterOpts{
Namespace: namespaceAccess,
Subsystem: subsystemExecutionStateIndexer,
Name: "indexed_events",
Help: "number of events indexed",
})
indexedRegisters := promauto.NewCounter(prometheus.CounterOpts{
Namespace: namespaceAccess,
Subsystem: subsystemExecutionStateIndexer,
Name: "indexed_registers",
Help: "number of registers indexed",
})
indexedTransactionResults := promauto.NewCounter(prometheus.CounterOpts{
Namespace: namespaceAccess,
Subsystem: subsystemExecutionStateIndexer,
Name: "indexed_transaction_results",
Help: "number of transaction results indexed",
})
reindexedHeightCount := promauto.NewCounter(prometheus.CounterOpts{
Namespace: namespaceAccess,
Subsystem: subsystemExecutionStateIndexer,
Name: "reindexed_height_count",
Help: "number of times a previously indexed height is reindexed",
})
return &ExecutionStateIndexerCollector{
indexDuration: indexDuration,
highestIndexedHeight: highestIndexedHeight,
indexedEvents: indexedEvents,
indexedRegisters: indexedRegisters,
indexedTransactionResults: indexedTransactionResults,
reindexedHeightCount: reindexedHeightCount,
}
}
// InitializeLatestHeight records the latest height that has been indexed.
// This should only be used during startup. After startup, use BlockIndexed to record newly
// indexed heights.
func (c *ExecutionStateIndexerCollector) InitializeLatestHeight(height uint64) {
c.highestIndexedHeight.Set(float64(height))
}
// BlockIndexed records metrics from indexing execution data from a single block.
func (c *ExecutionStateIndexerCollector) BlockIndexed(height uint64, duration time.Duration, events, registers, transactionResults int) {
c.indexDuration.Observe(float64(duration.Milliseconds()))
c.highestIndexedHeight.Set(float64(height))
c.indexedEvents.Add(float64(events))
c.indexedRegisters.Add(float64(registers))
c.indexedTransactionResults.Add(float64(transactionResults))
}
// BlockReindexed records that a previously indexed block was indexed again.
func (c *ExecutionStateIndexerCollector) BlockReindexed() {
c.reindexedHeightCount.Inc()
}