Skip to content

Commit

Permalink
Introduce 'logrotate' log generator (#720)
Browse files Browse the repository at this point in the history
* Introduce 'logrotate' log generator

This commit introduces a new log generator that is able to mimic logrotate's
operation. This also allows us to mimic how kubernetes logs work by setting
`total_rotations` to be zero.

REF SMPTNG-44

Signed-off-by: Brian L. Troutwine <[email protected]>

* losely -> loosely via @goxberry

Signed-off-by: Brian L. Troutwine <[email protected]>

* clippy dings

Signed-off-by: Brian L. Troutwine <[email protected]>

* wire up configuration, review feedback

Signed-off-by: Brian L. Troutwine <[email protected]>

* changelog, 0.20.0-rc1

Signed-off-by: Brian L. Troutwine <[email protected]>

---------

Signed-off-by: Brian L. Troutwine <[email protected]>
  • Loading branch information
blt authored Nov 7, 2023
1 parent f4b2111 commit 8c7d039
Show file tree
Hide file tree
Showing 3 changed files with 365 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.20.0-rc1]
### Added
- A new 'logrotate' file generator is introduced.

### Changed
- Existing file generator is renamed 'traditional', requiring a configuration
change.
Expand Down
10 changes: 10 additions & 0 deletions lading/src/generator/file_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//! Additional metrics may be emitted by this generator's [throttle].
//!

pub mod logrotate;
pub mod traditional;

use std::str;
Expand All @@ -28,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 @@ -36,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 @@ -46,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 @@ -65,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 @@ -84,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
Loading

0 comments on commit 8c7d039

Please sign in to comment.