Skip to content

Commit 64ab4a3

Browse files
authored
Merge pull request #837 from onflow/mpeter/add-transactions-dropped-counter
Add metric for the total number of dropped EVM transactions
2 parents d46ae32 + 4f41ae1 commit 64ab4a3

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

metrics/collector.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var evmBlockIndexedCounter = prometheus.NewCounter(prometheus.CounterOpts{
4141

4242
var evmTxIndexedCounter = prometheus.NewCounter(prometheus.CounterOpts{
4343
Name: prefixedName("txs_indexed_total"),
44-
Help: "Total number transactions indexed",
44+
Help: "Total number of transactions indexed",
4545
})
4646

4747
var evmAccountCallCounters = prometheus.NewCounterVec(prometheus.CounterOpts{
@@ -77,6 +77,11 @@ var requestRateLimitedCounters = prometheus.NewCounterVec(prometheus.CounterOpts
7777
Help: "Total number of rate limits by JSON-RPC method",
7878
}, []string{"method"})
7979

80+
var transactionsDroppedCounter = prometheus.NewCounter(prometheus.CounterOpts{
81+
Name: prefixedName("transactions_dropped_total"),
82+
Help: "Total number of EVM transactions dropped due to service errors",
83+
})
84+
8085
var metrics = []prometheus.Collector{
8186
apiErrors,
8287
serverPanicsCounters,
@@ -91,6 +96,7 @@ var metrics = []prometheus.Collector{
9196
gasEstimationIterations,
9297
blockIngestionTime,
9398
requestRateLimitedCounters,
99+
transactionsDroppedCounter,
94100
}
95101

96102
type Collector interface {
@@ -106,6 +112,7 @@ type Collector interface {
106112
GasEstimationIterations(count int)
107113
BlockIngestionTime(blockCreation time.Time)
108114
RequestRateLimited(method string)
115+
TransactionsDropped(count int)
109116
}
110117

111118
var _ Collector = &DefaultCollector{}
@@ -125,6 +132,7 @@ type DefaultCollector struct {
125132
gasEstimationIterations prometheus.Gauge
126133
blockIngestionTime prometheus.Histogram
127134
requestRateLimitedCounters *prometheus.CounterVec
135+
transactionsDroppedCounter prometheus.Counter
128136
}
129137

130138
func NewCollector(logger zerolog.Logger) Collector {
@@ -147,6 +155,7 @@ func NewCollector(logger zerolog.Logger) Collector {
147155
gasEstimationIterations: gasEstimationIterations,
148156
blockIngestionTime: blockIngestionTime,
149157
requestRateLimitedCounters: requestRateLimitedCounters,
158+
transactionsDroppedCounter: transactionsDroppedCounter,
150159
}
151160
}
152161

@@ -221,6 +230,10 @@ func (c *DefaultCollector) RequestRateLimited(method string) {
221230
).Inc()
222231
}
223232

233+
func (c *DefaultCollector) TransactionsDropped(count int) {
234+
c.transactionsDroppedCounter.Add(float64(count))
235+
}
236+
224237
func prefixedName(name string) string {
225238
return fmt.Sprintf("evm_gateway_%s", name)
226239
}

metrics/nop.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ func (c *nopCollector) AvailableSigningKeys(count int) {}
2424
func (c *nopCollector) GasEstimationIterations(count int) {}
2525
func (c *nopCollector) BlockIngestionTime(blockCreation time.Time) {}
2626
func (c *nopCollector) RequestRateLimited(method string) {}
27+
func (c *nopCollector) TransactionsDropped(count int) {}

services/requester/batch_tx_pool.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ func (t *BatchTxPool) batchSubmitTransactionsForSameAddress(
260260
coinbaseAddress,
261261
)
262262
if err != nil {
263+
// If there was any error during the transaction build
264+
// process, we record all transactions as dropped.
265+
t.collector.TransactionsDropped(len(hexEncodedTxs))
263266
return err
264267
}
265268

@@ -293,6 +296,9 @@ func (t *BatchTxPool) submitSingleTransaction(
293296
coinbaseAddress,
294297
)
295298
if err != nil {
299+
// If there was any error during the transaction build
300+
// process, we record it as a dropped transaction.
301+
t.collector.TransactionsDropped(1)
296302
return err
297303
}
298304

services/requester/single_tx_pool.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ func (t *SingleTxPool) Add(
107107
coinbaseAddress,
108108
)
109109
if err != nil {
110+
// If there was any error during the transaction build
111+
// process, we record it as a dropped transaction.
112+
t.collector.TransactionsDropped(1)
110113
return err
111114
}
112115

0 commit comments

Comments
 (0)