From 9df0fec894c8978de4970e724583a10e03a78d99 Mon Sep 17 00:00:00 2001 From: "Brian L. Troutwine" Date: Thu, 31 Oct 2024 11:26:09 -0700 Subject: [PATCH] Add telemetry to logrotate_fs This commit adds telemetry around filesystem and model operations. I am especially interested to know when rotations happen, how often and what operations the reader is calling against the filesystem. Signed-off-by: Brian L. Troutwine --- lading/src/generator/file_gen/logrotate_fs.rs | 13 +++++++++++++ lading/src/generator/file_gen/logrotate_fs/model.rs | 2 ++ 2 files changed, 15 insertions(+) diff --git a/lading/src/generator/file_gen/logrotate_fs.rs b/lading/src/generator/file_gen/logrotate_fs.rs index 3fad75872..6926bbc54 100644 --- a/lading/src/generator/file_gen/logrotate_fs.rs +++ b/lading/src/generator/file_gen/logrotate_fs.rs @@ -10,6 +10,7 @@ use fuser::{ ReplyDirectory, ReplyEntry, Request, }; use lading_payload::block; +use metrics::counter; use nix::libc::{self, ENOENT}; use rand::{rngs::SmallRng, SeedableRng}; use serde::{Deserialize, Serialize}; @@ -250,6 +251,8 @@ impl Filesystem for LogrotateFS { let mut state = self.state.lock().expect("lock poisoned"); state.advance_time(tick); + counter!("fs_lookup").increment(1); + let name_str = name.to_str().unwrap_or(""); if let Some(ino) = state.lookup(tick, parent as usize, name_str) { if let Some(attr) = getattr_helper(&mut state, self.start_time_system, tick, ino) { @@ -270,6 +273,8 @@ impl Filesystem for LogrotateFS { let mut state = self.state.lock().expect("lock poisoned"); state.advance_time(tick); + counter!("fs_getattr").increment(1); + if let Some(attr) = getattr_helper(&mut state, self.start_time_system, tick, ino as usize) { reply.attr(&TTL, &attr); } else { @@ -293,6 +298,8 @@ impl Filesystem for LogrotateFS { let mut state = self.state.lock().expect("lock poisoned"); state.advance_time(tick); + counter!("fs_read").increment(1); + // Get the FileHandle from fh let file_handle = { let open_files = self.open_files.lock().expect("lock poisoned"); @@ -329,6 +336,8 @@ impl Filesystem for LogrotateFS { let mut state = self.state.lock().expect("lock poisoned"); state.advance_time(tick); + counter!("fs_release").increment(1); + // Remove the FileHandle from the mapping let file_handle = { let mut open_files = self.open_files.lock().expect("lock poisoned"); @@ -350,6 +359,8 @@ impl Filesystem for LogrotateFS { let mut state = self.state.lock().expect("lock poisoned"); state.advance_time(tick); + counter!("fs_readdir").increment(1); + let root_inode = state.root_inode(); let mut entry_offset = 0; @@ -410,6 +421,8 @@ impl Filesystem for LogrotateFS { let mut state = self.state.lock().expect("lock poisoned"); state.advance_time(tick); + counter!("fs_open").increment(1); + if let Some(file_handle) = state.open_file(tick, ino as usize) { let fh = file_handle.id(); { diff --git a/lading/src/generator/file_gen/logrotate_fs/model.rs b/lading/src/generator/file_gen/logrotate_fs/model.rs index 0bceaa786..87f77f638 100644 --- a/lading/src/generator/file_gen/logrotate_fs/model.rs +++ b/lading/src/generator/file_gen/logrotate_fs/model.rs @@ -642,6 +642,7 @@ impl State { let (remove_current, next_peer) = match node { Node::File { file } => { file.incr_ordinal(); + counter!("log_file_rotated").increment(1); let remove_current = file.ordinal() > self.max_rotations; (remove_current, file.peer) @@ -712,6 +713,7 @@ impl State { for inode in to_remove { if let Some(Node::File { file }) = self.nodes.remove(&inode) { let lost_bytes = file.bytes_written.saturating_sub(file.max_offset_observed); + counter!("log_file_deleted").increment(1); counter!("lost_bytes").increment(lost_bytes); } }