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

chore: log if metrics_endpoint but no feature flag #5279

Merged
merged 10 commits into from
Nov 14, 2024
5 changes: 1 addition & 4 deletions stacks-signer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SpawnedSigner
);
let (res_send, res_recv) = channel();
let ev = SignerEventReceiver::new(config.network.is_mainnet());
#[cfg(feature = "monitoring_prom")]
{
crate::monitoring::start_serving_monitoring_metrics(config.clone()).ok();
}
crate::monitoring::start_serving_monitoring_metrics(config.clone()).ok();
let runloop = RunLoop::new(config.clone());
let mut signer: RunLoopSigner<S, T> = libsigner::Signer::new(runloop, ev, res_send);
let running_signer = signer.spawn(endpoint).expect("Failed to spawn signer");
Expand Down
6 changes: 3 additions & 3 deletions stacks-signer/src/monitoring/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use ::prometheus::HistogramTimer;
#[cfg(feature = "monitoring_prom")]
use slog::slog_error;
#[cfg(not(feature = "monitoring_prom"))]
use slog::slog_warn;
use slog::slog_info;
#[cfg(feature = "monitoring_prom")]
use stacks_common::error;
#[cfg(not(feature = "monitoring_prom"))]
use stacks_common::warn;
use stacks_common::info;

use crate::config::GlobalConfig;

Expand Down Expand Up @@ -144,7 +144,7 @@ pub fn start_serving_monitoring_metrics(config: GlobalConfig) -> Result<(), Stri
#[cfg(not(feature = "monitoring_prom"))]
{
if config.metrics_endpoint.is_some() {
warn!("Not starting monitoring metrics server as the monitoring_prom feature is not enabled");
info!("`metrics_endpoint` is configured for the signer, but the monitoring_prom feature is not enabled. Not starting monitoring metrics server.");
}
}
Ok(())
Expand Down
70 changes: 19 additions & 51 deletions testnet/stacks-node/src/tests/nakamoto_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,13 +1490,15 @@ fn simple_neon_integration() {
{
let prom_http_origin = format!("http://{}", prom_bind);
let client = reqwest::blocking::Client::new();
let info = get_chain_info_result(&naka_conf).unwrap();
let stacks_tip_height = info.stacks_tip_height;
let res = client
.get(&prom_http_origin)
.send()
.unwrap()
.text()
.unwrap();
let expected_result = format!("stacks_node_stacks_tip_height {block_height_pre_3_0}");
let expected_result = format!("stacks_node_stacks_tip_height {stacks_tip_height}");
assert!(res.contains(&expected_result));
}

Expand Down Expand Up @@ -1604,14 +1606,22 @@ fn simple_neon_integration() {
{
let prom_http_origin = format!("http://{}", prom_bind);
let client = reqwest::blocking::Client::new();
let res = client
.get(&prom_http_origin)
.send()
.unwrap()
.text()
.unwrap();
let expected_result = format!("stacks_node_stacks_tip_height {}", tip.stacks_block_height);
assert!(res.contains(&expected_result));
let info = get_chain_info_result(&naka_conf).unwrap();
let stacks_tip_height = info.stacks_tip_height;
wait_for(10, || {
let res = client
.get(&prom_http_origin)
.send()
.unwrap()
.text()
.unwrap();
let expected_result = format!(
"stacks_node_stacks_tip_height {}",
stacks_tip_height - 1_u64
obycode marked this conversation as resolved.
Show resolved Hide resolved
);
Ok(res.contains(&expected_result))
})
.expect("Timed out waiting for updated stacks tip height in prometheus metrics");
}

check_nakamoto_empty_block_heuristics();
Expand Down Expand Up @@ -5979,33 +5989,6 @@ fn signer_chainstate() {
let burnchain = naka_conf.get_burnchain();
let sortdb = burnchain.open_sortition_db(true).unwrap();

// query for prometheus metrics
#[cfg(feature = "monitoring_prom")]
{
let (chainstate, _) = StacksChainState::open(
naka_conf.is_mainnet(),
naka_conf.burnchain.chain_id,
&naka_conf.get_chainstate_path_str(),
None,
)
.unwrap();
let block_height_pre_3_0 =
NakamotoChainState::get_canonical_block_header(chainstate.db(), &sortdb)
.unwrap()
.unwrap()
.stacks_block_height;
let prom_http_origin = format!("http://{}", prom_bind);
let client = reqwest::blocking::Client::new();
let res = client
.get(&prom_http_origin)
.send()
.unwrap()
.text()
.unwrap();
let expected_result = format!("stacks_node_stacks_tip_height {block_height_pre_3_0}");
assert!(res.contains(&expected_result));
}

info!("Nakamoto miner started...");
blind_signer(&naka_conf, &signers, proposals_submitted.clone());

Expand Down Expand Up @@ -6601,21 +6584,6 @@ fn continue_tenure_extend() {
.unwrap()
.stacks_block_height;

// query for prometheus metrics
#[cfg(feature = "monitoring_prom")]
{
let prom_http_origin = format!("http://{}", prom_bind);
let client = reqwest::blocking::Client::new();
let res = client
.get(&prom_http_origin)
.send()
.unwrap()
.text()
.unwrap();
let expected_result = format!("stacks_node_stacks_tip_height {block_height_pre_3_0}");
assert!(res.contains(&expected_result));
}

info!("Nakamoto miner started...");
blind_signer(&naka_conf, &signers, proposals_submitted);

Expand Down
13 changes: 10 additions & 3 deletions testnet/stacks-node/src/tests/signer/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,16 +558,23 @@ fn miner_gather_signatures() {
// Test prometheus metrics response
#[cfg(feature = "monitoring_prom")]
{
let naka_blocks_confirmed = signer_test
.running_nodes
.nakamoto_blocks_mined
.load(Ordering::SeqCst);
info!("Nakamoto blocks confirmed: {}", naka_blocks_confirmed);
let metrics_response = signer_test.get_signer_metrics();

let expected_blocks = (naka_blocks_confirmed as usize) * num_signers;

// Because 5 signers are running in the same process, the prometheus metrics
// are incremented once for every signer. This is why we expect the metric to be
// `5`, even though there is only one block proposed.
let expected_result = format!("stacks_signer_block_proposals_received {}", num_signers);
// `5` * `naka_blocks_confirmed`.
let expected_result = format!("stacks_signer_block_proposals_received {}", expected_blocks);
assert!(metrics_response.contains(&expected_result));
let expected_result = format!(
"stacks_signer_block_responses_sent{{response_type=\"accepted\"}} {}",
num_signers
expected_blocks
);
assert!(metrics_response.contains(&expected_result));
}
Expand Down