Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add stats to onchain events ingestion #205

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/connectors/onchain_events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{
ValidatorMessage,
},
storage::store::engine::MempoolMessage,
utils::statsd_wrapper::StatsdClientWrapper,
};

sol!(
Expand Down Expand Up @@ -144,13 +145,15 @@ pub struct Subscriber {
mempool_tx: mpsc::Sender<MempoolMessage>,
start_block_number: u64,
stop_block_number: u64,
statsd_client: StatsdClientWrapper,
}

// TODO(aditi): Wait for 1 confirmation before "committing" an onchain event.
impl Subscriber {
pub fn new(
config: Config,
mempool_tx: mpsc::Sender<MempoolMessage>,
statsd_client: StatsdClientWrapper,
) -> Result<Subscriber, SubscribeError> {
if config.rpc_url.is_empty() {
return Err(SubscribeError::EmptyRpcUrl);
Expand All @@ -163,9 +166,15 @@ impl Subscriber {
mempool_tx,
start_block_number: config.start_block_number,
stop_block_number: config.stop_block_number,
statsd_client,
})
}

fn count(&self, key: &str, value: u64) {
self.statsd_client
.count(format!("onchain_events.{}", key).as_str(), value);
}

async fn add_onchain_event(
&mut self,
fid: u64,
Expand Down Expand Up @@ -200,6 +209,21 @@ impl Subscriber {
log_index = event.log_index,
"Processed onchain event"
);
match event_type {
OnChainEventType::EventTypeNone => {}
OnChainEventType::EventTypeSigner => {
self.count("num_signer_events", 1);
}
OnChainEventType::EventTypeSignerMigrated => {
self.count("num_signer_migrated_events", 1);
}
OnChainEventType::EventTypeIdRegister => {
self.count("num_id_register_events", 1);
}
OnChainEventType::EventTypeStorageRent => {
self.count("num_storage_events", 1);
}
};
let events = self.onchain_events_by_block.get_mut(&block_number);
match events {
None => {
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
let mut onchain_events_subscriber = snapchain::connectors::onchain_events::Subscriber::new(
app_config.onchain_events,
mempool_tx.clone(),
statsd_client.clone(),
)?;
tokio::spawn(async move {
let result = onchain_events_subscriber.run(false).await;
Expand Down