@@ -9,6 +9,84 @@ import (
99 "github.com/rs/zerolog"
1010)
1111
12+ var apiErrors = prometheus .NewCounter (prometheus.CounterOpts {
13+ Name : prefixedName ("api_errors_total" ),
14+ Help : "Total number of API errors" ,
15+ })
16+
17+ var serverPanicsCounters = prometheus .NewCounterVec (prometheus.CounterOpts {
18+ Name : prefixedName ("api_server_panics_total" ),
19+ Help : "Total number of panics in the API server" ,
20+ }, []string {"reason" })
21+
22+ var operatorBalance = prometheus .NewGauge (prometheus.GaugeOpts {
23+ Name : prefixedName ("operator_balance" ),
24+ Help : "Flow balance of the EVM gateway operator wallet" ,
25+ })
26+
27+ var cadenceBlockHeight = prometheus .NewGauge (prometheus.GaugeOpts {
28+ Name : prefixedName ("cadence_block_height" ),
29+ Help : "Current Cadence block height" ,
30+ })
31+
32+ var evmBlockHeight = prometheus .NewGauge (prometheus.GaugeOpts {
33+ Name : prefixedName ("evm_block_height" ),
34+ Help : "Current EVM block height" ,
35+ })
36+
37+ var evmBlockIndexedCounter = prometheus .NewCounter (prometheus.CounterOpts {
38+ Name : prefixedName ("blocks_indexed_total" ),
39+ Help : "Total number of blocks indexed" ,
40+ })
41+
42+ var evmTxIndexedCounter = prometheus .NewCounter (prometheus.CounterOpts {
43+ Name : prefixedName ("txs_indexed_total" ),
44+ Help : "Total number transactions indexed" ,
45+ })
46+
47+ var evmAccountCallCounters = prometheus .NewCounterVec (prometheus.CounterOpts {
48+ Name : prefixedName ("evm_account_interactions_total" ),
49+ Help : "Total number of account interactions" ,
50+ }, []string {"address" })
51+
52+ // TODO: Think of adding 'status_code'
53+ var requestDurations = prometheus .NewHistogramVec (prometheus.HistogramOpts {
54+ Name : prefixedName ("api_request_duration_seconds" ),
55+ Help : "Duration of the request made a specific API endpoint" ,
56+ Buckets : prometheus .DefBuckets ,
57+ }, []string {"method" })
58+
59+ var availableSigningKeys = prometheus .NewGauge (prometheus.GaugeOpts {
60+ Name : prefixedName ("available_signing_keys" ),
61+ Help : "Number of keys available for transaction signing" ,
62+ })
63+
64+ var gasEstimationIterations = prometheus .NewGauge (prometheus.GaugeOpts {
65+ Name : prefixedName ("gas_estimation_iterations" ),
66+ Help : "Number of iterations taken to estimate the gas of a EVM call/tx" ,
67+ })
68+
69+ var blockIngestionTime = prometheus .NewHistogram (prometheus.HistogramOpts {
70+ Name : prefixedName ("block_ingestion_time_seconds" ),
71+ Help : "Time taken to fully ingest an EVM block in the local state index" ,
72+ Buckets : prometheus .DefBuckets ,
73+ })
74+
75+ var metrics = []prometheus.Collector {
76+ apiErrors ,
77+ serverPanicsCounters ,
78+ cadenceBlockHeight ,
79+ evmBlockHeight ,
80+ evmBlockIndexedCounter ,
81+ evmTxIndexedCounter ,
82+ operatorBalance ,
83+ evmAccountCallCounters ,
84+ requestDurations ,
85+ availableSigningKeys ,
86+ gasEstimationIterations ,
87+ blockIngestionTime ,
88+ }
89+
1290type Collector interface {
1391 ApiErrorOccurred ()
1492 ServerPanicked (reason string )
@@ -42,83 +120,6 @@ type DefaultCollector struct {
42120}
43121
44122func NewCollector (logger zerolog.Logger ) Collector {
45- apiErrors := prometheus .NewCounter (prometheus.CounterOpts {
46- Name : prefixedName ("api_errors_total" ),
47- Help : "Total number of API errors" ,
48- })
49-
50- serverPanicsCounters := prometheus .NewCounterVec (prometheus.CounterOpts {
51- Name : prefixedName ("api_server_panics_total" ),
52- Help : "Total number of panics in the API server" ,
53- }, []string {"reason" })
54-
55- operatorBalance := prometheus .NewGauge (prometheus.GaugeOpts {
56- Name : prefixedName ("operator_balance" ),
57- Help : "Flow balance of the EVM gateway operator wallet" ,
58- })
59-
60- cadenceBlockHeight := prometheus .NewGauge (prometheus.GaugeOpts {
61- Name : prefixedName ("cadence_block_height" ),
62- Help : "Current Cadence block height" ,
63- })
64-
65- evmBlockHeight := prometheus .NewGauge (prometheus.GaugeOpts {
66- Name : prefixedName ("evm_block_height" ),
67- Help : "Current EVM block height" ,
68- })
69-
70- evmBlockIndexedCounter := prometheus .NewCounter (prometheus.CounterOpts {
71- Name : prefixedName ("blocks_indexed_total" ),
72- Help : "Total number of blocks indexed" ,
73- })
74-
75- evmTxIndexedCounter := prometheus .NewCounter (prometheus.CounterOpts {
76- Name : prefixedName ("txs_indexed_total" ),
77- Help : "Total number transactions indexed" ,
78- })
79-
80- evmAccountCallCounters := prometheus .NewCounterVec (prometheus.CounterOpts {
81- Name : prefixedName ("evm_account_interactions_total" ),
82- Help : "Total number of account interactions" ,
83- }, []string {"address" })
84-
85- // TODO: Think of adding 'status_code'
86- requestDurations := prometheus .NewHistogramVec (prometheus.HistogramOpts {
87- Name : prefixedName ("api_request_duration_seconds" ),
88- Help : "Duration of the request made a specific API endpoint" ,
89- Buckets : prometheus .DefBuckets ,
90- }, []string {"method" })
91-
92- availableSigningKeys := prometheus .NewGauge (prometheus.GaugeOpts {
93- Name : prefixedName ("available_signing_keys" ),
94- Help : "Number of keys available for transaction signing" ,
95- })
96-
97- gasEstimationIterations := prometheus .NewGauge (prometheus.GaugeOpts {
98- Name : prefixedName ("gas_estimation_iterations" ),
99- Help : "Number of iterations taken to estimate the gas of a EVM call/tx" ,
100- })
101-
102- blockIngestionTime := prometheus .NewHistogram (prometheus.HistogramOpts {
103- Name : prefixedName ("block_ingestion_time_seconds" ),
104- Help : "Time taken to fully ingest an EVM block in the local state index" ,
105- Buckets : prometheus .DefBuckets ,
106- })
107-
108- metrics := []prometheus.Collector {
109- apiErrors ,
110- serverPanicsCounters ,
111- cadenceBlockHeight ,
112- evmBlockHeight ,
113- evmBlockIndexedCounter ,
114- evmTxIndexedCounter ,
115- operatorBalance ,
116- evmAccountCallCounters ,
117- requestDurations ,
118- availableSigningKeys ,
119- gasEstimationIterations ,
120- blockIngestionTime ,
121- }
122123 if err := registerMetrics (logger , metrics ... ); err != nil {
123124 logger .Info ().Msg ("using noop collector as metric register failed" )
124125 return NopCollector
@@ -142,6 +143,10 @@ func NewCollector(logger zerolog.Logger) Collector {
142143
143144func registerMetrics (logger zerolog.Logger , metrics ... prometheus.Collector ) error {
144145 for _ , m := range metrics {
146+ // During E2E tests, the EVM GW might be bootstrapped again
147+ // and again, so we make sure to register the metrics on a
148+ // clean state.
149+ prometheus .Unregister (m )
145150 if err := prometheus .Register (m ); err != nil {
146151 logger .Err (err ).Msg ("failed to register metric" )
147152 return err
0 commit comments