Skip to content

Commit

Permalink
wire up configuration, review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
  • Loading branch information
blt committed Nov 2, 2023
1 parent 6dc7bf9 commit 5a44458
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 9 additions & 0 deletions lading/src/generator/file_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub enum Error {
/// Wrapper around [`traditional::Error`].
#[error(transparent)]
Traditional(#[from] traditional::Error),
/// Wrapper around [`logrotate::Error`].
#[error(transparent)]
Logrotate(#[from] logrotate::Error),
}

/// Configuration of [`FileGen`]
Expand All @@ -37,6 +40,8 @@ pub enum Error {
pub enum Config {
/// See [`traditional::Config`].
Traditional(traditional::Config),
/// See [`logrotate::Config`].
Logrotate(logrotate::Config),
}

#[derive(Debug)]
Expand All @@ -47,6 +52,8 @@ pub enum Config {
pub enum FileGen {
/// See [`traditional::Server`] for details.
Traditional(traditional::Server),
/// See [`logrotate::Server`] for details.
Logrotate(logrotate::Server),
}

impl FileGen {
Expand All @@ -66,6 +73,7 @@ impl FileGen {
Config::Traditional(c) => {
Self::Traditional(traditional::Server::new(general, c, shutdown)?)
}
Config::Logrotate(c) => Self::Logrotate(logrotate::Server::new(general, c, shutdown)?),
};
Ok(srv)
}
Expand All @@ -85,6 +93,7 @@ impl FileGen {
pub async fn spin(self) -> Result<(), Error> {
match self {
Self::Traditional(inner) => inner.spin().await?,
Self::Logrotate(inner) => inner.spin().await?,
};

Ok(())
Expand Down
10 changes: 7 additions & 3 deletions lading/src/generator/file_gen/logrotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ impl Child {
throttle: Throttle,
shutdown: Shutdown,
) -> Self {
let mut names = Vec::with_capacity(total_rotations as usize);
let mut names = Vec::with_capacity((total_rotations + 1).into());
names.push(PathBuf::from(basename));
for i in 0..total_rotations {
let name = format!(
"{orig}.{i}",
Expand Down Expand Up @@ -265,9 +266,10 @@ impl Child {
let maximum_bytes_per_log: u64 = u64::from(self.maximum_bytes_per_log.get());

let total_names = self.names.len();
let last_name = &self.names[total_names];
// SAFETY: By construction there is guaranteed to be at least one name.
let last_name = &self.names.last().unwrap();

// SAFETY: By construction the name is guranteed to have a parent.
// SAFETY: By construction the name is guaranteed to have a parent.
fs::create_dir_all(&self.names[0].parent().unwrap()).await?;
let mut fp = BufWriter::with_capacity(
bytes_per_second,
Expand All @@ -288,6 +290,8 @@ impl Child {
let bytes_written = register_counter!("bytes_written");

loop {
// SAFETY: By construction the block cache will never be empty
// except in the event of a catastrophic failure.
let blk = rcv.peek().await.unwrap();
let total_bytes = blk.total_bytes;

Expand Down

0 comments on commit 5a44458

Please sign in to comment.