Skip to content
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions crates/apollo_committer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ starknet_patricia_storage = { workspace = true, features = ["rocksdb_storage"] }
tracing.workspace = true

[dev-dependencies]
apollo_metrics = { workspace = true, features = ["testing"] }
assert_matches.workspace = true
indexmap.workspace = true
metrics.workspace = true
metrics-exporter-prometheus.workspace = true
starknet_committer = { workspace = true, features = ["testing"] }
starknet_patricia = { workspace = true, features = ["testing"] }
tokio.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions crates/apollo_committer/src/committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ use crate::metrics::{
AVERAGE_READ_RATE,
AVERAGE_WRITE_RATE,
BLOCKS_COMMITTED,
COMMITTER_BLOCK_COMMIT_LATENCY,
COMMITTER_OFFSET,
COMPUTE_DURATION_PER_BLOCK,
COUNT_CLASSES_TRIE_MODIFICATIONS_PER_BLOCK,
Expand Down Expand Up @@ -680,6 +681,7 @@ fn update_metrics(
) {
BLOCKS_COMMITTED.increment(1);
TOTAL_BLOCK_DURATION.increment((durations.block * 1000.0) as u64);
COMMITTER_BLOCK_COMMIT_LATENCY.record(durations.block);
let n_modifications = modifications_counts.total();
// Microseconds.
let total_block_duration_per_modification = if n_modifications > 0 {
Expand Down
18 changes: 18 additions & 0 deletions crates/apollo_committer/src/committer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use apollo_committer_types::committer_types::{
use apollo_committer_types::errors::CommitterError;
use assert_matches::assert_matches;
use indexmap::indexmap;
use metrics_exporter_prometheus::PrometheusBuilder;
use starknet_api::block::BlockNumber;
use starknet_api::block_hash::state_diff_hash::calculate_state_diff_hash;
use starknet_api::core::{ClassHash, CompiledClassHash, StateDiffCommitment};
Expand All @@ -21,6 +22,7 @@ use tracing_test::traced_test;

use super::Committer;
use crate::committer::StorageConstructor;
use crate::metrics::{register_metrics, COMMITTER_BLOCK_COMMIT_LATENCY};

#[cfg(feature = "os_input")]
#[path = "request_paths_and_commit_block_tests.rs"]
Expand Down Expand Up @@ -339,3 +341,19 @@ async fn no_warn_when_block_commit_within_duration_threshold() {
committer.commit_block(commit_block_request(1, Some(1), 0)).await.unwrap();
assert!(!logs_contain("block commit duration above the"));
}

#[tokio::test]
async fn block_commit_latency_histogram_records_commit_duration() {
let recorder = PrometheusBuilder::new().build_recorder();
let _recorder_guard = metrics::set_default_local_recorder(&recorder);
register_metrics(BlockNumber(0));

let mut committer = new_test_committer().await;
committer.commit_block(commit_block_request(1, Some(1), 0)).await.unwrap();

let recorded_metrics = recorder.handle().render();
let histogram_value =
COMMITTER_BLOCK_COMMIT_LATENCY.parse_histogram_metric(&recorded_metrics).unwrap();
assert_eq!(histogram_value.count, 1);
assert!(histogram_value.sum > 0.0);
}
7 changes: 7 additions & 0 deletions crates/apollo_committer/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ define_metrics!(
"Compute written entries per second average over a block (cumulative)",
init = 0
},
MetricHistogram {
COMMITTER_BLOCK_COMMIT_LATENCY,
"committer_block_commit_latency",
"Latency of committing a single block, in seconds (recorded for both commits and \
reverts)"
},
},
);

Expand All @@ -115,4 +121,5 @@ pub fn register_metrics(offset: BlockNumber) {
AVERAGE_WRITE_RATE.register();
COMPUTE_DURATION_PER_BLOCK.register();
AVERAGE_COMPUTE_RATE.register();
COMMITTER_BLOCK_COMMIT_LATENCY.register();
}
Loading