From 5f7bda78c3fef7f324f8cbeaed2d7d41b7169d16 Mon Sep 17 00:00:00 2001 From: Artem Fomiuk <88630083+Artemka374@users.noreply.github.com> Date: Tue, 14 May 2024 18:05:55 +0300 Subject: [PATCH] feat: Remove metrics crate (#1902) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ Remove emitting metrics with metrics crate - emit them with vise instead ## Why ❔ To be consistent with libraries we use ## Checklist - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`. - [x] Spellcheck has been run via `zk spellcheck`. --- Cargo.lock | 8 +- core/bin/contract-verifier/Cargo.toml | 2 +- core/bin/contract-verifier/src/main.rs | 1 + core/bin/contract-verifier/src/metrics.rs | 14 +++ core/bin/contract-verifier/src/verifier.rs | 8 +- core/lib/zksync_core/Cargo.toml | 1 - core/node/house_keeper/Cargo.toml | 1 - .../fri_proof_compressor_job_retry_manager.rs | 6 +- .../src/fri_proof_compressor_queue_monitor.rs | 31 ++--- .../src/fri_prover_job_retry_manager.rs | 6 +- .../src/fri_prover_queue_monitor.rs | 59 +++++----- ...ri_witness_generator_jobs_retry_manager.rs | 11 +- .../fri_witness_generator_queue_monitor.rs | 33 ++---- core/node/house_keeper/src/metrics.rs | 106 +++++++++++++++++- ...waiting_to_queued_fri_witness_job_mover.rs | 31 +++-- core/tests/loadnext/Cargo.toml | 2 +- core/tests/loadnext/src/executor.rs | 8 +- core/tests/loadnext/src/lib.rs | 1 + core/tests/loadnext/src/metrics.rs | 12 ++ .../loadnext/src/report_collector/mod.rs | 7 +- core/tests/vm-benchmark/Cargo.toml | 2 +- .../vm-benchmark/benches/diy_benchmark.rs | 13 ++- .../src/iai_results_to_prometheus.rs | 29 ++++- 23 files changed, 257 insertions(+), 135 deletions(-) create mode 100644 core/bin/contract-verifier/src/metrics.rs create mode 100644 core/tests/loadnext/src/metrics.rs diff --git a/Cargo.lock b/Cargo.lock index 26c714e2cf0..f04e00cf8a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3388,7 +3388,6 @@ dependencies = [ "envy", "futures 0.3.28", "hex", - "metrics", "num", "once_cell", "prometheus_exporter", @@ -3401,6 +3400,7 @@ dependencies = [ "thiserror", "tokio", "tracing", + "vise", "vlog", "zksync_config", "zksync_contracts", @@ -7311,9 +7311,9 @@ version = "0.1.0" dependencies = [ "criterion", "iai", - "metrics", "metrics-exporter-prometheus", "tokio", + "vise", "vm-benchmark-harness", ] @@ -8257,7 +8257,6 @@ dependencies = [ "futures 0.3.28", "hex", "lazy_static", - "metrics", "prometheus_exporter", "regex", "serde", @@ -8267,6 +8266,7 @@ dependencies = [ "thiserror", "tokio", "tracing", + "vise", "vlog", "zksync_config", "zksync_contracts", @@ -8307,7 +8307,6 @@ dependencies = [ "itertools 0.10.5", "jsonrpsee", "lru", - "metrics", "multivm", "once_cell", "pin-project-lite", @@ -8613,7 +8612,6 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", - "metrics", "prover_dal", "tokio", "tracing", diff --git a/core/bin/contract-verifier/Cargo.toml b/core/bin/contract-verifier/Cargo.toml index 49f22a17556..49e5469998c 100644 --- a/core/bin/contract-verifier/Cargo.toml +++ b/core/bin/contract-verifier/Cargo.toml @@ -29,7 +29,7 @@ thiserror.workspace = true chrono.workspace = true serde_json.workspace = true ethabi.workspace = true -metrics.workspace = true +vise.workspace = true hex.workspace = true serde = { workspace = true, features = ["derive"] } structopt.workspace = true diff --git a/core/bin/contract-verifier/src/main.rs b/core/bin/contract-verifier/src/main.rs index 01c0dc568af..0f3364263ed 100644 --- a/core/bin/contract-verifier/src/main.rs +++ b/core/bin/contract-verifier/src/main.rs @@ -16,6 +16,7 @@ use zksync_utils::wait_for_tasks::ManagedTasks; use crate::verifier::ContractVerifier; pub mod error; +mod metrics; pub mod verifier; pub mod zksolc_utils; pub mod zkvyper_utils; diff --git a/core/bin/contract-verifier/src/metrics.rs b/core/bin/contract-verifier/src/metrics.rs new file mode 100644 index 00000000000..fd98f51cd56 --- /dev/null +++ b/core/bin/contract-verifier/src/metrics.rs @@ -0,0 +1,14 @@ +use std::time::Duration; + +use vise::{Buckets, Histogram, Metrics}; + +#[derive(Debug, Metrics)] +#[metrics(prefix = "api_contract_verifier")] +pub(crate) struct ApiContractVerifierMetrics { + #[metrics(buckets = Buckets::LATENCIES)] + pub request_processing_time: Histogram, +} + +#[vise::register] +pub(crate) static API_CONTRACT_VERIFIER_METRICS: vise::Global = + vise::Global::new(); diff --git a/core/bin/contract-verifier/src/verifier.rs b/core/bin/contract-verifier/src/verifier.rs index 055a808b0ec..938ea2fd1ba 100644 --- a/core/bin/contract-verifier/src/verifier.rs +++ b/core/bin/contract-verifier/src/verifier.rs @@ -25,6 +25,7 @@ use zksync_types::{ use crate::{ error::ContractVerifierError, + metrics::API_CONTRACT_VERIFIER_METRICS, zksolc_utils::{Optimizer, Settings, Source, StandardJson, ZkSolc, ZkSolcInput, ZkSolcOutput}, zkvyper_utils::{ZkVyper, ZkVyperInput}, }; @@ -523,10 +524,9 @@ impl JobProcessor for ContractVerifier { let verification_result = Self::verify(&mut connection, job, config).await; Self::process_result(&mut connection, job_id, verification_result).await; - metrics::histogram!( - "api.contract_verifier.request_processing_time", - started_at.elapsed() - ); + API_CONTRACT_VERIFIER_METRICS + .request_processing_time + .observe(started_at.elapsed()); Ok(()) }) } diff --git a/core/lib/zksync_core/Cargo.toml b/core/lib/zksync_core/Cargo.toml index 756d32ab74a..2648e9319dd 100644 --- a/core/lib/zksync_core/Cargo.toml +++ b/core/lib/zksync_core/Cargo.toml @@ -67,7 +67,6 @@ serde = { workspace = true, features = ["derive"] } serde_json.workspace = true serde_yaml.workspace = true itertools.workspace = true -metrics.workspace = true ctrlc.workspace = true rand.workspace = true diff --git a/core/node/house_keeper/Cargo.toml b/core/node/house_keeper/Cargo.toml index 7a2a414116a..62b3605c385 100644 --- a/core/node/house_keeper/Cargo.toml +++ b/core/node/house_keeper/Cargo.toml @@ -21,4 +21,3 @@ async-trait.workspace = true tokio = { workspace = true, features = ["time"] } anyhow.workspace = true tracing.workspace = true -metrics.workspace = true diff --git a/core/node/house_keeper/src/fri_proof_compressor_job_retry_manager.rs b/core/node/house_keeper/src/fri_proof_compressor_job_retry_manager.rs index 2ee0e386a91..7dfb21090f7 100644 --- a/core/node/house_keeper/src/fri_proof_compressor_job_retry_manager.rs +++ b/core/node/house_keeper/src/fri_proof_compressor_job_retry_manager.rs @@ -4,7 +4,7 @@ use async_trait::async_trait; use prover_dal::{Prover, ProverDal}; use zksync_dal::ConnectionPool; -use crate::periodic_job::PeriodicJob; +use crate::{metrics::PROVER_FRI_METRICS, periodic_job::PeriodicJob}; #[derive(Debug)] pub struct FriProofCompressorJobRetryManager { @@ -48,7 +48,9 @@ impl PeriodicJob for FriProofCompressorJobRetryManager { for stuck_job in stuck_jobs { tracing::info!("re-queuing fri proof compressor job {:?}", stuck_job); } - metrics::counter!("prover_fri.proof_compressor.requeued_jobs", job_len as u64); + PROVER_FRI_METRICS + .proof_compressor_requeued_jobs + .inc_by(job_len as u64); Ok(()) } diff --git a/core/node/house_keeper/src/fri_proof_compressor_queue_monitor.rs b/core/node/house_keeper/src/fri_proof_compressor_queue_monitor.rs index e743bbd3189..b9f0bc47704 100644 --- a/core/node/house_keeper/src/fri_proof_compressor_queue_monitor.rs +++ b/core/node/house_keeper/src/fri_proof_compressor_queue_monitor.rs @@ -3,9 +3,10 @@ use prover_dal::{Prover, ProverDal}; use zksync_dal::ConnectionPool; use zksync_types::prover_dal::JobCountStatistics; -use crate::periodic_job::PeriodicJob; - -const PROOF_COMPRESSOR_SERVICE_NAME: &str = "proof_compressor"; +use crate::{ + metrics::{JobStatus, PROVER_FRI_METRICS}, + periodic_job::PeriodicJob, +}; #[derive(Debug)] pub struct FriProofCompressorStatsReporter { @@ -48,17 +49,9 @@ impl PeriodicJob for FriProofCompressorStatsReporter { ); } - metrics::gauge!( - format!("prover_fri.{}.jobs", PROOF_COMPRESSOR_SERVICE_NAME), - stats.queued as f64, - "type" => "queued" - ); - - metrics::gauge!( - format!("prover_fri.{}.jobs", PROOF_COMPRESSOR_SERVICE_NAME), - stats.in_progress as f64, - "type" => "in_progress" - ); + PROVER_FRI_METRICS.proof_compressor_jobs[&JobStatus::Queued].set(stats.queued as u64); + PROVER_FRI_METRICS.proof_compressor_jobs[&JobStatus::InProgress] + .set(stats.in_progress as u64); let oldest_not_compressed_batch = self .pool @@ -70,13 +63,9 @@ impl PeriodicJob for FriProofCompressorStatsReporter { .await; if let Some(l1_batch_number) = oldest_not_compressed_batch { - metrics::gauge!( - format!( - "prover_fri.{}.oldest_not_compressed_batch", - PROOF_COMPRESSOR_SERVICE_NAME - ), - l1_batch_number.0 as f64 - ); + PROVER_FRI_METRICS + .proof_compressor_oldest_uncompressed_batch + .set(l1_batch_number.0 as u64); } Ok(()) diff --git a/core/node/house_keeper/src/fri_prover_job_retry_manager.rs b/core/node/house_keeper/src/fri_prover_job_retry_manager.rs index 939b9cb8eaa..042af2f45e0 100644 --- a/core/node/house_keeper/src/fri_prover_job_retry_manager.rs +++ b/core/node/house_keeper/src/fri_prover_job_retry_manager.rs @@ -4,7 +4,7 @@ use async_trait::async_trait; use prover_dal::{Prover, ProverDal}; use zksync_dal::ConnectionPool; -use crate::periodic_job::PeriodicJob; +use crate::{metrics::SERVER_METRICS, periodic_job::PeriodicJob}; #[derive(Debug)] pub struct FriProverJobRetryManager { @@ -48,7 +48,9 @@ impl PeriodicJob for FriProverJobRetryManager { for stuck_job in stuck_jobs { tracing::info!("re-queuing fri prover job {:?}", stuck_job); } - metrics::counter!("server.prover_fri.requeued_jobs", job_len as u64); + SERVER_METRICS + .prover_fri_requeued_jobs + .inc_by(job_len as u64); Ok(()) } diff --git a/core/node/house_keeper/src/fri_prover_queue_monitor.rs b/core/node/house_keeper/src/fri_prover_queue_monitor.rs index d577f5668d9..8b76d88d2ba 100644 --- a/core/node/house_keeper/src/fri_prover_queue_monitor.rs +++ b/core/node/house_keeper/src/fri_prover_queue_monitor.rs @@ -3,7 +3,7 @@ use prover_dal::{Prover, ProverDal}; use zksync_config::configs::fri_prover_group::FriProverGroupConfig; use zksync_dal::{ConnectionPool, Core, CoreDal}; -use crate::periodic_job::PeriodicJob; +use crate::{metrics::FRI_PROVER_METRICS, periodic_job::PeriodicJob}; #[derive(Debug)] pub struct FriProverStatsReporter { @@ -57,22 +57,19 @@ impl PeriodicJob for FriProverStatsReporter { .get_group_id_for_circuit_id_and_aggregation_round(circuit_id, aggregation_round) .unwrap_or(u8::MAX); - metrics::gauge!( - "fri_prover.prover.jobs", - stats.queued as f64, - "type" => "queued", - "circuit_id" => circuit_id.to_string(), - "aggregation_round" => aggregation_round.to_string(), - "prover_group_id" => group_id.to_string(), + FRI_PROVER_METRICS.report_prover_jobs( + "queued", + circuit_id, + aggregation_round, + group_id, + stats.queued as u64, ); - - metrics::gauge!( - "fri_prover.prover.jobs", - stats.in_progress as f64, - "type" => "in_progress", - "circuit_id" => circuit_id.to_string(), - "aggregation_round" => aggregation_round.to_string(), - "prover_group_id" => group_id.to_string(), + FRI_PROVER_METRICS.report_prover_jobs( + "in_progress", + circuit_id, + aggregation_round, + group_id, + stats.in_progress as u64, ); } @@ -82,10 +79,9 @@ impl PeriodicJob for FriProverStatsReporter { .await; for ((circuit_id, aggregation_round), l1_batch_number) in lag_by_circuit_type { - metrics::gauge!( - "fri_prover.block_number", l1_batch_number.0 as f64, - "circuit_id" => circuit_id.to_string(), - "aggregation_round" => aggregation_round.to_string()); + FRI_PROVER_METRICS.block_number + [&(circuit_id.to_string(), aggregation_round.to_string())] + .set(l1_batch_number.0 as u64); } // FIXME: refactor metrics here @@ -97,7 +93,7 @@ impl PeriodicJob for FriProverStatsReporter { .get_oldest_unpicked_batch() .await { - Some(l1_batch_number) => l1_batch_number.0 as f64, + Some(l1_batch_number) => l1_batch_number.0 as u64, // if there is no unpicked batch in database, we use sealed batch number as a result None => { db_conn @@ -106,20 +102,21 @@ impl PeriodicJob for FriProverStatsReporter { .await .unwrap() .unwrap() - .0 as f64 + .0 as u64 } }; - metrics::gauge!("fri_prover.oldest_unpicked_batch", oldest_unpicked_batch); + FRI_PROVER_METRICS + .oldest_unpicked_batch + .set(oldest_unpicked_batch); if let Some(l1_batch_number) = db_conn .proof_generation_dal() .get_oldest_not_generated_batch() .await { - metrics::gauge!( - "fri_prover.oldest_not_generated_batch", - l1_batch_number.0 as f64 - ) + FRI_PROVER_METRICS + .oldest_not_generated_batch + .set(l1_batch_number.0 as u64); } for aggregation_round in 0..3 { @@ -128,11 +125,9 @@ impl PeriodicJob for FriProverStatsReporter { .min_unproved_l1_batch_number_for_aggregation_round(aggregation_round.into()) .await { - metrics::gauge!( - "fri_prover.oldest_unprocessed_block_by_round", - l1_batch_number.0 as f64, - "aggregation_round" => aggregation_round.to_string() - ) + FRI_PROVER_METRICS.oldest_unprocessed_block_by_round + [&aggregation_round.to_string()] + .set(l1_batch_number.0 as u64); } } diff --git a/core/node/house_keeper/src/fri_witness_generator_jobs_retry_manager.rs b/core/node/house_keeper/src/fri_witness_generator_jobs_retry_manager.rs index 26a86a778c4..8c24b0980ec 100644 --- a/core/node/house_keeper/src/fri_witness_generator_jobs_retry_manager.rs +++ b/core/node/house_keeper/src/fri_witness_generator_jobs_retry_manager.rs @@ -4,7 +4,10 @@ use zksync_config::configs::fri_witness_generator::WitnessGenerationTimeouts; use zksync_dal::ConnectionPool; use zksync_types::prover_dal::StuckJobs; -use crate::periodic_job::PeriodicJob; +use crate::{ + metrics::{WitnessType, SERVER_METRICS}, + periodic_job::PeriodicJob, +}; #[derive(Debug)] pub struct FriWitnessGeneratorJobRetryManager { @@ -33,10 +36,8 @@ impl FriWitnessGeneratorJobRetryManager { for stuck_job in stuck_jobs { tracing::info!("re-queuing {:?} {:?}", witness_type, stuck_job); } - metrics::counter!( - format!("server.{:?}.requeued_jobs", witness_type), - stuck_jobs.len() as u64 - ); + SERVER_METRICS.requeued_jobs[&WitnessType::from(witness_type)] + .inc_by(stuck_jobs.len() as u64); } pub async fn requeue_stuck_witness_inputs_jobs(&mut self) { diff --git a/core/node/house_keeper/src/fri_witness_generator_queue_monitor.rs b/core/node/house_keeper/src/fri_witness_generator_queue_monitor.rs index 38a28d5a7c2..f8beb88e20e 100644 --- a/core/node/house_keeper/src/fri_witness_generator_queue_monitor.rs +++ b/core/node/house_keeper/src/fri_witness_generator_queue_monitor.rs @@ -5,9 +5,7 @@ use prover_dal::{Prover, ProverDal}; use zksync_dal::ConnectionPool; use zksync_types::{basic_fri_types::AggregationRound, prover_dal::JobCountStatistics}; -use crate::periodic_job::PeriodicJob; - -const FRI_WITNESS_GENERATOR_SERVICE_NAME: &str = "fri_witness_generator"; +use crate::{metrics::SERVER_METRICS, periodic_job::PeriodicJob}; #[derive(Debug)] pub struct FriWitnessGeneratorStatsReporter { @@ -70,19 +68,10 @@ fn emit_metrics_for_round(round: AggregationRound, stats: JobCountStatistics) { ); } - metrics::gauge!( - format!("server.{}.jobs", FRI_WITNESS_GENERATOR_SERVICE_NAME), - stats.queued as f64, - "type" => "queued", - "round" => format!("{:?}", round) - ); - - metrics::gauge!( - format!("server.{}.jobs", FRI_WITNESS_GENERATOR_SERVICE_NAME), - stats.in_progress as f64, - "type" => "in_progress", - "round" => format!("{:?}", round) - ); + SERVER_METRICS.witness_generator_jobs_by_round[&("queued", format!("{:?}", round))] + .set(stats.queued as u64); + SERVER_METRICS.witness_generator_jobs_by_round[&("in_progress", format!("{:?}", round))] + .set(stats.queued as u64); } /// Invoked periodically to push job statistics to Prometheus @@ -107,17 +96,9 @@ impl PeriodicJob for FriWitnessGeneratorStatsReporter { ); } - metrics::gauge!( - format!("server.{}.jobs", FRI_WITNESS_GENERATOR_SERVICE_NAME), - aggregated.queued as f64, - "type" => "queued" - ); + SERVER_METRICS.witness_generator_jobs[&("queued")].set(aggregated.queued as u64); + SERVER_METRICS.witness_generator_jobs[&("in_progress")].set(aggregated.in_progress as u64); - metrics::gauge!( - format!("server.{}.jobs", FRI_WITNESS_GENERATOR_SERVICE_NAME), - aggregated.in_progress as f64, - "type" => "in_progress" - ); Ok(()) } diff --git a/core/node/house_keeper/src/metrics.rs b/core/node/house_keeper/src/metrics.rs index 69615c634cf..b47031a0f10 100644 --- a/core/node/house_keeper/src/metrics.rs +++ b/core/node/house_keeper/src/metrics.rs @@ -1,4 +1,4 @@ -use vise::{Counter, Metrics}; +use vise::{Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, LabeledFamily, Metrics}; #[derive(Debug, Metrics)] #[metrics(prefix = "house_keeper")] @@ -9,3 +9,107 @@ pub(crate) struct HouseKeeperMetrics { #[vise::register] pub(crate) static HOUSE_KEEPER_METRICS: vise::Global = vise::Global::new(); + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] +#[metrics(label = "type", rename_all = "snake_case")] +#[allow(dead_code)] +pub enum JobStatus { + Queued, + InProgress, + Successful, + Failed, + SentToServer, + Skipped, +} + +#[derive(Debug, Metrics)] +#[metrics(prefix = "prover_fri")] +pub(crate) struct ProverFriMetrics { + pub proof_compressor_requeued_jobs: Counter, + pub proof_compressor_jobs: Family>, + pub proof_compressor_oldest_uncompressed_batch: Gauge, +} + +#[vise::register] +pub(crate) static PROVER_FRI_METRICS: vise::Global = vise::Global::new(); + +const PROVER_JOBS_LABELS: [&str; 4] = + ["type", "circuit_id", "aggregation_round", "prover_group_id"]; +type ProverJobsLabels = (&'static str, String, String, String); + +#[derive(Debug, Metrics)] +#[metrics(prefix = "fri_prover")] +pub(crate) struct FriProverMetrics { + #[metrics(labels = PROVER_JOBS_LABELS)] + pub prover_jobs: LabeledFamily, 4>, + #[metrics(labels = ["circuit_id", "aggregation_round"])] + pub block_number: LabeledFamily<(String, String), Gauge, 2>, + pub oldest_unpicked_batch: Gauge, + pub oldest_not_generated_batch: Gauge, + #[metrics(labels = ["round"])] + pub oldest_unprocessed_block_by_round: LabeledFamily>, +} + +impl FriProverMetrics { + pub fn report_prover_jobs( + &self, + status: &'static str, + circuit_id: u8, + aggregation_round: u8, + prover_group_id: u8, + amount: u64, + ) { + self.prover_jobs[&( + status, + circuit_id.to_string(), + aggregation_round.to_string(), + prover_group_id.to_string(), + )] + .set(amount); + } +} + +#[vise::register] +pub(crate) static FRI_PROVER_METRICS: vise::Global = vise::Global::new(); + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)] +#[metrics(label = "type", rename_all = "snake_case")] +#[allow(clippy::enum_variant_names)] +pub(crate) enum WitnessType { + WitnessInputsFri, + LeafAggregationJobsFri, + NodeAggregationJobsFri, + RecursionTipJobsFri, + SchedulerJobsFri, +} + +impl From<&str> for WitnessType { + fn from(s: &str) -> Self { + match s { + "witness_inputs_fri" => Self::WitnessInputsFri, + "leaf_aggregations_jobs_fri" => Self::LeafAggregationJobsFri, + "node_aggregations_jobs_fri" => Self::NodeAggregationJobsFri, + "recursion_tip_jobs_fri" => Self::RecursionTipJobsFri, + "scheduler_jobs_fri" => Self::SchedulerJobsFri, + _ => panic!("Invalid witness type"), + } + } +} + +#[derive(Debug, Metrics)] +#[metrics(prefix = "server")] +pub(crate) struct ServerMetrics { + pub prover_fri_requeued_jobs: Counter, + pub requeued_jobs: Family>, + #[metrics(labels = ["type", "round"])] + pub witness_generator_jobs_by_round: LabeledFamily<(&'static str, String), Gauge, 2>, + #[metrics(labels = ["type"])] + pub witness_generator_jobs: LabeledFamily<&'static str, Gauge>, + pub leaf_fri_witness_generator_waiting_to_queued_jobs_transitions: Counter, + pub node_fri_witness_generator_waiting_to_queued_jobs_transitions: Counter, + pub recursion_tip_witness_generator_waiting_to_queued_jobs_transitions: Counter, + pub scheduler_witness_generator_waiting_to_queued_jobs_transitions: Counter, +} + +#[vise::register] +pub(crate) static SERVER_METRICS: vise::Global = vise::Global::new(); diff --git a/core/node/house_keeper/src/waiting_to_queued_fri_witness_job_mover.rs b/core/node/house_keeper/src/waiting_to_queued_fri_witness_job_mover.rs index 76d016b8618..0d4030d9408 100644 --- a/core/node/house_keeper/src/waiting_to_queued_fri_witness_job_mover.rs +++ b/core/node/house_keeper/src/waiting_to_queued_fri_witness_job_mover.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use prover_dal::{Prover, ProverDal}; use zksync_dal::ConnectionPool; -use crate::periodic_job::PeriodicJob; +use crate::{metrics::SERVER_METRICS, periodic_job::PeriodicJob}; #[derive(Debug)] pub struct WaitingToQueuedFriWitnessJobMover { @@ -32,10 +32,10 @@ impl WaitingToQueuedFriWitnessJobMover { circuit_id ); } - metrics::counter!( - "server.node_fri_witness_generator.waiting_to_queued_jobs_transitions", - len as u64 - ); + + SERVER_METRICS + .node_fri_witness_generator_waiting_to_queued_jobs_transitions + .inc_by(len as u64); } async fn move_node_aggregation_jobs_from_waiting_to_queued(&mut self) -> Vec<(i64, u8, u16)> { @@ -65,10 +65,9 @@ impl WaitingToQueuedFriWitnessJobMover { depth ); } - metrics::counter!( - "server.leaf_fri_witness_generator.waiting_to_queued_jobs_transitions", - len as u64 - ); + SERVER_METRICS + .leaf_fri_witness_generator_waiting_to_queued_jobs_transitions + .inc_by(len as u64); } /// Marks recursion tip witness jobs as queued. @@ -85,10 +84,9 @@ impl WaitingToQueuedFriWitnessJobMover { l1_batch_number, ); } - metrics::counter!( - "server.recursion_tip_witness_generator.waiting_to_queued_jobs_transitions", - l1_batch_numbers.len() as u64 - ); + SERVER_METRICS + .recursion_tip_witness_generator_waiting_to_queued_jobs_transitions + .inc_by(l1_batch_numbers.len() as u64); } /// Marks scheduler witness jobs as queued. @@ -105,10 +103,9 @@ impl WaitingToQueuedFriWitnessJobMover { l1_batch_number, ); } - metrics::counter!( - "server.scheduler_witness_generator.waiting_to_queued_jobs_transitions", - l1_batch_numbers.len() as u64 - ); + SERVER_METRICS + .scheduler_witness_generator_waiting_to_queued_jobs_transitions + .inc_by(l1_batch_numbers.len() as u64); } } diff --git a/core/tests/loadnext/Cargo.toml b/core/tests/loadnext/Cargo.toml index 804a4b9e1cd..b829ec244e4 100644 --- a/core/tests/loadnext/Cargo.toml +++ b/core/tests/loadnext/Cargo.toml @@ -37,5 +37,5 @@ once_cell.workspace = true thiserror.workspace = true reqwest = { workspace = true, features = ["blocking", "json"] } regex.workspace = true -metrics.workspace = true +vise.workspace = true tracing.workspace = true diff --git a/core/tests/loadnext/src/executor.rs b/core/tests/loadnext/src/executor.rs index fe262acc138..ff8b97fe23b 100644 --- a/core/tests/loadnext/src/executor.rs +++ b/core/tests/loadnext/src/executor.rs @@ -15,6 +15,7 @@ use crate::{ account_pool::AccountPool, config::{ExecutionConfig, LoadtestConfig, RequestLimiters}, constants::*, + metrics::LOADTEST_METRICS, report::ReportBuilder, report_collector::{LoadtestResult, ReportCollector}, sdk::{ @@ -114,10 +115,9 @@ impl Executor { self.pool.master_wallet.address(), format_eth(eth_balance) ); - metrics::gauge!( - "loadtest.master_account_balance", - eth_balance.as_u128() as f64 - ); + LOADTEST_METRICS + .master_account_balance + .set(eth_balance.as_u128() as u64); Ok(()) } diff --git a/core/tests/loadnext/src/lib.rs b/core/tests/loadnext/src/lib.rs index eeb59c9f2fe..c1d2719a4c6 100644 --- a/core/tests/loadnext/src/lib.rs +++ b/core/tests/loadnext/src/lib.rs @@ -9,6 +9,7 @@ pub mod constants; pub mod corrupted_tx; pub mod executor; pub mod fs_utils; +pub(crate) mod metrics; pub mod report; pub mod report_collector; pub mod rng; diff --git a/core/tests/loadnext/src/metrics.rs b/core/tests/loadnext/src/metrics.rs new file mode 100644 index 00000000000..bebc1f0f4a3 --- /dev/null +++ b/core/tests/loadnext/src/metrics.rs @@ -0,0 +1,12 @@ +use vise::{Gauge, LabeledFamily, Metrics}; + +#[derive(Debug, Metrics)] +#[metrics(prefix = "loadtest")] +pub(crate) struct LoadtestMetrics { + #[metrics(labels = ["label"])] + pub tps: LabeledFamily>, + pub master_account_balance: Gauge, +} + +#[vise::register] +pub(crate) static LOADTEST_METRICS: vise::Global = vise::Global::new(); diff --git a/core/tests/loadnext/src/report_collector/mod.rs b/core/tests/loadnext/src/report_collector/mod.rs index 6a7a5de39ba..d891ad1c715 100644 --- a/core/tests/loadnext/src/report_collector/mod.rs +++ b/core/tests/loadnext/src/report_collector/mod.rs @@ -4,6 +4,7 @@ use futures::{channel::mpsc::Receiver, StreamExt}; use operation_results_collector::OperationResultsCollector; use crate::{ + metrics::LOADTEST_METRICS, report::{ActionType, Report, ReportLabel}, report_collector::metrics_collector::MetricsCollector, }; @@ -40,11 +41,7 @@ impl Collectors { let actual_duration = self.start.elapsed(); self.metrics.report(); if !self.is_aborted { - metrics::gauge!( - "loadtest.tps", - self.operation_results.nominal_tps(), - "label" => prometheus_label, - ); + LOADTEST_METRICS.tps[&prometheus_label].set(self.operation_results.nominal_tps()); } self.operation_results.report(actual_duration); } diff --git a/core/tests/vm-benchmark/Cargo.toml b/core/tests/vm-benchmark/Cargo.toml index 98bef08124b..5b96d776730 100644 --- a/core/tests/vm-benchmark/Cargo.toml +++ b/core/tests/vm-benchmark/Cargo.toml @@ -7,7 +7,7 @@ license.workspace = true [dependencies] vm-benchmark-harness.workspace = true metrics-exporter-prometheus.workspace = true -metrics.workspace = true +vise.workspace = true tokio.workspace = true [dev-dependencies] diff --git a/core/tests/vm-benchmark/benches/diy_benchmark.rs b/core/tests/vm-benchmark/benches/diy_benchmark.rs index b99837d8eab..c1c627cbcb4 100644 --- a/core/tests/vm-benchmark/benches/diy_benchmark.rs +++ b/core/tests/vm-benchmark/benches/diy_benchmark.rs @@ -1,6 +1,7 @@ use std::time::{Duration, Instant}; use criterion::black_box; +use vise::{Gauge, LabeledFamily, Metrics}; use vm_benchmark_harness::{cut_to_allowed_bytecode_size, get_deploy_tx, BenchmarkingVm}; fn main() { @@ -34,9 +35,19 @@ fn main() { vm_benchmark::with_prometheus::with_prometheus(|| { for (name, timings) in results { for (i, timing) in timings.into_iter().enumerate() { - metrics::gauge!("vm_benchmark.timing", timing, "benchmark" => name.clone(), "run_no" => i.to_string()); + VM_BENCHMARK_METRICS.timing[&(name.clone(), i.to_string())].set(timing); } } }); } } + +#[derive(Debug, Metrics)] +#[metrics(prefix = "vm_benchmark")] +pub(crate) struct VmBenchmarkMetrics { + #[metrics(labels = ["benchmark", "run_no"])] + pub timing: LabeledFamily<(String, String), Gauge, 2>, +} + +#[vise::register] +pub(crate) static VM_BENCHMARK_METRICS: vise::Global = vise::Global::new(); diff --git a/core/tests/vm-benchmark/src/iai_results_to_prometheus.rs b/core/tests/vm-benchmark/src/iai_results_to_prometheus.rs index 396d59948a8..d419603bae8 100644 --- a/core/tests/vm-benchmark/src/iai_results_to_prometheus.rs +++ b/core/tests/vm-benchmark/src/iai_results_to_prometheus.rs @@ -1,5 +1,6 @@ use std::io::BufReader; +use vise::{Gauge, LabeledFamily, Metrics}; use vm_benchmark::parse_iai::IaiResult; fn main() { @@ -8,11 +9,29 @@ fn main() { vm_benchmark::with_prometheus::with_prometheus(|| { for r in results { - metrics::gauge!("vm_cachegrind.instructions", r.instructions as f64, "benchmark" => r.name.clone()); - metrics::gauge!("vm_cachegrind.l1_accesses", r.l1_accesses as f64, "benchmark" => r.name.clone()); - metrics::gauge!("vm_cachegrind.l2_accesses", r.l2_accesses as f64, "benchmark" => r.name.clone()); - metrics::gauge!("vm_cachegrind.ram_accesses", r.ram_accesses as f64, "benchmark" => r.name.clone()); - metrics::gauge!("vm_cachegrind.cycles", r.cycles as f64, "benchmark" => r.name); + VM_CACHEGRIND_METRICS.instructions[&r.name.clone()].set(r.instructions as f64); + VM_CACHEGRIND_METRICS.l1_accesses[&r.name.clone()].set(r.l1_accesses as f64); + VM_CACHEGRIND_METRICS.l2_accesses[&r.name.clone()].set(r.l2_accesses as f64); + VM_CACHEGRIND_METRICS.ram_accesses[&r.name.clone()].set(r.ram_accesses as f64); + VM_CACHEGRIND_METRICS.cycles[&r.name.clone()].set(r.cycles as f64); } }) } + +#[derive(Debug, Metrics)] +#[metrics(prefix = "vm_cachegrind")] +pub(crate) struct VmCachegrindMetrics { + #[metrics(labels = ["benchmark"])] + pub instructions: LabeledFamily>, + #[metrics(labels = ["benchmark"])] + pub l1_accesses: LabeledFamily>, + #[metrics(labels = ["benchmark"])] + pub l2_accesses: LabeledFamily>, + #[metrics(labels = ["benchmark"])] + pub ram_accesses: LabeledFamily>, + #[metrics(labels = ["benchmark"])] + pub cycles: LabeledFamily>, +} + +#[vise::register] +pub(crate) static VM_CACHEGRIND_METRICS: vise::Global = vise::Global::new();