Skip to content

Commit

Permalink
Configuration and logging improvements to logrotate_fs (#1074)
Browse files Browse the repository at this point in the history
### What does this PR do?

This commit involves minor tweaks to the logrotate_fs to improve logging
and the configuration of said generator. Also I include an example
config.
  • Loading branch information
blt authored Oct 29, 2024
1 parent d92f425 commit 063881b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
17 changes: 17 additions & 0 deletions examples/lading-logrotatefs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
generator:
- file_gen:
logrotate_fs:
seed: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131]
concurrent_logs: 8
maximum_bytes_per_log: 100MB
total_rotations: 4
max_depth: 0
variant: "ascii"
bytes_per_second: 10MB
maximum_prebuild_cache_size_bytes: 1GB
mount_point: /tmp/logrotate

blackhole:
- tcp:
binding_addr: "0.0.0.0:8080"
8 changes: 6 additions & 2 deletions lading/src/generator/file_gen/logrotate_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::{
time::Duration,
};
use tokio::task::{self, JoinError};
use tracing::{error, info};
use tracing::{debug, error, info};

mod model;

Expand Down Expand Up @@ -123,6 +123,10 @@ impl Server {
config.concurrent_logs,
);

info!(
"Creating logrotate filesystem with mount point {mount}",
mount = config.mount_point.display(),
);
// Initialize the FUSE filesystem
let fs = LogrotateFS {
state: Arc::new(Mutex::new(state)),
Expand Down Expand Up @@ -243,7 +247,7 @@ impl Filesystem for LogrotateFS {
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) {
info!("lookup: returning attr for inode {}: {:?}", ino, attr);
debug!("lookup: returning attr for inode {}: {:?}", ino, attr);
reply.entry(&TTL, &attr, 0);
return;
}
Expand Down
26 changes: 14 additions & 12 deletions lading/src/generator/file_gen/logrotate_fs/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,14 @@ impl State {
return state;
}

// Generate random group names
let num_groups = rng.gen_range(1..=concurrent_logs);
for group_id in 0..num_groups {
// Strategy:
//
// For 0 to `concurrent_logs` generate a directory path up to
// `max_depth` from the root node and place a file in that
// directory. Node that we must keep track of the group we're in, so we
// loop over `concurrent_logs`.
for group_id in 0..concurrent_logs {
// First, generate the group name.
let base: String = (0..8)
.map(|_| rng.sample(rand::distributions::Alphanumeric) as char)
.collect();
Expand All @@ -392,17 +397,14 @@ impl State {
names.push(format!("{base_name}.{i}")); // Ordinal i
}
state.group_names.push(names);
}

// Strategy:
//
// For 0 to num_groups generate a directory path up to `max_depth` from
// the root node and place a file in that directory. Node that we must
// keep track of the group we're in, so we loop over num_groups.

for group_id in 0..num_groups {
// Now, build up the directory tree and put the file in it.
let mut current_inode = state.root_inode;
let depth = rng.gen_range(1..=max_depth as usize);
let depth = if max_depth == 0 {
0
} else {
rng.gen_range(1..=max_depth as usize)
};

// Build the directory path
for _ in 0..depth {
Expand Down

0 comments on commit 063881b

Please sign in to comment.