Skip to content

Commit aaa2ca9

Browse files
committed
refactor: render logback from validated log-config choice
1 parent 8ad1112 commit aaa2ca9

2 files changed

Lines changed: 37 additions & 42 deletions

File tree

  • rust/operator-binary/src/zk_controller/build

rust/operator-binary/src/zk_controller/build/properties/product_logging/mod.rs

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22
//! product log config (`logback.xml` / `log4j.properties`) and the Vector agent
33
//! config (`vector.yaml`).
44
5-
use std::collections::BTreeMap;
6-
75
use stackable_operator::{
86
memory::{BinaryMultiple, MemoryQuantity},
9-
product_logging::{
10-
self,
11-
spec::{ContainerLogConfig, ContainerLogConfigChoice, Logging},
12-
},
7+
product_logging::{self, spec::AutomaticContainerLogConfig},
8+
v2::product_logging::framework::ValidatedContainerLogConfigChoice,
139
};
1410

15-
use super::ConfigFileName;
16-
use crate::crd::{STACKABLE_LOG_DIR, v1alpha1};
11+
use crate::crd::STACKABLE_LOG_DIR;
1712

1813
/// The file the ZooKeeper server logs are written to.
1914
pub const ZOOKEEPER_LOG_FILE: &str = "zookeeper.log4j.xml";
@@ -39,41 +34,39 @@ pub fn vector_config_file_content() -> String {
3934
VECTOR_CONFIG.to_owned()
4035
}
4136

42-
/// Builds the product log config entry (`logback.xml`) for a role group.
37+
/// Renders the product log config (`logback.xml`) for the ZooKeeper server container.
4338
///
44-
/// `logging` is the merged [`Logging`] from the role group's validated config.
39+
/// Returns `None` when the container uses a custom log ConfigMap instead of the operator's
40+
/// automatic logging configuration, in which case no `logback.xml` is added to the rolegroup
41+
/// `ConfigMap`. Consumes the *validated* log-config choice (off `ValidatedLogging`) rather than
42+
/// re-reading the raw `Logging`.
4543
///
46-
/// The Vector agent config (`vector.yaml`) is added separately via
47-
/// [`vector_config_file_content`].
48-
pub fn build_product_log_config(
49-
logging: &Logging<v1alpha1::Container>,
50-
) -> BTreeMap<String, String> {
51-
let mut data = BTreeMap::new();
52-
53-
if let Some(ContainerLogConfig {
54-
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
55-
}) = logging.containers.get(&v1alpha1::Container::Zookeeper)
56-
{
57-
let log_dir = format!("{STACKABLE_LOG_DIR}/zookeeper");
58-
let max_log_file_size_mib = MAX_ZK_LOG_FILES_SIZE
59-
.scale_to(BinaryMultiple::Mebi)
60-
.floor()
61-
.value as u32;
62-
63-
data.insert(
64-
ConfigFileName::LogbackXml.to_string(),
65-
product_logging::framework::create_logback_config(
66-
&log_dir,
67-
ZOOKEEPER_LOG_FILE,
68-
max_log_file_size_mib,
69-
CONSOLE_CONVERSION_PATTERN,
70-
log_config,
71-
None,
72-
),
73-
);
44+
/// The Vector agent config (`vector.yaml`) is added separately via [`vector_config_file_content`].
45+
pub fn build_logback_config(
46+
zookeeper_container: &ValidatedContainerLogConfigChoice,
47+
) -> Option<String> {
48+
match zookeeper_container {
49+
ValidatedContainerLogConfigChoice::Automatic(log_config) => {
50+
Some(logback_config(log_config))
51+
}
52+
ValidatedContainerLogConfigChoice::Custom(_) => None,
7453
}
54+
}
7555

76-
data
56+
fn logback_config(log_config: &AutomaticContainerLogConfig) -> String {
57+
let log_dir = format!("{STACKABLE_LOG_DIR}/zookeeper");
58+
let max_log_file_size_mib = MAX_ZK_LOG_FILES_SIZE
59+
.scale_to(BinaryMultiple::Mebi)
60+
.floor()
61+
.value as u32;
62+
product_logging::framework::create_logback_config(
63+
&log_dir,
64+
ZOOKEEPER_LOG_FILE,
65+
max_log_file_size_mib,
66+
CONSOLE_CONVERSION_PATTERN,
67+
log_config,
68+
None,
69+
)
7770
}
7871

7972
#[cfg(test)]

rust/operator-binary/src/zk_controller/build/resource/config_map.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ pub fn build_server_rolegroup_config_map(
7777
);
7878

7979
// logback.xml
80-
data.extend(product_logging::build_product_log_config(
81-
&rolegroup_config.config.logging,
82-
));
80+
if let Some(logback) =
81+
product_logging::build_logback_config(&rolegroup_config.logging.zookeeper_container)
82+
{
83+
data.insert(ConfigFileName::LogbackXml.to_string(), logback);
84+
}
8385

8486
// vector.yaml (only present when the Vector agent is enabled)
8587
if rolegroup_config.config.logging.enable_vector_agent {

0 commit comments

Comments
 (0)