Skip to content

Commit

Permalink
Add telemetry to logrotate_fs
Browse files Browse the repository at this point in the history
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 <brian.troutwine@datadoghq.com>
  • Loading branch information
blt committed Oct 31, 2024
1 parent ce6d1aa commit bd8c65a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lading/src/generator/file_gen/logrotate_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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;

Expand Down Expand Up @@ -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();
{
Expand Down
2 changes: 2 additions & 0 deletions lading/src/generator/file_gen/logrotate_fs/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit bd8c65a

Please sign in to comment.