Skip to content

Commit 5e68664

Browse files
committed
Add metric to count the number of rate-limited transactions per EOA
1 parent 64ab4a3 commit 5e68664

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

metrics/collector.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ var transactionsDroppedCounter = prometheus.NewCounter(prometheus.CounterOpts{
8282
Help: "Total number of EVM transactions dropped due to service errors",
8383
})
8484

85+
var eoaRateLimitedTransactions = prometheus.NewCounterVec(prometheus.CounterOpts{
86+
Name: prefixedName("eoa_rate_limited_transactions"),
87+
Help: "Total number of rate limited transactions by EOA",
88+
}, []string{"address"})
89+
8590
var metrics = []prometheus.Collector{
8691
apiErrors,
8792
serverPanicsCounters,
@@ -97,6 +102,7 @@ var metrics = []prometheus.Collector{
97102
blockIngestionTime,
98103
requestRateLimitedCounters,
99104
transactionsDroppedCounter,
105+
eoaRateLimitedTransactions,
100106
}
101107

102108
type Collector interface {
@@ -113,6 +119,7 @@ type Collector interface {
113119
BlockIngestionTime(blockCreation time.Time)
114120
RequestRateLimited(method string)
115121
TransactionsDropped(count int)
122+
EOARateLimited(address string)
116123
}
117124

118125
var _ Collector = &DefaultCollector{}
@@ -133,6 +140,7 @@ type DefaultCollector struct {
133140
blockIngestionTime prometheus.Histogram
134141
requestRateLimitedCounters *prometheus.CounterVec
135142
transactionsDroppedCounter prometheus.Counter
143+
eoaRateLimitedTransactions *prometheus.CounterVec
136144
}
137145

138146
func NewCollector(logger zerolog.Logger) Collector {
@@ -156,6 +164,7 @@ func NewCollector(logger zerolog.Logger) Collector {
156164
blockIngestionTime: blockIngestionTime,
157165
requestRateLimitedCounters: requestRateLimitedCounters,
158166
transactionsDroppedCounter: transactionsDroppedCounter,
167+
eoaRateLimitedTransactions: eoaRateLimitedTransactions,
159168
}
160169
}
161170

@@ -234,6 +243,12 @@ func (c *DefaultCollector) TransactionsDropped(count int) {
234243
c.transactionsDroppedCounter.Add(float64(count))
235244
}
236245

246+
func (c *DefaultCollector) EOARateLimited(address string) {
247+
c.eoaRateLimitedTransactions.
248+
With(prometheus.Labels{"address": address}).
249+
Inc()
250+
}
251+
237252
func prefixedName(name string) string {
238253
return fmt.Sprintf("evm_gateway_%s", name)
239254
}

metrics/nop.go

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

services/requester/requester.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (e *EVM) SendRawTransaction(ctx context.Context, data []byte) (common.Hash,
219219
return common.Hash{}, fmt.Errorf("failed to check rate limit: %w", err)
220220
}
221221
if !ok {
222-
e.collector.RequestRateLimited("SendRawTransaction")
222+
e.collector.EOARateLimited(from.Hex())
223223
return common.Hash{}, errs.ErrRateLimit
224224
}
225225
}

0 commit comments

Comments
 (0)