Skip to content

Commit a74c713

Browse files
committed
Use plain Counter instead of CounterVec for the number of rate-limited transactions
1 parent ab059ad commit a74c713

File tree

3 files changed

+38
-40
lines changed

3 files changed

+38
-40
lines changed

metrics/collector.go

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ 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"})
80+
var rateLimitedTransactionsCounter = prometheus.NewCounter(prometheus.CounterOpts{
81+
Name: prefixedName("rate_limited_transactions_total"),
82+
Help: "Total number of rate-limited transactions",
83+
})
8484

8585
var metrics = []prometheus.Collector{
8686
apiErrors,
@@ -96,7 +96,7 @@ var metrics = []prometheus.Collector{
9696
gasEstimationIterations,
9797
blockIngestionTime,
9898
requestRateLimitedCounters,
99-
eoaRateLimitedTransactions,
99+
rateLimitedTransactionsCounter,
100100
}
101101

102102
type Collector interface {
@@ -112,27 +112,27 @@ type Collector interface {
112112
GasEstimationIterations(count int)
113113
BlockIngestionTime(blockCreation time.Time)
114114
RequestRateLimited(method string)
115-
EOARateLimited(address string)
115+
TransactionRateLimited()
116116
}
117117

118118
var _ Collector = &DefaultCollector{}
119119

120120
type DefaultCollector struct {
121121
// TODO: for now we cannot differentiate which api request failed number of times
122-
apiErrorsCounter prometheus.Counter
123-
serverPanicsCounters *prometheus.CounterVec
124-
cadenceBlockHeight prometheus.Gauge
125-
evmBlockHeight prometheus.Gauge
126-
evmBlockIndexedCounter prometheus.Counter
127-
evmTxIndexedCounter prometheus.Counter
128-
operatorBalance prometheus.Gauge
129-
evmAccountCallCounters *prometheus.CounterVec
130-
requestDurations *prometheus.HistogramVec
131-
availableSigningkeys prometheus.Gauge
132-
gasEstimationIterations prometheus.Gauge
133-
blockIngestionTime prometheus.Histogram
134-
requestRateLimitedCounters *prometheus.CounterVec
135-
eoaRateLimitedTransactions *prometheus.CounterVec
122+
apiErrorsCounter prometheus.Counter
123+
serverPanicsCounters *prometheus.CounterVec
124+
cadenceBlockHeight prometheus.Gauge
125+
evmBlockHeight prometheus.Gauge
126+
evmBlockIndexedCounter prometheus.Counter
127+
evmTxIndexedCounter prometheus.Counter
128+
operatorBalance prometheus.Gauge
129+
evmAccountCallCounters *prometheus.CounterVec
130+
requestDurations *prometheus.HistogramVec
131+
availableSigningkeys prometheus.Gauge
132+
gasEstimationIterations prometheus.Gauge
133+
blockIngestionTime prometheus.Histogram
134+
requestRateLimitedCounters *prometheus.CounterVec
135+
rateLimitedTransactionsCounter prometheus.Counter
136136
}
137137

138138
func NewCollector(logger zerolog.Logger) Collector {
@@ -142,20 +142,20 @@ func NewCollector(logger zerolog.Logger) Collector {
142142
}
143143

144144
return &DefaultCollector{
145-
apiErrorsCounter: apiErrors,
146-
serverPanicsCounters: serverPanicsCounters,
147-
cadenceBlockHeight: cadenceBlockHeight,
148-
evmBlockHeight: evmBlockHeight,
149-
evmBlockIndexedCounter: evmBlockIndexedCounter,
150-
evmTxIndexedCounter: evmTxIndexedCounter,
151-
evmAccountCallCounters: evmAccountCallCounters,
152-
requestDurations: requestDurations,
153-
operatorBalance: operatorBalance,
154-
availableSigningkeys: availableSigningKeys,
155-
gasEstimationIterations: gasEstimationIterations,
156-
blockIngestionTime: blockIngestionTime,
157-
requestRateLimitedCounters: requestRateLimitedCounters,
158-
eoaRateLimitedTransactions: eoaRateLimitedTransactions,
145+
apiErrorsCounter: apiErrors,
146+
serverPanicsCounters: serverPanicsCounters,
147+
cadenceBlockHeight: cadenceBlockHeight,
148+
evmBlockHeight: evmBlockHeight,
149+
evmBlockIndexedCounter: evmBlockIndexedCounter,
150+
evmTxIndexedCounter: evmTxIndexedCounter,
151+
evmAccountCallCounters: evmAccountCallCounters,
152+
requestDurations: requestDurations,
153+
operatorBalance: operatorBalance,
154+
availableSigningkeys: availableSigningKeys,
155+
gasEstimationIterations: gasEstimationIterations,
156+
blockIngestionTime: blockIngestionTime,
157+
requestRateLimitedCounters: requestRateLimitedCounters,
158+
rateLimitedTransactionsCounter: rateLimitedTransactionsCounter,
159159
}
160160
}
161161

@@ -230,10 +230,8 @@ func (c *DefaultCollector) RequestRateLimited(method string) {
230230
).Inc()
231231
}
232232

233-
func (c *DefaultCollector) EOARateLimited(address string) {
234-
c.eoaRateLimitedTransactions.
235-
With(prometheus.Labels{"address": address}).
236-
Inc()
233+
func (c *DefaultCollector) TransactionRateLimited() {
234+
c.rateLimitedTransactionsCounter.Inc()
237235
}
238236

239237
func prefixedName(name string) string {

metrics/nop.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +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) {}
27+
func (c *nopCollector) TransactionRateLimited() {}

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.EOARateLimited(from.Hex())
222+
e.collector.TransactionRateLimited()
223223
return common.Hash{}, errs.ErrRateLimit
224224
}
225225
}

0 commit comments

Comments
 (0)