Skip to content

feat(stackable-telemetry)!: Allow configuration of file_log_max_files #1010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 11, 2025
8 changes: 7 additions & 1 deletion crates/stackable-operator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added

- Adds the `--file-log-max-files` CLI argument and `FILE_LOG_MAX_FILES` environment variable
see detailed [stackable-telemetry changelog](../stackable-telemetry/CHANGELOG.md) ([#1010]).

### Changed

- BREAKING: Update and align telemetry related CLI arguments of `ProductOperatorRun`, see detailed
changelog [here](../stackable-telemetry/CHANGELOG.md) ([#1009]).
changelog [stackable-telemetry changelog](../stackable-telemetry/CHANGELOG.md) ([#1009]).

[#1009]: https://github.com/stackabletech/operator-rs/pull/1009
[#1010]: https://github.com/stackabletech/operator-rs/pull/1010

## [0.91.1] - 2025-04-09

Expand Down
6 changes: 6 additions & 0 deletions crates/stackable-telemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ All notable changes to this project will be documented in this file.
- `FILE_LOG_LEVEL` instead of `FILE_LOG`.
- `OTEL_LOG_EXPORTER_LEVEL` instead of `OTLP_LOG`.
- `OTEL_TRACE_EXPORTER_LEVEL` instead of `OTLP_TRACE`.
- BREAKING: Allow configuration of `file_log_max_files` ([#1010]).
- Adds the `--file-log-max-files` CLI argument (env: `FILE_LOG_MAX_FILES`).
- `FileLogSettingsBuilder::with_max_log_files` which took a `usize` was renamed to
`FileLogSettingsBuilder::with_max_files` and now takes an `impl Into<Option<usize>>`
for improved builder ergonomics.

[#1009]: https://github.com/stackabletech/operator-rs/pull/1009
[#1010]: https://github.com/stackabletech/operator-rs/pull/1010

## [0.5.0] - 2025-04-08

Expand Down
11 changes: 11 additions & 0 deletions crates/stackable-telemetry/src/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub enum Error {
/// console_log_disabled: false,
/// file_log_directory: None,
/// file_log_rotation_period: None,
/// file_log_max_files: Some(6),
/// otel_trace_exporter_enabled: true,
/// otel_log_exporter_enabled: true,
/// };
Expand Down Expand Up @@ -348,6 +349,7 @@ impl Tracing {
console_log_disabled,
file_log_directory,
file_log_rotation_period,
file_log_max_files,
otel_trace_exporter_enabled,
otel_log_exporter_enabled,
} = options;
Expand All @@ -367,6 +369,7 @@ impl Tracing {
.with_default_level(LevelFilter::INFO)
.file_log_settings_builder(log_directory, Self::FILE_LOG_SUFFIX)
.with_rotation_period(file_log_rotation_period)
.with_max_files(file_log_max_files)
.build()
}))
.with_otlp_log_exporter((
Expand Down Expand Up @@ -775,6 +778,13 @@ pub struct TelemetryOptions {
)]
pub file_log_rotation_period: Option<RotationPeriod>,

/// Maximum NUMBER of log files to keep.
#[cfg_attr(
feature = "clap",
arg(long, env, value_name = "NUMBER", requires = "file_log")
)]
pub file_log_max_files: Option<usize>,

/// Enable exporting OpenTelemetry traces via OTLP.
#[cfg_attr(feature = "clap", arg(long, env))]
pub otel_trace_exporter_enabled: bool,
Expand Down Expand Up @@ -1015,6 +1025,7 @@ mod test {
console_log_disabled: false,
file_log_directory: None,
file_log_rotation_period: None,
file_log_max_files: None,
otel_trace_exporter_enabled: true,
otel_log_exporter_enabled: false,
});
Expand Down
6 changes: 3 additions & 3 deletions crates/stackable-telemetry/src/tracing/settings/file_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ impl FileLogSettingsBuilder {
}

/// Set maximum number of log files to keep.
pub fn with_max_log_files(mut self, max_log_files: usize) -> Self {
self.max_log_files = Some(max_log_files);
pub fn with_max_files(mut self, max_log_files: impl Into<Option<usize>>) -> Self {
self.max_log_files = max_log_files.into();
self
}

Expand Down Expand Up @@ -115,7 +115,7 @@ mod test {
.with_default_level(LevelFilter::DEBUG)
.file_log_settings_builder(PathBuf::from("/logs"), "tracing-rs.log")
.with_rotation_period(Rotation::HOURLY)
.with_max_log_files(6)
.with_max_files(6)
.build();

assert_eq!(expected, result);
Expand Down