Skip to content

Commit 8df06b5

Browse files
committed
chore: add persist and RootStore metrics
1 parent eea5be4 commit 8df06b5

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

firewood/src/persist_worker.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ use parking_lot::{Condvar, Mutex, MutexGuard};
6464
use crate::{manager::CommittedRevision, root_store::RootStore};
6565
use crossbeam::channel::{self, Receiver, Sender};
6666

67+
use firewood_metrics::firewood_increment;
6768
use firewood_storage::logger::error;
6869

6970
/// Error type for persistence operations.
@@ -385,6 +386,7 @@ impl PersistLoop {
385386
}
386387

387388
/// Persists the given revision and releases semaphore permits.
389+
#[crate::metrics("persist.total", "persist revision to storage")]
388390
fn persist(
389391
&mut self,
390392
revision: &CommittedRevision,
@@ -444,9 +446,17 @@ impl PersistLoop {
444446
if let Some(ref store) = self.shared.root_store
445447
&& let (Some(hash), Some(addr)) = (revision.root_hash(), revision.root_address())
446448
{
447-
store
449+
let start = coarsetime::Instant::now();
450+
451+
let result = store
448452
.add_root(&hash, &addr)
449-
.map_err(|e| PersistError::RootStore(e.into()))?;
453+
.map_err(|e| PersistError::RootStore(e.into()));
454+
455+
let success = if result.is_err() { "false" } else { "true" };
456+
firewood_increment!(crate::registry::PERSIST_ROOT_STORE, 1, "success" => success);
457+
firewood_increment!(crate::registry::PERSIST_ROOT_STORE_MS, start.elapsed().as_millis(), "success" => success);
458+
459+
result?;
450460
}
451461

452462
Ok(())

firewood/src/registry.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ pub const ACTIVE_REVISIONS: &str = "active_revisions";
3535
/// Maximum number of revisions configured.
3636
pub const MAX_REVISIONS: &str = "max_revisions";
3737

38+
/// Number of persist operations.
39+
pub const PERSIST_TOTAL: &str = "persist.total";
40+
41+
/// Persist latency in milliseconds.
42+
pub const PERSIST_TOTAL_MS: &str = "persist.total_ms";
43+
44+
/// Number of root store save operations.
45+
pub const PERSIST_ROOT_STORE: &str = "persist.root_store";
46+
47+
/// Root store save latency in milliseconds.
48+
pub const PERSIST_ROOT_STORE_MS: &str = "persist.root_store_ms";
49+
3850
/// Registers all firewood metric descriptions.
3951
pub fn register() {
4052
describe_counter!(PROPOSALS, "Number of proposals created");
@@ -59,4 +71,8 @@ pub fn register() {
5971
describe_counter!(COMMIT_LATENCY_MS, "Commit latency (ms)");
6072
describe_gauge!(ACTIVE_REVISIONS, "Current number of active revisions");
6173
describe_gauge!(MAX_REVISIONS, "Maximum number of revisions configured");
74+
describe_counter!(PERSIST_TOTAL, "Number of persist operations");
75+
describe_counter!(PERSIST_TOTAL_MS, "Persist latency (ms)");
76+
describe_counter!(PERSIST_ROOT_STORE, "Number of root store save operations");
77+
describe_counter!(PERSIST_ROOT_STORE_MS, "Root store save latency (ms)");
6278
}

0 commit comments

Comments
 (0)