Skip to content

Commit add299d

Browse files
committed
Use plain Counter instead of CounterVec for the number of rate-limited transactions
1 parent 5e68664 commit add299d

File tree

3 files changed

+40
-42
lines changed

3 files changed

+40
-42
lines changed

metrics/collector.go

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ 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"})
85+
var rateLimitedTransactionsCounter = prometheus.NewCounter(prometheus.CounterOpts{
86+
Name: prefixedName("rate_limited_transactions_total"),
87+
Help: "Total number of rate-limited transactions",
88+
})
8989

9090
var metrics = []prometheus.Collector{
9191
apiErrors,
@@ -102,7 +102,7 @@ var metrics = []prometheus.Collector{
102102
blockIngestionTime,
103103
requestRateLimitedCounters,
104104
transactionsDroppedCounter,
105-
eoaRateLimitedTransactions,
105+
rateLimitedTransactionsCounter,
106106
}
107107

108108
type Collector interface {
@@ -119,28 +119,28 @@ type Collector interface {
119119
BlockIngestionTime(blockCreation time.Time)
120120
RequestRateLimited(method string)
121121
TransactionsDropped(count int)
122-
EOARateLimited(address string)
122+
TransactionRateLimited()
123123
}
124124

125125
var _ Collector = &DefaultCollector{}
126126

127127
type DefaultCollector struct {
128128
// TODO: for now we cannot differentiate which api request failed number of times
129-
apiErrorsCounter prometheus.Counter
130-
serverPanicsCounters *prometheus.CounterVec
131-
cadenceBlockHeight prometheus.Gauge
132-
evmBlockHeight prometheus.Gauge
133-
evmBlockIndexedCounter prometheus.Counter
134-
evmTxIndexedCounter prometheus.Counter
135-
operatorBalance prometheus.Gauge
136-
evmAccountCallCounters *prometheus.CounterVec
137-
requestDurations *prometheus.HistogramVec
138-
availableSigningkeys prometheus.Gauge
139-
gasEstimationIterations prometheus.Gauge
140-
blockIngestionTime prometheus.Histogram
141-
requestRateLimitedCounters *prometheus.CounterVec
142-
transactionsDroppedCounter prometheus.Counter
143-
eoaRateLimitedTransactions *prometheus.CounterVec
129+
apiErrorsCounter prometheus.Counter
130+
serverPanicsCounters *prometheus.CounterVec
131+
cadenceBlockHeight prometheus.Gauge
132+
evmBlockHeight prometheus.Gauge
133+
evmBlockIndexedCounter prometheus.Counter
134+
evmTxIndexedCounter prometheus.Counter
135+
operatorBalance prometheus.Gauge
136+
evmAccountCallCounters *prometheus.CounterVec
137+
requestDurations *prometheus.HistogramVec
138+
availableSigningkeys prometheus.Gauge
139+
gasEstimationIterations prometheus.Gauge
140+
blockIngestionTime prometheus.Histogram
141+
requestRateLimitedCounters *prometheus.CounterVec
142+
transactionsDroppedCounter prometheus.Counter
143+
rateLimitedTransactionsCounter prometheus.Counter
144144
}
145145

146146
func NewCollector(logger zerolog.Logger) Collector {
@@ -150,21 +150,21 @@ func NewCollector(logger zerolog.Logger) Collector {
150150
}
151151

152152
return &DefaultCollector{
153-
apiErrorsCounter: apiErrors,
154-
serverPanicsCounters: serverPanicsCounters,
155-
cadenceBlockHeight: cadenceBlockHeight,
156-
evmBlockHeight: evmBlockHeight,
157-
evmBlockIndexedCounter: evmBlockIndexedCounter,
158-
evmTxIndexedCounter: evmTxIndexedCounter,
159-
evmAccountCallCounters: evmAccountCallCounters,
160-
requestDurations: requestDurations,
161-
operatorBalance: operatorBalance,
162-
availableSigningkeys: availableSigningKeys,
163-
gasEstimationIterations: gasEstimationIterations,
164-
blockIngestionTime: blockIngestionTime,
165-
requestRateLimitedCounters: requestRateLimitedCounters,
166-
transactionsDroppedCounter: transactionsDroppedCounter,
167-
eoaRateLimitedTransactions: eoaRateLimitedTransactions,
153+
apiErrorsCounter: apiErrors,
154+
serverPanicsCounters: serverPanicsCounters,
155+
cadenceBlockHeight: cadenceBlockHeight,
156+
evmBlockHeight: evmBlockHeight,
157+
evmBlockIndexedCounter: evmBlockIndexedCounter,
158+
evmTxIndexedCounter: evmTxIndexedCounter,
159+
evmAccountCallCounters: evmAccountCallCounters,
160+
requestDurations: requestDurations,
161+
operatorBalance: operatorBalance,
162+
availableSigningkeys: availableSigningKeys,
163+
gasEstimationIterations: gasEstimationIterations,
164+
blockIngestionTime: blockIngestionTime,
165+
requestRateLimitedCounters: requestRateLimitedCounters,
166+
transactionsDroppedCounter: transactionsDroppedCounter,
167+
rateLimitedTransactionsCounter: rateLimitedTransactionsCounter,
168168
}
169169
}
170170

@@ -243,10 +243,8 @@ func (c *DefaultCollector) TransactionsDropped(count int) {
243243
c.transactionsDroppedCounter.Add(float64(count))
244244
}
245245

246-
func (c *DefaultCollector) EOARateLimited(address string) {
247-
c.eoaRateLimitedTransactions.
248-
With(prometheus.Labels{"address": address}).
249-
Inc()
246+
func (c *DefaultCollector) TransactionRateLimited() {
247+
c.rateLimitedTransactionsCounter.Inc()
250248
}
251249

252250
func prefixedName(name string) string {

metrics/nop.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +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) {}
28+
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)