Skip to content

Commit 28d6226

Browse files
committed
fix(kms-connector): error metric handling
1 parent 114d711 commit 28d6226

File tree

1 file changed

+17
-6
lines changed
  • kms-connector/crates/gw-listener/src/core

1 file changed

+17
-6
lines changed

kms-connector/crates/gw-listener/src/core/gateway.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
core::{Config, publish::update_last_block_polled, publish_event},
3-
monitoring::metrics::EVENT_RECEIVED_COUNTER,
3+
monitoring::metrics::{EVENT_RECEIVED_COUNTER, EVENT_RECEIVED_ERRORS},
44
};
55
use alloy::{
66
network::Ethereum,
@@ -105,7 +105,7 @@ where
105105
info!("GatewayListener stopped successfully!");
106106
}
107107

108-
/// Polls a contract group for events using `eth_getLogs`.
108+
/// Polls a contract for events using `eth_getLogs`.
109109
///
110110
/// Cancels all other tasks on failure.
111111
async fn poll_events(self, contract: MonitoredContract) {
@@ -208,15 +208,21 @@ where
208208
}
209209

210210
/// Decodes a log and dispatches it to the appropriate event handler.
211-
async fn process_log(&self, group: MonitoredContract, log: Log) {
212-
let event: GatewayEventKind = match group {
211+
async fn process_log(&self, contract: MonitoredContract, log: Log) {
212+
let contract_label = contract.to_string().to_lowercase();
213+
let event: GatewayEventKind = match contract {
213214
MonitoredContract::Decryption => match DecryptionEvents::decode_log(&log.inner) {
214215
Ok(event) => match event.data {
215216
DecryptionEvents::PublicDecryptionRequest(e) => e.into(),
216217
DecryptionEvents::UserDecryptionRequest(e) => e.into(),
217218
_ => return trace!("Ignoring Decryption event: {log:?}"),
218219
},
219-
Err(e) => return warn!("Failed to decode Decryption event: {e}"),
220+
Err(e) => {
221+
EVENT_RECEIVED_ERRORS
222+
.with_label_values(&[&contract_label])
223+
.inc();
224+
return warn!("Failed to decode Decryption event: {e}");
225+
}
220226
},
221227
MonitoredContract::KmsGeneration => match KMSGenerationEvents::decode_log(&log.inner) {
222228
Ok(event) => match event.data {
@@ -227,7 +233,12 @@ where
227233
KMSGenerationEvents::KeyReshareSameSet(e) => e.into(),
228234
_ => return trace!("Ignoring KMSGeneration event: {log:?}"),
229235
},
230-
Err(e) => return warn!("Failed to decode KMSGeneration event: {e}"),
236+
Err(e) => {
237+
EVENT_RECEIVED_ERRORS
238+
.with_label_values(&[&contract_label])
239+
.inc();
240+
return warn!("Failed to decode KMSGeneration event: {e}");
241+
}
231242
},
232243
};
233244

0 commit comments

Comments
 (0)