Skip to content

Commit

Permalink
feat: remove server side bucket configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani-cw committed Jun 11, 2024
1 parent 1231bb8 commit 43afaba
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 135 deletions.
7 changes: 0 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ use crate::eth::Executor;
use crate::eth::TransactionRelayer;
use crate::ext::binary_name;
use crate::ext::parse_duration;
#[cfg(feature = "metrics")]
use crate::infra::metrics::MetricsHistogramKind;
use crate::infra::tracing::info_task_spawn;
use crate::infra::tracing::warn_task_tx_closed;
use crate::infra::tracing::TracingLogFormat;
Expand Down Expand Up @@ -88,11 +86,6 @@ pub struct CommonConfig {
#[arg(long = "metrics-exporter-address", env = "METRICS_EXPORTER_ADDRESS", default_value = "0.0.0.0:9000")]
pub metrics_exporter_address: SocketAddr,

#[cfg(feature = "metrics")]
/// Metrics histograms will be collected using summaries or histograms (buckets)?
#[arg(long = "metrics-histogram-kind", env = "METRICS_HISTOGRAM_KIND", default_value = "summary")]
pub metrics_histogram_kind: MetricsHistogramKind,

// Address where Tokio Console GRPC server will be exposed.
#[arg(long = "tokio-console-address", env = "TRACING_TOKIO_CONSOLE_ADDRESS", default_value = "0.0.0.0:6669")]
pub tokio_console_address: SocketAddr,
Expand Down
2 changes: 1 addition & 1 deletion src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ where

// init metrics
#[cfg(feature = "metrics")]
infra::init_metrics(common.metrics_exporter_address, common.metrics_histogram_kind).expect("failed to init metrics");
infra::init_metrics(common.metrics_exporter_address).expect("failed to init metrics");

// init sentry
let _sentry_guard = common
Expand Down
116 changes: 58 additions & 58 deletions src/infra/metrics/metrics_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,212 +5,212 @@ metrics! {
group: json_rpc,

"Number of JSON-RPC requests active right now."
gauge rpc_requests_active{client, method, function} [],
gauge rpc_requests_active{client, method, function},

"Number of JSON-RPC requests that started."
counter rpc_requests_started{client, method, function} [],
counter rpc_requests_started{client, method, function},

"Number of JSON-RPC requests that finished."
histogram_duration rpc_requests_finished{client, method, function, result, success} [],
histogram_duration rpc_requests_finished{client, method, function, result, success},

"Number of JSON-RPC subscriptions active right now."
gauge rpc_subscriptions_active{subscription} []
gauge rpc_subscriptions_active{subscription}
}

// Storage reads.
metrics! {
group: storage_read,

"Time to execute storage check_conflicts operation."
histogram_duration storage_check_conflicts{success, conflicted} [],
histogram_duration storage_check_conflicts{success, conflicted},

"Time to execute storage read_active_block_number operation."
histogram_duration storage_read_active_block_number{success} [],
histogram_duration storage_read_active_block_number{success},

"Time to execute storage read_mined_block_number operation."
histogram_duration storage_read_mined_block_number{success} [],
histogram_duration storage_read_mined_block_number{success},

"Time to execute storage read_account operation."
histogram_duration storage_read_account{found_at, point_in_time, success} [],
histogram_duration storage_read_account{found_at, point_in_time, success},

"Time to execute storage read_block operation."
histogram_duration storage_read_block{success} [],
histogram_duration storage_read_block{success},

"Time to execute storage read_logs operation."
histogram_duration storage_read_logs{success} [],
histogram_duration storage_read_logs{success},

"Time to execute storage read_slot operation."
histogram_duration storage_read_slot{found_at, point_in_time, success} [],
histogram_duration storage_read_slot{found_at, point_in_time, success},

"Time to execute storage read_slot operation."
histogram_duration storage_read_slots{point_in_time, success} [],
histogram_duration storage_read_slots{point_in_time, success},

"Time to execute storage read_mined_transaction operation."
histogram_duration storage_read_mined_transaction{success} []
histogram_duration storage_read_mined_transaction{success}
}

// Storage writes.
metrics! {
group: storage_write,

"Time to execute storage set_active_block_number operation."
histogram_duration storage_set_active_block_number{success} [],
histogram_duration storage_set_active_block_number{success},

"Time to execute storage set_mined_block_number operation."
histogram_duration storage_set_mined_block_number{success} [],
histogram_duration storage_set_mined_block_number{success},

"Time to execute storage save_accounts operation."
histogram_duration storage_save_accounts{success} [],
histogram_duration storage_save_accounts{success},

"Time to execute storage save_account_changes operation."
histogram_duration storage_save_execution{success} [],
histogram_duration storage_save_execution{success},

"Time to execute storage flush operation."
histogram_duration storage_flush{kind, success} [],
histogram_duration storage_flush{kind, success},

"Time to execute storage set_active_external_block operation."
histogram_duration storage_set_active_external_block{success} [],
histogram_duration storage_set_active_external_block{success},

"Time to execute storage finish_block operation."
histogram_duration storage_finish_block{success} [],
histogram_duration storage_finish_block{success},

"Time to execute storage save_block operation."
histogram_duration storage_save_block{size_by_tx, size_by_gas, success} [],
histogram_duration storage_save_block{size_by_tx, size_by_gas, success},

"Time to execute storage reset operation."
histogram_duration storage_reset{kind, success} []
histogram_duration storage_reset{kind, success}
}

// Importer online metrics.
metrics! {
group: importer_online,

"Time to import one block."
histogram_duration import_online_mined_block{} [],
histogram_duration import_online_mined_block{},

"Number of transactions imported."
counter importer_online_transactions_total{} []
counter importer_online_transactions_total{}
}

// Execution metrics.
metrics! {
group: executor,

"Time to execute and persist an external block with all transactions."
histogram_duration executor_external_block{} [],
histogram_duration executor_external_block{},

"Time to execute and persist temporary changes of a single transaction inside import_offline operation."
histogram_duration executor_external_transaction{function} [],
histogram_duration executor_external_transaction{function},

"Gas spent to execute a single transaction inside import_offline operation."
histogram_counter executor_external_transaction_gas{function} [],
histogram_counter executor_external_transaction_gas{function},

"Number of account reads when importing an external block."
histogram_counter executor_external_block_account_reads{} [0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 150., 200.],
histogram_counter executor_external_block_account_reads{},

"Number of slot reads when importing an external block."
histogram_counter executor_external_block_slot_reads{} [0., 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000., 2000., 3000., 4000., 5000., 6000., 7000., 8000., 9000., 10000.],
histogram_counter executor_external_block_slot_reads{},

"Number of slot reads cached when importing an external block."
histogram_counter executor_external_block_slot_reads_cached{} [0., 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000., 2000., 3000., 4000., 5000., 6000., 7000., 8000., 9000., 10000.],
histogram_counter executor_external_block_slot_reads_cached{},

"Time to execute a transaction received with eth_sendRawTransaction."
histogram_duration executor_transact{success, function} [],
histogram_duration executor_transact{success, function},

"Gas spent execute a transaction received with eth_sendRawTransaction."
histogram_counter executor_transact_gas{success, function} [],
histogram_counter executor_transact_gas{success, function},

"Time to execute a transaction received with eth_call or eth_estimateGas."
histogram_duration executor_call{success, function} [],
histogram_duration executor_call{success, function},

"Gas spent to execute a transaction received with eth_call or eth_estimateGas."
histogram_counter executor_call_gas{function} []
histogram_counter executor_call_gas{function}
}

metrics! {
group: evm,

"Time to execute EVM execution."
histogram_duration evm_execution{point_in_time, success} [],
histogram_duration evm_execution{point_in_time, success},

"Number of accounts read in a single EVM execution."
histogram_counter evm_execution_account_reads{} [0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.],
histogram_counter evm_execution_account_reads{},

"Number of slots read in a single EVM execution."
histogram_counter evm_execution_slot_reads{} [0., 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.],
histogram_counter evm_execution_slot_reads{},

"Number of slots read cached in a single EVM execution."
histogram_counter evm_execution_slot_reads_cached{} [0., 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.]
histogram_counter evm_execution_slot_reads_cached{}
}

metrics! {
group: rocks,

"Number of issued gets to rocksdb."
gauge rocks_db_get{dbname} [],
gauge rocks_db_get{dbname},

"Number of writes issued to rocksdb."
gauge rocks_db_write{dbname} [],
gauge rocks_db_write{dbname},

"Time spent compacting data."
gauge rocks_compaction_time{dbname} [],
gauge rocks_compaction_time{dbname},

"CPU time spent compacting data."
gauge rocks_compaction_cpu_time{dbname} [],
gauge rocks_compaction_cpu_time{dbname},

"Time spent flushing memtable to disk."
gauge rocks_flush_time{dbname} [],
gauge rocks_flush_time{dbname},

"Number of block cache misses."
gauge rocks_block_cache_miss{dbname} [],
gauge rocks_block_cache_miss{dbname},

"Number of block cache hits."
gauge rocks_block_cache_hit{dbname} [],
gauge rocks_block_cache_hit{dbname},

"Number of bytes written."
gauge rocks_bytes_written{dbname} [],
gauge rocks_bytes_written{dbname},

"Number of bytes read."
gauge rocks_bytes_read{dbname} []
gauge rocks_bytes_read{dbname}
}

metrics! {
group: consensus,

"Time to run Consensus::append_block_to_peer."
histogram_duration consensus_append_block_to_peer{} [],
histogram_duration consensus_append_block_to_peer{},

"Time to run Consensus::start_election."
histogram_duration consensus_start_election{} [],
histogram_duration consensus_start_election{},

"Time to run Consensus::forward."
histogram_duration consensus_forward{} [],
histogram_duration consensus_forward{},

"The diff between what is on the follower database and what it received from Append Entries."
gauge append_entries_block_number_diff{} []
gauge append_entries_block_number_diff{}
}

metrics! {
group: external_relayer,

"Time to run ExternalRelayer::relay_next_block."
histogram_duration relay_next_block{} [],
histogram_duration relay_next_block{},

"Time to run ExternalRelayer::compute_tx_dag."
histogram_duration compute_tx_dag{} [],
histogram_duration compute_tx_dag{},

"Time to run ExternalRelayer::relay_and_check_mempool."
histogram_duration relay_and_check_mempool{} [],
histogram_duration relay_and_check_mempool{},

"Time to run ExternalRelayer::take_roots."
histogram_duration take_roots{} [],
histogram_duration take_roots{},

"Time to run ExternalRelayer::relay_dag."
histogram_duration relay_dag{} [],
histogram_duration relay_dag{},

"Number of execution mismatches."
histogram_duration save_mismatch{} [],
histogram_duration save_mismatch{},

"Time to run ExternalRelayerClient::send_to_relayer."
histogram_duration send_to_relayer{} []
histogram_duration send_to_relayer{}
}
28 changes: 2 additions & 26 deletions src/infra/metrics/metrics_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use std::net::SocketAddr;
use std::stringify;

use metrics_exporter_prometheus::Matcher;
use metrics_exporter_prometheus::PrometheusBuilder;

use crate::infra::metrics::metrics_for_consensus;
Expand All @@ -16,21 +15,11 @@ use crate::infra::metrics::metrics_for_json_rpc;
use crate::infra::metrics::metrics_for_rocks;
use crate::infra::metrics::metrics_for_storage_read;
use crate::infra::metrics::metrics_for_storage_write;
use crate::infra::metrics::MetricsHistogramKind;

/// Default bucket for duration based metrics.
const BUCKET_FOR_DURATION: [f64; 37] = [
0.0001, 0.0002, 0.0003, 0.0004, 0.0005, 0.0006, 0.0007, 0.0008, 0.0009, // 0.1ms to 0.9ms
0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, // 1ms to 9ms
0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, // 10ms to 90ms
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, // 100ms to 900ms
1., // 1s or more
];

/// Init application global metrics.
///
/// Default configuration runs metrics exporter on port 9000.
pub fn init_metrics(address: SocketAddr, histogram_kind: MetricsHistogramKind) -> anyhow::Result<()> {
pub fn init_metrics(address: SocketAddr) -> anyhow::Result<()> {
tracing::info!(%address, "creating metrics exporter");

// get metric definitions
Expand All @@ -46,20 +35,7 @@ pub fn init_metrics(address: SocketAddr, histogram_kind: MetricsHistogramKind) -
metrics.extend(metrics_for_external_relayer());

// init exporter
let mut builder = PrometheusBuilder::new().with_http_listener(address);

// init buckets
if histogram_kind == MetricsHistogramKind::Histogram {
builder = builder.set_buckets(&BUCKET_FOR_DURATION).unwrap();
for metric in &metrics {
if metric.has_custom_buckets() {
builder = builder.set_buckets_for_metric(Matcher::Full(metric.name.to_string()), &metric.buckets).unwrap();
}
}
}

// init exporter
if let Err(e) = builder.install() {
if let Err(e) = PrometheusBuilder::new().with_http_listener(address).install() {
tracing::error!(reason = ?e, %address, "failed to create metrics exporter");
}

Expand Down
2 changes: 0 additions & 2 deletions src/infra/metrics/metrics_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ macro_rules! metrics {
$(
$description:literal
$kind:ident $name:ident{ $($label:ident),* }
$buckets:expr
),+
) => {
// Generate function to get metric definition.
Expand All @@ -25,7 +24,6 @@ macro_rules! metrics {
kind: stringify!($kind),
name: stringify!([<stratus_ $name>]),
description: stringify!($description),
buckets: $buckets.to_vec()
},
)+
]
Expand Down
Loading

0 comments on commit 43afaba

Please sign in to comment.