Skip to content

Commit ab059ad

Browse files
committed
Add metric to count the number of rate-limited transactions per EOA
1 parent c732a56 commit ab059ad

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
@@ -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 eoaRateLimitedTransactions = prometheus.NewCounterVec(prometheus.CounterOpts{
81+
Name: prefixedName("eoa_rate_limited_transactions"),
82+
Help: "Total number of rate limited transactions by EOA",
83+
}, []string{"address"})
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+
eoaRateLimitedTransactions,
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+
EOARateLimited(address string)
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+
eoaRateLimitedTransactions *prometheus.CounterVec
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+
eoaRateLimitedTransactions: eoaRateLimitedTransactions,
150159
}
151160
}
152161

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

233+
func (c *DefaultCollector) EOARateLimited(address string) {
234+
c.eoaRateLimitedTransactions.
235+
With(prometheus.Labels{"address": address}).
236+
Inc()
237+
}
238+
224239
func prefixedName(name string) string {
225240
return fmt.Sprintf("evm_gateway_%s", name)
226241
}

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) 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)