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 1 commit
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
10 changes: 10 additions & 0 deletions crates/tree_availability/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use semaphore::Field;
use serde::de::Error;
use serde::{Deserialize, Deserializer, Serialize};
use serde_json::Value;
use tokio::time::Instant;

use crate::error::TreeError;
use crate::world_tree::{Hash, WorldTree};
Expand Down Expand Up @@ -81,12 +82,21 @@ pub async fn inclusion_proof<M: Middleware>(
State(world_tree): State<Arc<WorldTree<M>>>,
Json(req): Json<InclusionProofRequest>,
) -> Result<(StatusCode, Json<Option<InclusionProof>>), TreeError> {
metrics::increment_counter!("tree_availability.server.inclusion_proof");
0xKitsune marked this conversation as resolved.
Show resolved Hide resolved

if world_tree.tree_updater.synced.load(Ordering::Relaxed) {
let inclusion_proof_start_time = Instant::now();

let inclusion_proof = world_tree
.tree_data
.get_inclusion_proof(req.identity_commitment, req.root)
.await;

metrics::histogram!(
0xKitsune marked this conversation as resolved.
Show resolved Hide resolved
"tree_availability.server.inclusion_proof_duration_ms",
inclusion_proof_start_time.elapsed().as_millis() as f64
);

Ok((StatusCode::OK, inclusion_proof.into()))
} else {
Err(TreeError::TreeNotSynced)
Expand Down
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 @@ -34,6 +34,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 current_block = self.current_block.load(Ordering::SeqCst);

if current_block >= latest_block {
Expand Down
8 changes: 8 additions & 0 deletions crates/tree_availability/src/world_tree/tree_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,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 @@ -126,6 +130,10 @@ impl<M: Middleware> TreeUpdater<M> {
let indices: Vec<_> =
indices.into_iter().map(|x| x as usize).collect();

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

tree_data.delete_many(&indices).await;
} else {
return Err(TreeAvailabilityError::UnrecognizedFunctionSelector);
Expand Down