Skip to content

Commit dc4958a

Browse files
committed
feat!: Replace log initialization with stackable-telemetry
BREAKING: The log directory variable for the rolling file appender has changed
1 parent 7ae057d commit dc4958a

File tree

8 files changed

+2524
-631
lines changed

8 files changed

+2524
-631
lines changed

Cargo.lock

Lines changed: 398 additions & 129 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.nix

Lines changed: 2008 additions & 475 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ edition = "2021"
1010
repository = "https://github.com/stackabletech/listener-operator"
1111

1212
[workspace.dependencies]
13+
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.89.1" }
14+
stackable-telemetry = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-telemetry-0.4.0" }
15+
1316
anyhow = "1.0"
1417
built = { version = "0.7", features = ["chrono", "git2"] }
1518
clap = "4.5"
@@ -24,7 +27,6 @@ serde = "1.0"
2427
serde_json = "1.0"
2528
serde_yaml = "0.9"
2629
snafu = "0.8"
27-
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.87.0" }
2830
strum = { version = "0.27", features = ["derive"] }
2931
socket2 = { version = "0.5", features = ["all"] }
3032
tokio = { version = "1.40", features = ["full"] }

crate-hashes.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/olm-deployer/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ repository.workspace = true
99
publish = false
1010

1111
[dependencies]
12+
stackable-operator.workspace = true
13+
stackable-telemetry.workspace = true
14+
1215
anyhow.workspace = true
1316
clap.workspace = true
1417
tokio.workspace = true
1518
tracing.workspace = true
16-
stackable-operator.workspace = true
1719
serde.workspace = true
1820
serde_json.workspace = true
1921
serde_yaml.workspace = true

rust/olm-deployer/src/main.rs

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,29 @@ mod owner;
1717
mod resources;
1818
mod tolerations;
1919

20+
use std::ops::Deref as _;
21+
2022
use anyhow::{Context, Result, anyhow, bail};
21-
use clap::{Parser, crate_description, crate_version};
23+
use clap::Parser;
2224
use stackable_operator::{
23-
cli::Command,
25+
cli::{Command, RollingPeriod, TelemetryArguments},
2426
client,
2527
k8s_openapi::api::{apps::v1::Deployment, rbac::v1::ClusterRole},
26-
kube,
2728
kube::{
29+
self,
2830
api::{Api, DynamicObject, ListParams, Patch, PatchParams, ResourceExt},
2931
core::GroupVersionKind,
3032
discovery::{ApiResource, Discovery, Scope},
3133
},
32-
logging, utils,
3334
utils::cluster_info::KubernetesClusterInfoOpts,
3435
};
36+
use stackable_telemetry::{Tracing, tracing::settings::Settings};
37+
use tracing::level_filters::LevelFilter;
3538

3639
pub const APP_NAME: &str = "stkbl-listener-olm-deployer";
37-
pub const ENV_VAR_LOGGING: &str = "STKBL_LISTENER_OLM_DEPLOYER_LOG";
40+
41+
// TODO (@NickLarsenNZ): Change the variable to `CONSOLE_LOG`
42+
pub const ENV_VAR_CONSOLE_LOG: &str = "STKBL_LISTENER_OLM_DEPLOYER_LOG";
3843

3944
mod built_info {
4045
include!(concat!(env!("OUT_DIR"), "/built.rs"));
@@ -56,21 +61,26 @@ struct OlmDeployerRun {
5661
help = "Keep running after manifests have been successfully applied."
5762
)]
5863
keep_alive: bool,
64+
5965
#[arg(
6066
long,
6167
short,
6268
help = "Name of ClusterServiceVersion object that owns this Deployment."
6369
)]
6470
csv: String,
71+
6572
#[arg(long, short, help = "Name of deployment object that owns this Pod.")]
6673
deployer: String,
74+
6775
#[arg(long, short, help = "Namespace of the ClusterServiceVersion object.")]
6876
namespace: String,
77+
6978
#[arg(long, short, help = "Directory with manifests to patch and apply.")]
7079
dir: std::path::PathBuf,
71-
/// Tracing log collector system
72-
#[arg(long, env, default_value_t, value_enum)]
73-
pub tracing_target: logging::TracingTarget,
80+
81+
#[command(flatten)]
82+
pub telemetry_arguments: TelemetryArguments,
83+
7484
#[command(flatten)]
7585
pub cluster_info_opts: KubernetesClusterInfoOpts,
7686
}
@@ -84,11 +94,48 @@ async fn main() -> Result<()> {
8494
deployer,
8595
namespace,
8696
dir,
87-
tracing_target,
97+
telemetry_arguments,
8898
cluster_info_opts,
8999
}) = opts.cmd
90100
{
91-
logging::initialize_logging(ENV_VAR_LOGGING, APP_NAME, tracing_target);
101+
let _tracing_guard = Tracing::builder()
102+
.service_name("secret-operator-olm-deployer")
103+
.with_console_output((
104+
ENV_VAR_CONSOLE_LOG,
105+
LevelFilter::INFO,
106+
!telemetry_arguments.no_console_output,
107+
))
108+
// NOTE (@NickLarsenNZ): Before stackable-telemetry was used, the log directory was
109+
// set via an env: `STKBL_LISTENER_OLM_DEPLOYER_LOG_DIRECTORY`.
110+
// See: https://github.com/stackabletech/operator-rs/blob/f035997fca85a54238c8de895389cc50b4d421e2/crates/stackable-operator/src/logging/mod.rs#L40
111+
// Now it will be `ROLLING_LOGS` (or via `--rolling-logs <DIRECTORY>`).
112+
.with_file_output(telemetry_arguments.rolling_logs.map(|log_directory| {
113+
let rotation_period = telemetry_arguments
114+
.rolling_logs_period
115+
.unwrap_or(RollingPeriod::Hourly)
116+
.deref()
117+
.clone();
118+
119+
Settings::builder()
120+
.with_environment_variable(ENV_VAR_CONSOLE_LOG)
121+
.with_default_level(LevelFilter::INFO)
122+
.file_log_settings_builder(log_directory, "tracing-rs.log")
123+
.with_rotation_period(rotation_period)
124+
.build()
125+
}))
126+
.with_otlp_log_exporter((
127+
"OTLP_LOG",
128+
LevelFilter::DEBUG,
129+
telemetry_arguments.otlp_logs,
130+
))
131+
.with_otlp_trace_exporter((
132+
"OTLP_TRACE",
133+
LevelFilter::DEBUG,
134+
telemetry_arguments.otlp_traces,
135+
))
136+
.build()
137+
.init()?;
138+
92139
tracing::info!(
93140
built_info.pkg_version = built_info::PKG_VERSION,
94141
built_info.git_version = built_info::GIT_VERSION,

rust/operator-binary/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ publish = false
1010

1111
[dependencies]
1212
csi-grpc = { path = "../csi-grpc" }
13+
stackable-operator.workspace = true
14+
stackable-telemetry.workspace = true
1315

1416
clap.workspace = true
1517
const_format.workspace = true
@@ -18,7 +20,6 @@ libc.workspace = true
1820
pin-project.workspace = true
1921
prost.workspace = true
2022
socket2.workspace = true
21-
stackable-operator.workspace = true
2223
tokio.workspace = true
2324
tokio-stream.workspace = true
2425
tonic.workspace = true

rust/operator-binary/src/main.rs

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{os::unix::prelude::FileTypeExt, path::PathBuf};
1+
use std::{ops::Deref as _, os::unix::prelude::FileTypeExt, path::PathBuf};
22

33
use clap::Parser;
44
use csi_grpc::v1::{
@@ -11,13 +11,15 @@ use csi_server::{
1111
use futures::{FutureExt, TryStreamExt, pin_mut};
1212
use stackable_operator::{
1313
CustomResourceExt,
14+
cli::{RollingPeriod, TelemetryArguments},
1415
commons::listener::{Listener, ListenerClass, PodListeners},
15-
logging::TracingTarget,
1616
utils::cluster_info::KubernetesClusterInfoOpts,
1717
};
18+
use stackable_telemetry::{Tracing, tracing::settings::Settings};
1819
use tokio::signal::unix::{SignalKind, signal};
1920
use tokio_stream::wrappers::UnixListenerStream;
2021
use tonic::transport::Server;
22+
use tracing::level_filters::LevelFilter;
2123
use utils::unix_stream::{TonicUnixStream, uds_bind_private};
2224

2325
mod csi_server;
@@ -36,15 +38,15 @@ struct Opts {
3638

3739
#[derive(clap::Parser)]
3840
struct ListenerOperatorRun {
39-
#[arg(long, env, default_value_t, value_enum)]
40-
tracing_target: TracingTarget,
41-
4241
#[clap(long, env)]
4342
csi_endpoint: PathBuf,
4443

4544
#[clap(subcommand)]
4645
mode: RunMode,
4746

47+
#[command(flatten)]
48+
pub telemetry_arguments: TelemetryArguments,
49+
4850
#[command(flatten)]
4951
pub cluster_info_opts: KubernetesClusterInfoOpts,
5052
}
@@ -62,6 +64,9 @@ mod built_info {
6264
include!(concat!(env!("OUT_DIR"), "/built.rs"));
6365
}
6466

67+
// TODO (@NickLarsenNZ): Change the variable to `CONSOLE_LOG`
68+
pub const ENV_VAR_CONSOLE_LOG: &str = "LISTENER_OPERATOR_LOG";
69+
6570
#[tokio::main]
6671
async fn main() -> anyhow::Result<()> {
6772
let opts = Opts::parse();
@@ -72,16 +77,49 @@ async fn main() -> anyhow::Result<()> {
7277
PodListeners::print_yaml_schema(built_info::PKG_VERSION)?;
7378
}
7479
stackable_operator::cli::Command::Run(ListenerOperatorRun {
75-
tracing_target,
7680
csi_endpoint,
7781
mode,
82+
telemetry_arguments,
7883
cluster_info_opts,
7984
}) => {
80-
stackable_operator::logging::initialize_logging(
81-
"LISTENER_OPERATOR_LOG",
82-
"listener-operator",
83-
tracing_target,
84-
);
85+
let _tracing_guard = Tracing::builder()
86+
.service_name("listener-operator")
87+
.with_console_output((
88+
ENV_VAR_CONSOLE_LOG,
89+
LevelFilter::INFO,
90+
!telemetry_arguments.no_console_output,
91+
))
92+
// NOTE (@NickLarsenNZ): Before stackable-telemetry was used, the log directory was
93+
// set via an env: `LISTENER_OPERATOR_LOG_DIRECTORY`.
94+
// See: https://github.com/stackabletech/operator-rs/blob/f035997fca85a54238c8de895389cc50b4d421e2/crates/stackable-operator/src/logging/mod.rs#L40
95+
// Now it will be `ROLLING_LOGS` (or via `--rolling-logs <DIRECTORY>`).
96+
.with_file_output(telemetry_arguments.rolling_logs.map(|log_directory| {
97+
let rotation_period = telemetry_arguments
98+
.rolling_logs_period
99+
.unwrap_or(RollingPeriod::Hourly)
100+
.deref()
101+
.clone();
102+
103+
Settings::builder()
104+
.with_environment_variable(ENV_VAR_CONSOLE_LOG)
105+
.with_default_level(LevelFilter::INFO)
106+
.file_log_settings_builder(log_directory, "tracing-rs.log")
107+
.with_rotation_period(rotation_period)
108+
.build()
109+
}))
110+
.with_otlp_log_exporter((
111+
"OTLP_LOG",
112+
LevelFilter::DEBUG,
113+
telemetry_arguments.otlp_logs,
114+
))
115+
.with_otlp_trace_exporter((
116+
"OTLP_TRACE",
117+
LevelFilter::DEBUG,
118+
telemetry_arguments.otlp_traces,
119+
))
120+
.build()
121+
.init()?;
122+
85123
tracing::info!(
86124
run_mode = %mode,
87125
built_info.pkg_version = built_info::PKG_VERSION,

0 commit comments

Comments
 (0)