Skip to content

feat!: Add method for pre-configured Tracing instance #1001

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 18 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions crates/stackable-operator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Changed

- BREAKING: Remove `cli::TelemetryArguments` and `cli::RollingPeriod` which are both replaced by
types from `stackable_telemetry` ([#1001]).
- BREAKING: The `ProductOperatorRun` struct now uses `stackable_telemetry::tracing::TelemetryOptions`
for the `telemetry_arguments` field ([#1001]).

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

## [0.90.0] - 2025-04-07

### Added
Expand Down
1 change: 1 addition & 0 deletions crates/stackable-operator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository.workspace = true
time = ["dep:time"]

[dependencies]
stackable-telemetry = { path = "../stackable-telemetry", features = ["clap"]}
stackable-operator-derive = { path = "../stackable-operator-derive" }
stackable-shared = { path = "../stackable-shared" }

Expand Down
56 changes: 5 additions & 51 deletions crates/stackable-operator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@
//!
use std::{
ffi::OsStr,
ops::Deref,
path::{Path, PathBuf},
};

use clap::Args;
use product_config::ProductConfigManager;
use snafu::{ResultExt, Snafu};
use stackable_telemetry::tracing::TelemetryOptions;

use crate::{namespace::WatchNamespace, utils::cluster_info::KubernetesClusterInfoOpts};

Expand Down Expand Up @@ -165,10 +165,8 @@ pub enum Command<Run: Args = ProductOperatorRun> {
/// ```rust
/// # use stackable_operator::cli::{Command, ProductOperatorRun, ProductConfigPath};
/// use clap::Parser;
/// use stackable_operator::{
/// cli::TelemetryArguments,
/// namespace::WatchNamespace,
/// };
/// use stackable_operator::namespace::WatchNamespace;
/// use stackable_telemetry::tracing::TelemetryOptions;
///
/// #[derive(clap::Parser, Debug, PartialEq, Eq)]
/// struct Run {
Expand All @@ -184,7 +182,7 @@ pub enum Command<Run: Args = ProductOperatorRun> {
/// common: ProductOperatorRun {
/// product_config: ProductConfigPath::from("bar".as_ref()),
/// watch_namespace: WatchNamespace::One("foobar".to_string()),
/// telemetry_arguments: TelemetryArguments::default(),
/// telemetry_arguments: TelemetryOptions::default(),
/// cluster_info_opts: Default::default(),
/// },
/// }));
Expand Down Expand Up @@ -219,7 +217,7 @@ pub struct ProductOperatorRun {
pub watch_namespace: WatchNamespace,

#[command(flatten)]
pub telemetry_arguments: TelemetryArguments,
pub telemetry_arguments: TelemetryOptions,

#[command(flatten)]
pub cluster_info_opts: KubernetesClusterInfoOpts,
Expand Down Expand Up @@ -280,50 +278,6 @@ impl ProductConfigPath {
}
}

#[derive(Debug, Default, PartialEq, Eq, Args)]
pub struct TelemetryArguments {
/// Disable console output.
#[arg(long, env)]
pub no_console_output: bool,

/// Enable logging to rolling files located in the specified DIRECTORY.
#[arg(long, env, value_name = "DIRECTORY", group = "rolling_logs_group")]
pub rolling_logs: Option<PathBuf>,

/// Time PERIOD after which log files are rolled over.
#[arg(long, env, value_name = "PERIOD", requires = "rolling_logs_group")]
pub rolling_logs_period: Option<RollingPeriod>,

/// Enable exporting traces via OTLP.
#[arg(long, env)]
pub otlp_traces: bool,

/// Enable exporting logs via OTLP.
#[arg(long, env)]
pub otlp_logs: bool,
}

#[derive(Clone, Debug, PartialEq, Eq, strum::Display, strum::EnumString, clap::ValueEnum)]
pub enum RollingPeriod {
Minutely,
Hourly,
Daily,
Never,
}

impl Deref for RollingPeriod {
type Target = tracing_appender::rolling::Rotation;

fn deref(&self) -> &Self::Target {
match self {
RollingPeriod::Minutely => &tracing_appender::rolling::Rotation::MINUTELY,
RollingPeriod::Hourly => &tracing_appender::rolling::Rotation::HOURLY,
RollingPeriod::Daily => &tracing_appender::rolling::Rotation::DAILY,
RollingPeriod::Never => &tracing_appender::rolling::Rotation::NEVER,
}
}
}

#[cfg(test)]
mod tests {
use std::{env, fs::File};
Expand Down
13 changes: 13 additions & 0 deletions crates/stackable-telemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added

- Add new `Tracing::pre_configured` method ([#1001]).
- Add `TelemetryOptions` struct and `RollingPeriod` enum
- Add `clap` feature to enable `TelemetryOptions` being used as CLI arguments

### Changed

- BREAKING: Change `FileLogSettingsBuilder::with_rotation_period` to take `impl Into<Rotation>`
instead of `Rotation` ([#1001]).

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

## [0.4.0] - 2025-04-02

### Added
Expand Down
5 changes: 5 additions & 0 deletions crates/stackable-telemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ license.workspace = true
edition.workspace = true
repository.workspace = true

[features]
clap = ["dep:clap"]

[dependencies]
axum.workspace = true
clap = { workspace = true, optional = true }
futures-util.workspace = true
opentelemetry = { workspace = true, features = ["logs"] }
opentelemetry-appender-tracing.workspace = true
Expand All @@ -16,6 +20,7 @@ opentelemetry-otlp = { workspace = true, features = ["grpc-tonic", "gzip-tonic",
opentelemetry_sdk = { workspace = true, features = ["logs", "rt-tokio", "spec_unstable_logs_enabled"] }
pin-project.workspace = true
snafu.workspace = true
strum.workspace = true
tokio.workspace = true
tower.workspace = true
tracing.workspace = true
Expand Down
Loading