Skip to content

Commit

Permalink
[State Sync] Add metrics around chunk sizes.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLind authored and areshand committed Dec 17, 2022
1 parent 3214bfe commit f63e51e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
25 changes: 23 additions & 2 deletions state-sync/state-sync-v2/state-sync-driver/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<IntCounterVec> = Lazy::new(|| {
register_int_counter_vec!(
Expand Down Expand Up @@ -96,6 +102,16 @@ pub static EXECUTING_COMPONENT: Lazy<IntCounterVec> = Lazy::new(|| {
.unwrap()
});

/// Counter for tracking sizes of data chunks sent to the storage synchronizer
pub static STORAGE_SYNCHRONIZER_CHUNK_SIZES: Lazy<HistogramVec> = 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<IntCounterVec> = Lazy::new(|| {
register_int_counter_vec!(
Expand Down Expand Up @@ -151,6 +167,11 @@ pub fn decrement_gauge(gauge: &Lazy<IntGaugeVec>, 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<HistogramVec>, 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<IntGaugeVec>, label: &str) -> i64 {
gauge.with_label_values(&[label]).get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,18 @@ fn spawn_executor<ChunkExecutor: ChunkExecutorTrait + 'static>(
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,
);
}
Expand Down Expand Up @@ -451,10 +459,18 @@ fn spawn_executor<ChunkExecutor: ChunkExecutorTrait + 'static>(
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,
);
}
Expand Down

0 comments on commit f63e51e

Please sign in to comment.