diff --git a/state-sync/state-sync-v2/state-sync-driver/src/metrics.rs b/state-sync/state-sync-v2/state-sync-driver/src/metrics.rs index 0a5601e5e7c78..2fb7cc6705af9 100644 --- a/state-sync/state-sync-v2/state-sync-driver/src/metrics.rs +++ b/state-sync/state-sync-v2/state-sync-driver/src/metrics.rs @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 use aptos_metrics_core::{ - register_histogram_vec, register_int_counter_vec, register_int_gauge_vec, HistogramTimer, - HistogramVec, IntCounterVec, IntGaugeVec, + histogram_opts, register_histogram_vec, register_int_counter_vec, register_int_gauge_vec, + HistogramTimer, HistogramVec, IntCounterVec, IntGaugeVec, }; use once_cell::sync::Lazy; @@ -56,6 +56,12 @@ impl StorageSynchronizerOperations { } } +/// Histogram buckets for tracking chunk sizes +const CHUNK_SIZE_BUCKETS: &[f64] = &[ + 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0, 1024.0, 2048.0, 4096.0, 8192.0, + 16384.0, +]; + /// Counter for state sync bootstrapper errors pub static BOOTSTRAPPER_ERRORS: Lazy = Lazy::new(|| { register_int_counter_vec!( @@ -96,6 +102,16 @@ pub static EXECUTING_COMPONENT: Lazy = Lazy::new(|| { .unwrap() }); +/// Counter for tracking sizes of data chunks sent to the storage synchronizer +pub static STORAGE_SYNCHRONIZER_CHUNK_SIZES: Lazy = Lazy::new(|| { + let histogram_opts = histogram_opts!( + "aptos_state_sync_storage_synchronizer_chunk_sizes", + "Counter for tracking sizes of data chunks sent to the storage synchronizer", + CHUNK_SIZE_BUCKETS.to_vec() + ); + register_histogram_vec!(histogram_opts, &["label"]).unwrap() +}); + /// Counter for storage synchronizer errors pub static STORAGE_SYNCHRONIZER_ERRORS: Lazy = Lazy::new(|| { register_int_counter_vec!( @@ -151,6 +167,11 @@ pub fn decrement_gauge(gauge: &Lazy, label: &str, delta: u64) { gauge.with_label_values(&[label]).sub(delta as i64); } +/// Adds a new observation for the given histogram, label and value +pub fn observe_value(histogram: &Lazy, label: &str, value: u64) { + histogram.with_label_values(&[label]).observe(value as f64); +} + /// Reads the gauge with the specific label pub fn read_gauge(gauge: &Lazy, label: &str) -> i64 { gauge.with_label_values(&[label]).get() diff --git a/state-sync/state-sync-v2/state-sync-driver/src/storage_synchronizer.rs b/state-sync/state-sync-v2/state-sync-driver/src/storage_synchronizer.rs index fcd9659911447..14bec1a3320d5 100644 --- a/state-sync/state-sync-v2/state-sync-driver/src/storage_synchronizer.rs +++ b/state-sync/state-sync-v2/state-sync-driver/src/storage_synchronizer.rs @@ -411,10 +411,18 @@ fn spawn_executor( num_transactions )) ); + + let operation_label = + metrics::StorageSynchronizerOperations::ExecutedTransactions + .get_label(); metrics::increment_gauge( &metrics::STORAGE_SYNCHRONIZER_OPERATIONS, - metrics::StorageSynchronizerOperations::ExecutedTransactions - .get_label(), + operation_label, + num_transactions as u64, + ); + metrics::observe_value( + &metrics::STORAGE_SYNCHRONIZER_CHUNK_SIZES, + operation_label, num_transactions as u64, ); } @@ -451,10 +459,18 @@ fn spawn_executor( num_outputs )) ); + + let operation_label = + metrics::StorageSynchronizerOperations::AppliedTransactionOutputs + .get_label(); metrics::increment_gauge( &metrics::STORAGE_SYNCHRONIZER_OPERATIONS, - metrics::StorageSynchronizerOperations::AppliedTransactionOutputs - .get_label(), + operation_label, + num_outputs as u64, + ); + metrics::observe_value( + &metrics::STORAGE_SYNCHRONIZER_CHUNK_SIZES, + operation_label, num_outputs as u64, ); }