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

Added metrics for tree_availability crate #24

Closed
wants to merge 10 commits into from
Closed
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
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion bin/tree_availability_service.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;

use clap::Parser;
use common::metrics::{self, init_statsd_exporter};
use common::tracing::init_subscriber;
use ethers::providers::{Http, Provider};
use ethers::types::H160;
Expand Down Expand Up @@ -57,8 +58,8 @@ pub async fn main() -> eyre::Result<()> {
let opts = Opts::parse();

if opts.datadog {
todo!("Initialize datadog tracing backend");
// init_datadog_subscriber("tree-availability-service", Level::INFO);
init_statsd_exporter();
} else {
init_subscriber(Level::INFO);
}
Expand Down
1 change: 1 addition & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ tracing-subscriber = {version = "0.3.17", features = ["env-filter"]}
tokio = "1.33.0"
http = "0.2.9"
opentelemetry-http = "0.9.0"
metrics-exporter-statsd = "0.6.0"
1 change: 1 addition & 0 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod metrics;
pub mod test_utilities;
pub mod tracing;
12 changes: 12 additions & 0 deletions crates/common/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use metrics_exporter_statsd::StatsdBuilder;

pub fn init_statsd_exporter() {
//TODO: update these to be args
let recorder = StatsdBuilder::from("127.0.0.1", 8125)
.with_queue_size(5000)
.with_buffer_size(1024)
.build(Some("prefix"))
.expect("Could not create StatsdRecorder");

metrics::set_boxed_recorder(Box::new(recorder)).expect("TODO:");
}
5 changes: 5 additions & 0 deletions crates/tree_availability/src/world_tree/block_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ where
) -> Result<Vec<Log>, M::Error> {
let latest_block = self.middleware.get_block_number().await?.as_u64();

metrics::gauge!(
"tree_availability.block_scanner.latest_block",
latest_block as f64
);

let last_synced_block = self.last_synced_block.load(Ordering::SeqCst);

if last_synced_block >= latest_block {
Expand Down
15 changes: 14 additions & 1 deletion crates/tree_availability/src/world_tree/tree_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ impl<M: Middleware> TreeUpdater<M> {
.map(|u256: U256| Hash::from_limbs(u256.0))
.collect();

metrics::increment_counter!(
"tree_availability.tree_updater.insertion"
);

tree_data
.insert_many_at(start_index as usize, &identities)
.await;
Expand All @@ -160,6 +164,11 @@ impl<M: Middleware> TreeUpdater<M> {
.into_iter().take_while(|x| *x != 2_u32.pow(tree_data.depth as u32))
.map(|x| x as usize)
.collect();

metrics::increment_counter!(
"tree_availability.tree_updater.deletion"
);

tree_data.delete_many(&indices).await;

} else if function_selector == DeleteIdentitiesWithDeletionProofAndBatchSizeAndPackedDeletionIndicesAndPreRootCall::selector() {
Expand All @@ -169,11 +178,15 @@ impl<M: Middleware> TreeUpdater<M> {
// @dev This is a type that is generated by abigen!() since there is a function defined with a conflicting function name but different params
let delete_identities_call =
DeleteIdentitiesWithDeletionProofAndBatchSizeAndPackedDeletionIndicesAndPreRootCall::decode(calldata.as_ref())?;

let indices= unpack_indices(
delete_identities_call.packed_deletion_indices.as_ref(),
);

metrics::increment_counter!(
"tree_availability.tree_updater.deletion"
);

let indices: Vec<usize> = indices
.into_iter().take_while(|x| *x != 2_u32.pow(tree_data.depth as u32))
.map(|x| x as usize)
Expand Down