Skip to content

Commit 7ee1793

Browse files
apollo_integration_tests: make metric recorder init global in flow tests
1 parent f3b7a50 commit 7ee1793

File tree

1 file changed

+13
-12
lines changed
  • crates/apollo_integration_tests/tests/common

1 file changed

+13
-12
lines changed

crates/apollo_integration_tests/tests/common/mod.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use apollo_integration_tests::utils::{
2020
CreateRpcTxsFn,
2121
TestTxHashesFn,
2222
};
23-
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusRecorder};
23+
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle};
2424
use pretty_assertions::assert_eq;
2525
use starknet_api::execution_resources::GasAmount;
2626
use starknet_api::transaction::TransactionHash;
@@ -39,8 +39,9 @@ pub async fn end_to_end_flow(
3939
configure_tracing().await;
4040

4141
let mut tx_generator = create_flow_test_tx_generator();
42-
let recorder = PrometheusBuilder::new().build_recorder();
43-
let _recorder_guard = metrics::set_default_local_recorder(&recorder);
42+
let global_recorder_handle = PrometheusBuilder::new()
43+
.install_recorder()
44+
.expect("Should be able to install global prometheus recorder");
4445

4546
const TEST_SCENARIO_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(50);
4647
// Setup.
@@ -107,7 +108,7 @@ pub async fn end_to_end_flow(
107108
{current_batched_txs_count}"
108109
);
109110

110-
current_batched_txs_count = get_total_batched_txs_count(&recorder);
111+
current_batched_txs_count = get_total_batched_txs_count(&global_recorder_handle);
111112
if current_batched_txs_count == total_expected_batched_txs_count {
112113
break;
113114
}
@@ -125,8 +126,8 @@ pub async fn end_to_end_flow(
125126
});
126127
}
127128

128-
assert_full_blocks_flow(&recorder, expecting_full_blocks);
129-
assert_no_reverted_transactions_flow(&recorder);
129+
assert_full_blocks_flow(&global_recorder_handle, expecting_full_blocks);
130+
assert_no_reverted_transactions_flow(&global_recorder_handle);
130131
}
131132

132133
pub struct TestScenario {
@@ -135,13 +136,13 @@ pub struct TestScenario {
135136
pub test_tx_hashes_fn: TestTxHashesFn,
136137
}
137138

138-
fn get_total_batched_txs_count(recorder: &PrometheusRecorder) -> usize {
139-
let metrics = recorder.handle().render();
139+
fn get_total_batched_txs_count(handle: &PrometheusHandle) -> usize {
140+
let metrics = handle.render();
140141
apollo_batcher::metrics::BATCHED_TRANSACTIONS.parse_numeric_metric::<usize>(&metrics).unwrap()
141142
}
142143

143-
fn assert_full_blocks_flow(recorder: &PrometheusRecorder, expecting_full_blocks: bool) {
144-
let metrics = recorder.handle().render();
144+
fn assert_full_blocks_flow(recorder_handle: &PrometheusHandle, expecting_full_blocks: bool) {
145+
let metrics = recorder_handle.render();
145146
let full_blocks_metric = apollo_batcher::metrics::BLOCK_CLOSE_REASON
146147
.parse_numeric_metric::<u64>(
147148
&metrics,
@@ -158,8 +159,8 @@ fn assert_full_blocks_flow(recorder: &PrometheusRecorder, expecting_full_blocks:
158159
}
159160
}
160161

161-
fn assert_no_reverted_transactions_flow(recorder: &PrometheusRecorder) {
162-
let metrics = recorder.handle().render();
162+
fn assert_no_reverted_transactions_flow(recorder_handle: &PrometheusHandle) {
163+
let metrics = recorder_handle.render();
163164
let reverted_transactions_metric =
164165
REVERTED_TRANSACTIONS.parse_numeric_metric::<u64>(&metrics).unwrap();
165166
assert_eq!(reverted_transactions_metric, 0);

0 commit comments

Comments
 (0)