Skip to content

Commit 6ca5bb0

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

File tree

8 files changed

+3282
-631
lines changed

8 files changed

+3282
-631
lines changed

Cargo.lock

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

Cargo.nix

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

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ edition = "2021"
1010
repository = "https://github.com/stackabletech/zookeeper-operator"
1111

1212
[workspace.dependencies]
13+
product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.7.0" }
14+
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.89.1" }
15+
stackable-telemetry = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-telemetry-0.4.0" }
16+
stackable-versioned = { git = "https://github.com/stackabletech/operator-rs.git", features = ["k8s"], tag = "stackable-versioned-0.7.1" }
17+
1318
anyhow = "1.0"
1419
built = { version = "0.7", features = ["chrono", "git2"] }
1520
clap = "4.5"
@@ -23,9 +28,6 @@ serde = { version = "1.0", features = ["derive"] }
2328
serde_json = "1.0"
2429
serde_yaml = "0.9"
2530
snafu = "0.8"
26-
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.87.5" }
27-
stackable-versioned = { git = "https://github.com/stackabletech/operator-rs.git", features = ["k8s"], tag = "stackable-versioned-0.7.0" }
28-
product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.7.0" }
2931
strum = { version = "0.27", features = ["derive"] }
3032
tokio = { version = "1.40", features = ["full"] }
3133
tokio-zookeeper = "0.4"

crate-hashes.json

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

rust/operator-binary/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ publish = false
1010
build = "build.rs"
1111

1212
[dependencies]
13+
stackable-operator.workspace = true
14+
stackable-telemetry.workspace = true
15+
stackable-versioned.workspace = true
16+
1317
anyhow.workspace = true
1418
clap.workspace = true
1519
const_format.workspace = true
@@ -22,8 +26,6 @@ semver.workspace = true
2226
serde.workspace = true
2327
serde_json.workspace = true
2428
snafu.workspace = true
25-
stackable-operator.workspace = true
26-
stackable-versioned.workspace = true
2729
strum.workspace = true
2830
tokio-zookeeper.workspace = true
2931
tokio.workspace = true

rust/operator-binary/src/main.rs

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use std::sync::Arc;
1+
use std::{ops::Deref as _, sync::Arc};
22

33
use clap::Parser;
44
use crd::{APP_NAME, OPERATOR_NAME, ZookeeperCluster, ZookeeperZnode, v1alpha1};
55
use futures::{StreamExt, pin_mut};
66
use stackable_operator::{
77
YamlSchema,
8-
cli::{Command, ProductOperatorRun},
8+
cli::{Command, ProductOperatorRun, RollingPeriod},
99
k8s_openapi::api::{
1010
apps::v1::StatefulSet,
1111
core::v1::{ConfigMap, Endpoints, Service},
@@ -23,6 +23,8 @@ use stackable_operator::{
2323
logging::controller::report_controller_reconciled,
2424
shared::yaml::SerializeOptions,
2525
};
26+
use stackable_telemetry::{Tracing, tracing::settings::Settings};
27+
use tracing::level_filters::LevelFilter;
2628

2729
use crate::{zk_controller::ZK_FULL_CONTROLLER_NAME, znode_controller::ZNODE_FULL_CONTROLLER_NAME};
2830

@@ -38,9 +40,11 @@ mod znode_controller;
3840

3941
mod built_info {
4042
include!(concat!(env!("OUT_DIR"), "/built.rs"));
41-
pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
4243
}
4344

45+
// TODO (@NickLarsenNZ): Change the variable to `CONSOLE_LOG`
46+
pub const ENV_VAR_CONSOLE_LOG: &str = "ZOOKEEPER_OPERATOR_LOG";
47+
4448
#[derive(clap::Parser)]
4549
#[clap(about, author)]
4650
struct Opts {
@@ -61,14 +65,47 @@ async fn main() -> anyhow::Result<()> {
6165
Command::Run(ProductOperatorRun {
6266
product_config,
6367
watch_namespace,
64-
tracing_target,
68+
telemetry_arguments,
6569
cluster_info_opts,
6670
}) => {
67-
stackable_operator::logging::initialize_logging(
68-
"ZOOKEEPER_OPERATOR_LOG",
69-
APP_NAME,
70-
tracing_target,
71-
);
71+
let _tracing_guard = Tracing::builder()
72+
.service_name("zookeeper-operator")
73+
.with_console_output((
74+
ENV_VAR_CONSOLE_LOG,
75+
LevelFilter::INFO,
76+
!telemetry_arguments.no_console_output,
77+
))
78+
// NOTE (@NickLarsenNZ): Before stackable-telemetry was used, the log directory was
79+
// set via an env: `ZOOKEEPER_OPERATOR_LOG_DIRECTORY`.
80+
// See: https://github.com/stackabletech/operator-rs/blob/f035997fca85a54238c8de895389cc50b4d421e2/crates/stackable-operator/src/logging/mod.rs#L40
81+
// Now it will be `ROLLING_LOGS` (or via `--rolling-logs <DIRECTORY>`).
82+
.with_file_output(telemetry_arguments.rolling_logs.map(|log_directory| {
83+
let rotation_period = telemetry_arguments
84+
.rolling_logs_period
85+
.unwrap_or(RollingPeriod::Never)
86+
.deref()
87+
.clone();
88+
89+
Settings::builder()
90+
.with_environment_variable(ENV_VAR_CONSOLE_LOG)
91+
.with_default_level(LevelFilter::INFO)
92+
.file_log_settings_builder(log_directory, "tracing-rs.log")
93+
.with_rotation_period(rotation_period)
94+
.build()
95+
}))
96+
.with_otlp_log_exporter((
97+
"OTLP_LOG",
98+
LevelFilter::DEBUG,
99+
telemetry_arguments.otlp_logs,
100+
))
101+
.with_otlp_trace_exporter((
102+
"OTLP_TRACE",
103+
LevelFilter::DEBUG,
104+
telemetry_arguments.otlp_traces,
105+
))
106+
.build()
107+
.init()?;
108+
72109
tracing::info!(
73110
built_info.pkg_version = built_info::PKG_VERSION,
74111
built_info.git_version = built_info::GIT_VERSION,

rust/operator-binary/src/zk_controller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ pub async fn reconcile_zk(
333333
let resolved_product_image = zk
334334
.spec
335335
.image
336-
.resolve(DOCKER_IMAGE_BASE_NAME, crate::built_info::CARGO_PKG_VERSION);
336+
.resolve(DOCKER_IMAGE_BASE_NAME, crate::built_info::PKG_VERSION);
337337

338338
let mut cluster_resources = ClusterResources::new(
339339
APP_NAME,

rust/operator-binary/src/znode_controller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub async fn reconcile_znode(
238238
let resolved_product_image = zk
239239
.spec
240240
.image
241-
.resolve(DOCKER_IMAGE_BASE_NAME, crate::built_info::CARGO_PKG_VERSION);
241+
.resolve(DOCKER_IMAGE_BASE_NAME, crate::built_info::PKG_VERSION);
242242
reconcile_apply(client, &znode, Ok(zk), &znode_path, &resolved_product_image)
243243
.await
244244
}

0 commit comments

Comments
 (0)