Skip to content

Commit 30acb47

Browse files
authored
Merge pull request #5283 from stacks-network/fix/metrics-in-tests
Fix metric breakage
2 parents 3261d0d + 02fa642 commit 30acb47

File tree

2 files changed

+51
-33
lines changed

2 files changed

+51
-33
lines changed

testnet/stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,16 +1488,19 @@ fn simple_neon_integration() {
14881488
// query for prometheus metrics
14891489
#[cfg(feature = "monitoring_prom")]
14901490
{
1491-
let prom_http_origin = format!("http://{}", prom_bind);
1492-
let client = reqwest::blocking::Client::new();
1493-
let res = client
1494-
.get(&prom_http_origin)
1495-
.send()
1496-
.unwrap()
1497-
.text()
1498-
.unwrap();
1499-
let expected_result = format!("stacks_node_stacks_tip_height {block_height_pre_3_0}");
1500-
assert!(res.contains(&expected_result));
1491+
wait_for(10, || {
1492+
let prom_http_origin = format!("http://{}", prom_bind);
1493+
let client = reqwest::blocking::Client::new();
1494+
let res = client
1495+
.get(&prom_http_origin)
1496+
.send()
1497+
.unwrap()
1498+
.text()
1499+
.unwrap();
1500+
let expected_result = format!("stacks_node_stacks_tip_height {block_height_pre_3_0}");
1501+
Ok(res.contains(&expected_result))
1502+
})
1503+
.expect("Prometheus metrics did not update");
15011504
}
15021505

15031506
info!("Nakamoto miner started...");
@@ -1599,19 +1602,30 @@ fn simple_neon_integration() {
15991602
let bhh = u64::from(tip.burn_header_height);
16001603
test_observer::contains_burn_block_range(220..=bhh).unwrap();
16011604

1602-
// make sure prometheus returns an updated height
1605+
// make sure prometheus returns an updated number of processed blocks
16031606
#[cfg(feature = "monitoring_prom")]
16041607
{
1605-
let prom_http_origin = format!("http://{}", prom_bind);
1606-
let client = reqwest::blocking::Client::new();
1607-
let res = client
1608-
.get(&prom_http_origin)
1609-
.send()
1610-
.unwrap()
1611-
.text()
1612-
.unwrap();
1613-
let expected_result = format!("stacks_node_stacks_tip_height {}", tip.stacks_block_height);
1614-
assert!(res.contains(&expected_result));
1608+
wait_for(10, || {
1609+
let prom_http_origin = format!("http://{}", prom_bind);
1610+
let client = reqwest::blocking::Client::new();
1611+
let res = client
1612+
.get(&prom_http_origin)
1613+
.send()
1614+
.unwrap()
1615+
.text()
1616+
.unwrap();
1617+
let expected_result_1 = format!(
1618+
"stacks_node_stx_blocks_processed_total {}",
1619+
tip.stacks_block_height
1620+
);
1621+
1622+
let expected_result_2 = format!(
1623+
"stacks_node_stacks_tip_height {}",
1624+
tip.stacks_block_height - 1
1625+
);
1626+
Ok(res.contains(&expected_result_1) && res.contains(&expected_result_2))
1627+
})
1628+
.expect("Prometheus metrics did not update");
16151629
}
16161630

16171631
check_nakamoto_empty_block_heuristics();

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -558,18 +558,22 @@ fn miner_gather_signatures() {
558558
// Test prometheus metrics response
559559
#[cfg(feature = "monitoring_prom")]
560560
{
561-
let metrics_response = signer_test.get_signer_metrics();
562-
563-
// Because 5 signers are running in the same process, the prometheus metrics
564-
// are incremented once for every signer. This is why we expect the metric to be
565-
// `5`, even though there is only one block proposed.
566-
let expected_result = format!("stacks_signer_block_proposals_received {}", num_signers);
567-
assert!(metrics_response.contains(&expected_result));
568-
let expected_result = format!(
569-
"stacks_signer_block_responses_sent{{response_type=\"accepted\"}} {}",
570-
num_signers
571-
);
572-
assert!(metrics_response.contains(&expected_result));
561+
wait_for(30, || {
562+
let metrics_response = signer_test.get_signer_metrics();
563+
564+
// Because 5 signers are running in the same process, the prometheus metrics
565+
// are incremented once for every signer. This is why we expect the metric to be
566+
// `10`, even though there are only two blocks proposed.
567+
let expected_result_1 =
568+
format!("stacks_signer_block_proposals_received {}", num_signers * 2);
569+
let expected_result_2 = format!(
570+
"stacks_signer_block_responses_sent{{response_type=\"accepted\"}} {}",
571+
num_signers * 2
572+
);
573+
Ok(metrics_response.contains(&expected_result_1)
574+
&& metrics_response.contains(&expected_result_2))
575+
})
576+
.expect("Failed to advance prometheus metrics");
573577
}
574578
}
575579

0 commit comments

Comments
 (0)