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

feat: Prometheus Block Fullness Metrics #3025

Merged
merged 14 commits into from
Feb 1, 2022
7 changes: 7 additions & 0 deletions src/chainstate/stacks/db/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ use crate::types::chainstate::{
StacksAddress, StacksBlockHeader, StacksBlockId, StacksMicroblockHeader,
};
use crate::{types, util};
use monitoring::set_last_execution_cost_observed;
use types::chainstate::BurnchainHeaderHash;

#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -5002,6 +5003,10 @@ impl StacksChainState {
None,
)?;

let block_limit = clarity_tx
.block_limit()
.unwrap_or(ExecutionCost::max_value());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if setting block_limit to ExecutionCost::max_value() in the case of an error makes sense...

Could we at least add a warn if there is an error here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... what would it mean if block_limit() failed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would mean that a transaction was currently being evaluated. I don't think it's possible in this code path, but it'd be good to warn --

Suggested change
.unwrap_or(ExecutionCost::max_value());
.unwrap_or_else(|| {
warn!("Failed to read transaction block limit");
ExecutionCost::max_value()
});


let (
scheduled_miner_reward,
block_execution_cost,
Expand Down Expand Up @@ -5240,6 +5245,8 @@ impl StacksChainState {

chainstate_tx.log_transactions_processed(&new_tip.index_block_hash(), &tx_receipts);

set_last_execution_cost_observed(&block_execution_cost, &block_limit);

let epoch_receipt = StacksEpochReceipt {
header: new_tip,
tx_receipts,
Expand Down
25 changes: 25 additions & 0 deletions src/monitoring/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ use crate::{
},
};
use burnchains::BurnchainSigner;
use std::convert::TryInto;
use std::error::Error;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Mutex;
use util::db::sqlite_open;
use util::db::Error as DatabaseError;
use util::uint::{Uint256, Uint512};
use vm::costs::ExecutionCost;

#[cfg(feature = "monitoring_prom")]
mod prometheus;
Expand Down Expand Up @@ -104,6 +106,28 @@ pub fn increment_btc_blocks_received_counter() {
prometheus::BTC_BLOCKS_RECEIVED_COUNTER.inc();
}

/// Log `execution_cost` as a ratio of `block_limit`.
#[allow(unused_variables)]
pub fn set_last_execution_cost_observed(
execution_cost: &ExecutionCost,
block_limit: &ExecutionCost,
) {
#[cfg(feature = "monitoring_prom")]
Copy link
Member

@jcnelson jcnelson Feb 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to just group all of these statements inside a single #[cfg(feature = "monitoring_prom")]? Something like:

#[cfg(feature = "monitoring_prom")] {
   /* do stuff here */
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did this

prometheus::LAST_BLOCK_READ_COUNT
.set(execution_cost.read_count as f64 / block_limit.read_count as f64);
#[cfg(feature = "monitoring_prom")]
prometheus::LAST_BLOCK_WRITE_COUNT
.set(execution_cost.write_count as f64 / block_limit.read_count as f64);
#[cfg(feature = "monitoring_prom")]
prometheus::LAST_BLOCK_READ_LENGTH
.set(execution_cost.read_length as f64 / block_limit.read_length as f64);
#[cfg(feature = "monitoring_prom")]
prometheus::LAST_BLOCK_WRITE_LENGTH
.set(execution_cost.write_length as f64 / block_limit.write_length as f64);
#[cfg(feature = "monitoring_prom")]
prometheus::LAST_BLOCK_RUNTIME.set(execution_cost.runtime as f64 / block_limit.runtime as f64);
}

pub fn increment_btc_ops_sent_counter() {
#[cfg(feature = "monitoring_prom")]
prometheus::BTC_OPS_SENT_COUNTER.inc();
Expand Down Expand Up @@ -397,6 +421,7 @@ pub fn set_burnchain_signer(signer: BurnchainSigner) -> Result<(), SetGlobalBurn
Ok(())
}

#[allow(unreachable_code)]
pub fn get_burnchain_signer() -> Option<BurnchainSigner> {
#[cfg(feature = "monitoring_prom")]
{
Expand Down
25 changes: 25 additions & 0 deletions src/monitoring/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,31 @@ lazy_static! {
"Total number of error logs emitted by node"
)).unwrap();

pub static ref LAST_BLOCK_READ_COUNT: Gauge = register_gauge!(opts!(
"stacks_node_last_block_read_count",
"`execution_cost_read_count` for the last block observed."
)).unwrap();

pub static ref LAST_BLOCK_WRITE_COUNT: Gauge = register_gauge!(opts!(
"stacks_node_last_block_write_count",
"`execution_cost_write_count` for the last block observed."
)).unwrap();

pub static ref LAST_BLOCK_READ_LENGTH: Gauge = register_gauge!(opts!(
"stacks_node_last_block_read_length",
"`execution_cost_read_length` for the last block observed."
)).unwrap();

pub static ref LAST_BLOCK_WRITE_LENGTH: Gauge = register_gauge!(opts!(
"stacks_node_last_block_write_length",
"`execution_cost_write_length` for the last block observed."
)).unwrap();

pub static ref LAST_BLOCK_RUNTIME: Gauge = register_gauge!(opts!(
"stacks_node_last_block_runtime",
"`execution_cost_runtime` for the last block observed."
)).unwrap();

pub static ref ACTIVE_MINERS_COUNT_GAUGE: IntGauge = register_int_gauge!(opts!(
"stacks_node_active_miners_total",
"Total number of active miners"
Expand Down