Skip to main content

commonware_storage/qmdb/sync/
metrics.rs

1use commonware_runtime::telemetry::metrics::{Gauge, GaugeExt, MetricsExt};
2
3/// Progress gauges updated by a sync flow.
4///
5/// Progress is expressed as the synced size against the size
6/// of the current sync target. The gauges match once the flow has synced the
7/// latest target.
8pub struct Metrics {
9    /// Size of the current sync target.
10    target_size: Gauge,
11    /// Database size reached by sync.
12    size: Gauge,
13}
14
15impl Metrics {
16    /// Register sync progress metrics on the provided context.
17    pub fn new(context: &impl commonware_runtime::Metrics) -> Self {
18        Self {
19            target_size: context.gauge("target_size", "Size of the current sync target"),
20            size: context.gauge(
21                "size",
22                "Database size reached by sync, equal to target_size when sync completes",
23            ),
24        }
25    }
26
27    /// Record the size of the current sync target.
28    pub fn record_target(&self, size: u64) {
29        let _ = self.target_size.try_set(size);
30    }
31
32    /// Record the database size reached by sync so far.
33    pub fn record_synced(&self, size: u64) {
34        let _ = self.size.try_set(size);
35    }
36}