Skip to content

Commit 94ba554

Browse files
authored
Fix minor issues with CCTPv2 Observer (#1448)
- Remove a metrics tag that has unbounded cardinality - Don't keep calculating deposit hashes if ctx is cancelled
1 parent dd62855 commit 94ba554

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

execute/tokendata/cctp/v2/http_client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func (m *MockMetricsReporter) TrackAttestationAPILatency(
5757
m.Called(sourceChain, sourceDomain, success, httpStatus, latency)
5858
}
5959

60-
func (m *MockMetricsReporter) TrackObserveLatency(numRequests int, latency time.Duration) {
61-
m.Called(numRequests, latency)
60+
func (m *MockMetricsReporter) TrackObserveLatency(latency time.Duration) {
61+
m.Called(latency)
6262
}
6363

6464
func (m *MockMetricsReporter) TrackDepositHashCalculationError(

execute/tokendata/cctp/v2/metrics.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var (
4141
Help: "Latency of CCTP v2 Observe() calls",
4242
Buckets: prometheus.DefBuckets,
4343
},
44-
[]string{"destChainFamily", "destChainID", "numRequests"},
44+
[]string{"destChainFamily", "destChainID"},
4545
)
4646

4747
PromCCTPv2DepositHashCalculationErrorCounter = promauto.NewCounterVec(
@@ -73,7 +73,7 @@ var (
7373
type MetricsReporter interface {
7474
TrackAttestationAPILatency(
7575
sourceChain cciptypes.ChainSelector, sourceDomain uint32, success bool, httpStatus string, latency time.Duration)
76-
TrackObserveLatency(numRequests int, latency time.Duration)
76+
TrackObserveLatency(latency time.Duration)
7777
TrackDepositHashCalculationError(sourceChain cciptypes.ChainSelector, sourceDomain uint32)
7878
TrackMessageToTokenDataError(sourceChain cciptypes.ChainSelector, sourceDomain uint32)
7979
TrackAssignTokenDataFailure(sourceChain cciptypes.ChainSelector, sourceDomain uint32)
@@ -92,7 +92,7 @@ type noOpMetricsReporter struct{}
9292
func (n *noOpMetricsReporter) TrackAttestationAPILatency(cciptypes.ChainSelector, uint32, bool, string, time.Duration) {
9393
}
9494

95-
func (n *noOpMetricsReporter) TrackObserveLatency(int, time.Duration) {
95+
func (n *noOpMetricsReporter) TrackObserveLatency(time.Duration) {
9696
}
9797

9898
func (n *noOpMetricsReporter) TrackDepositHashCalculationError(cciptypes.ChainSelector, uint32) {
@@ -136,9 +136,9 @@ func (r *MetricsReporterImpl) TrackAttestationAPILatency(
136136
}
137137

138138
// TrackObserveLatency tracks the overall latency of Observe() calls
139-
func (r *MetricsReporterImpl) TrackObserveLatency(numRequests int, latency time.Duration) {
139+
func (r *MetricsReporterImpl) TrackObserveLatency(latency time.Duration) {
140140
PromCCTPv2ObserveLatencyHistogram.
141-
WithLabelValues(r.destChainFamily, r.destChainID, strconv.Itoa(numRequests)).
141+
WithLabelValues(r.destChainFamily, r.destChainID).
142142
Observe(latency.Seconds())
143143
}
144144

execute/tokendata/cctp/v2/observer.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (o *CCTPv2TokenDataObserver) Observe(
115115
startTime := time.Now()
116116
defer func() {
117117
latency := time.Since(startTime)
118-
o.metricsReporter.TrackObserveLatency(cctpV2RequestParams.Cardinality(), latency)
118+
o.metricsReporter.TrackObserveLatency(latency)
119119
}()
120120

121121
// Extract the CCTPv2 API requests that need to be made
@@ -265,6 +265,11 @@ func (o *CCTPv2TokenDataObserver) convertCCTPv2MessagesToTokenData(
265265

266266
// Process each individual CCTP v2 message in the batch
267267
for _, msg := range messages.Messages {
268+
// Return immediately if context is cancelled to avoid heavy processing done by
269+
// calculateDepositHashFn
270+
if ctx.Err() != nil {
271+
return result
272+
}
268273
// Calculate the deposit hash for this message
269274
depositHash, err := o.calculateDepositHashFn(msg.DecodedMessage)
270275
if err != nil {

0 commit comments

Comments
 (0)