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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/apollo_mempool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ assert_matches.workspace = true
blockifier = { workspace = true, features = ["mocks", "testing"] }
blockifier_test_utils.workspace = true
criterion = { workspace = true, features = ["async_tokio"] }
expect-test.workspace = true
itertools.workspace = true
mempool_test_utils.workspace = true
metrics.workspace = true
Expand Down
62 changes: 33 additions & 29 deletions crates/apollo_mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use apollo_mempool_p2p_types::communication::{
use apollo_mempool_types::communication::AddTransactionArgsWrapper;
use apollo_mempool_types::errors::MempoolError;
use apollo_mempool_types::mempool_types::{AccountState, AddTransactionArgs, ValidationArgs};
use apollo_metrics::metrics::HistogramValue;
use apollo_network_types::network_types::BroadcastedMessageMetadata;
use apollo_test_utils::{get_rng, GetTestInstance};
use apollo_time::test_utils::FakeClock;
use expect_test::expect;
use metrics_exporter_prometheus::PrometheusBuilder;
use mockall::predicate::eq;
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -1201,7 +1201,7 @@ fn test_register_metrics() {
register_metrics();

let expected_metrics = MempoolMetrics::default();
expected_metrics.verify_metrics(&recorder);
assert_eq!(MempoolMetrics::from_recorder(&recorder), expected_metrics);
}

#[test]
Expand Down Expand Up @@ -1294,33 +1294,37 @@ fn metrics_correctness() {
fake_clock.advance(Duration::from_secs(20));
commit_block(&mut mempool, [("0x9", 1), ("0x3", 1)], []);

let expected_metrics = MempoolMetrics {
txs_received_invoke: 8,
txs_received_declare: 2,
txs_received_deploy_account: 0,
txs_committed: 3,
txs_dropped_expired: 1,
txs_dropped_rejected: 1,
txs_dropped_evicted: 1,
pool_size: 3,
priority_queue_size: 2,
pending_queue_size: 1,
get_txs_size: 1,
delayed_declares_size: 1,
total_size_in_bytes: 1552,
evictions_count: 1,
transaction_time_spent_until_batched: HistogramValue {
sum: 2.0,
count: 1,
..Default::default()
},
transaction_time_spent_until_committed: HistogramValue {
sum: 42.0,
count: 3,
..Default::default()
},
};
expected_metrics.verify_metrics(&recorder);
let mut metrics = MempoolMetrics::from_recorder(&recorder);
metrics.transaction_time_spent_until_batched.histogram = Default::default();
metrics.transaction_time_spent_until_committed.histogram = Default::default();
expect![[r#"
MempoolMetrics {
txs_received_invoke: 8,
txs_received_declare: 2,
txs_received_deploy_account: 0,
txs_committed: 3,
txs_dropped_expired: 1,
txs_dropped_rejected: 1,
txs_dropped_evicted: 1,
pool_size: 3,
priority_queue_size: 2,
pending_queue_size: 1,
get_txs_size: 1,
delayed_declares_size: 1,
total_size_in_bytes: 1552,
transaction_time_spent_until_batched: HistogramValue {
sum: 2.0,
count: 1,
histogram: {},
},
transaction_time_spent_until_committed: HistogramValue {
sum: 42.0,
count: 3,
histogram: {},
},
}
"#]]
.assert_debug_eq(&metrics);
}

#[rstest]
Expand Down
107 changes: 63 additions & 44 deletions crates/apollo_mempool/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ pub fn get_txs_and_assert_expected(
assert_eq!(txs, expected_txs);
}

#[derive(Default)]
#[derive(Default, Debug, PartialEq)]
pub struct MempoolMetrics {
pub txs_received_invoke: u64,
pub txs_received_declare: u64,
Expand All @@ -309,54 +309,73 @@ pub struct MempoolMetrics {
pub get_txs_size: u64,
pub delayed_declares_size: u64,
pub total_size_in_bytes: u64,
pub evictions_count: u64,
pub transaction_time_spent_until_batched: HistogramValue,
pub transaction_time_spent_until_committed: HistogramValue,
}

impl MempoolMetrics {
pub fn verify_metrics(&self, recorder: &PrometheusRecorder) {
pub fn from_recorder(recorder: &PrometheusRecorder) -> Self {
let metrics = &recorder.handle().render();
MEMPOOL_TRANSACTIONS_RECEIVED.assert_eq(
metrics,
self.txs_received_invoke,
&[(LABEL_NAME_TX_TYPE, RpcTransactionLabelValue::Invoke.into())],
);
MEMPOOL_TRANSACTIONS_RECEIVED.assert_eq(
metrics,
self.txs_received_declare,
&[(LABEL_NAME_TX_TYPE, RpcTransactionLabelValue::Declare.into())],
);
MEMPOOL_TRANSACTIONS_RECEIVED.assert_eq(
metrics,
self.txs_received_deploy_account,
&[(LABEL_NAME_TX_TYPE, RpcTransactionLabelValue::DeployAccount.into())],
);
MEMPOOL_TRANSACTIONS_COMMITTED.assert_eq(metrics, self.txs_committed);
MEMPOOL_TRANSACTIONS_DROPPED.assert_eq(
metrics,
self.txs_dropped_expired,
&[(LABEL_NAME_DROP_REASON, DropReason::Expired.into())],
);
MEMPOOL_TRANSACTIONS_DROPPED.assert_eq(
metrics,
self.txs_dropped_rejected,
&[(LABEL_NAME_DROP_REASON, DropReason::Rejected.into())],
);
MEMPOOL_TRANSACTIONS_DROPPED.assert_eq(
metrics,
self.txs_dropped_evicted,
&[(LABEL_NAME_DROP_REASON, DropReason::Evicted.into())],
);
MEMPOOL_POOL_SIZE.assert_eq(metrics, self.pool_size);
MEMPOOL_PRIORITY_QUEUE_SIZE.assert_eq(metrics, self.priority_queue_size);
MEMPOOL_PENDING_QUEUE_SIZE.assert_eq(metrics, self.pending_queue_size);
MEMPOOL_GET_TXS_SIZE.assert_eq(metrics, self.get_txs_size);
MEMPOOL_DELAYED_DECLARES_SIZE.assert_eq(metrics, self.delayed_declares_size);
MEMPOOL_TOTAL_SIZE_BYTES.assert_eq(metrics, self.total_size_in_bytes);
TRANSACTION_TIME_SPENT_UNTIL_BATCHED
.assert_eq(metrics, &self.transaction_time_spent_until_batched);
TRANSACTION_TIME_SPENT_UNTIL_COMMITTED
.assert_eq(metrics, &self.transaction_time_spent_until_committed);
Self {
txs_received_invoke: MEMPOOL_TRANSACTIONS_RECEIVED
.parse_numeric_metric::<u64>(
metrics,
&[(LABEL_NAME_TX_TYPE, RpcTransactionLabelValue::Invoke.into())],
)
.unwrap(),
txs_received_declare: MEMPOOL_TRANSACTIONS_RECEIVED
.parse_numeric_metric::<u64>(
metrics,
&[(LABEL_NAME_TX_TYPE, RpcTransactionLabelValue::Declare.into())],
)
.unwrap(),
txs_received_deploy_account: MEMPOOL_TRANSACTIONS_RECEIVED
.parse_numeric_metric::<u64>(
metrics,
&[(LABEL_NAME_TX_TYPE, RpcTransactionLabelValue::DeployAccount.into())],
)
.unwrap(),
txs_committed: MEMPOOL_TRANSACTIONS_COMMITTED
.parse_numeric_metric::<u64>(metrics)
.unwrap(),
txs_dropped_expired: MEMPOOL_TRANSACTIONS_DROPPED
.parse_numeric_metric::<u64>(
metrics,
&[(LABEL_NAME_DROP_REASON, DropReason::Expired.into())],
)
.unwrap(),
txs_dropped_rejected: MEMPOOL_TRANSACTIONS_DROPPED
.parse_numeric_metric::<u64>(
metrics,
&[(LABEL_NAME_DROP_REASON, DropReason::Rejected.into())],
)
.unwrap(),
txs_dropped_evicted: MEMPOOL_TRANSACTIONS_DROPPED
.parse_numeric_metric::<u64>(
metrics,
&[(LABEL_NAME_DROP_REASON, DropReason::Evicted.into())],
)
.unwrap(),
pool_size: MEMPOOL_POOL_SIZE.parse_numeric_metric::<u64>(metrics).unwrap(),
priority_queue_size: MEMPOOL_PRIORITY_QUEUE_SIZE
.parse_numeric_metric::<u64>(metrics)
.unwrap(),
pending_queue_size: MEMPOOL_PENDING_QUEUE_SIZE
.parse_numeric_metric::<u64>(metrics)
.unwrap(),
get_txs_size: MEMPOOL_GET_TXS_SIZE.parse_numeric_metric::<u64>(metrics).unwrap(),
delayed_declares_size: MEMPOOL_DELAYED_DECLARES_SIZE
.parse_numeric_metric::<u64>(metrics)
.unwrap(),
total_size_in_bytes: MEMPOOL_TOTAL_SIZE_BYTES
.parse_numeric_metric::<u64>(metrics)
.unwrap(),
transaction_time_spent_until_batched: TRANSACTION_TIME_SPENT_UNTIL_BATCHED
.parse_histogram_metric(metrics)
.unwrap(),
transaction_time_spent_until_committed: TRANSACTION_TIME_SPENT_UNTIL_COMMITTED
.parse_histogram_metric(metrics)
.unwrap(),
}
}
}
2 changes: 1 addition & 1 deletion crates/apollo_metrics/src/metrics/histograms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl MetricHistogram {
}

#[cfg(any(feature = "testing", test))]
pub(crate) fn parse_histogram_metric(&self, metrics_as_string: &str) -> Option<HistogramValue> {
pub fn parse_histogram_metric(&self, metrics_as_string: &str) -> Option<HistogramValue> {
parse_histogram_metric(metrics_as_string, self.get_name(), None)
}

Expand Down
Loading