Skip to content

Commit 69a0e2a

Browse files
maltesanderclaude
andcommitted
refactor: Move logging constants out of crd into their consumers
These constants are no longer used in crd/mod.rs. Following hdfs-operator (logging constants live in the logging builder) and trino-operator (MAX_PREPARE_LOG_FILE_SIZE lives in the controller): - LOGBACK_CONFIG_FILE, LOG4J_CONFIG_FILE, ZOOKEEPER_LOG_FILE and MAX_ZK_LOG_FILES_SIZE move to zk_controller/build/properties/logging.rs. - MAX_PREPARE_LOG_FILE_SIZE (the prepare init container) moves to zk_controller.rs. - config/jvm.rs keeps its own local log-config-file consts (as it already does for security.properties) to avoid coupling config to the controller build module. No behavior change. Build, clippy, the 16 unit tests, and the generated CRD are all unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent bb1f171 commit 69a0e2a

5 files changed

Lines changed: 35 additions & 32 deletions

File tree

rust/operator-binary/src/config/jvm.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use stackable_operator::{
55
};
66

77
use crate::crd::{
8-
JMX_METRICS_PORT, LOG4J_CONFIG_FILE, LOGBACK_CONFIG_FILE, LoggingFramework,
9-
STACKABLE_CONFIG_DIR, STACKABLE_LOG_CONFIG_DIR, ZookeeperServerRoleType,
8+
JMX_METRICS_PORT, LoggingFramework, STACKABLE_CONFIG_DIR, STACKABLE_LOG_CONFIG_DIR,
9+
ZookeeperServerRoleType,
1010
v1alpha1::{ZookeeperCluster, ZookeeperConfig},
1111
};
1212

@@ -16,6 +16,11 @@ const JAVA_HEAP_FACTOR: f32 = 0.8;
1616
/// ConfigMap (see `zk_controller::build::properties::ConfigFileName`).
1717
const JVM_SECURITY_PROPERTIES_FILE: &str = "security.properties";
1818

19+
/// The log config files the JVM is pointed at via system properties. These are
20+
/// written by `zk_controller::build::properties::logging`.
21+
const LOG4J_CONFIG_FILE: &str = "log4j.properties";
22+
const LOGBACK_CONFIG_FILE: &str = "logback.xml";
23+
1924
#[derive(Snafu, Debug)]
2025
pub enum Error {
2126
#[snafu(display("invalid memory resource configuration - missing default or value in crd?"))]

rust/operator-binary/src/crd/mod.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use stackable_operator::{
2323
apimachinery::pkg::api::resource::Quantity,
2424
},
2525
kube::{CustomResource, ResourceExt, runtime::reflector::ObjectRef},
26-
memory::{BinaryMultiple, MemoryQuantity},
2726
product_logging::{self, spec::Logging},
2827
role_utils::{GenericRoleConfig, JavaCommonConfig, Role, RoleGroup, RoleGroupRef},
2928
schemars::{self, JsonSchema},
@@ -67,20 +66,6 @@ pub const STACKABLE_LOG_CONFIG_DIR: &str = "/stackable/log_config";
6766
pub const STACKABLE_LOG_DIR: &str = "/stackable/log";
6867
pub const STACKABLE_RW_CONFIG_DIR: &str = "/stackable/rwconfig";
6968

70-
pub const LOGBACK_CONFIG_FILE: &str = "logback.xml";
71-
pub const LOG4J_CONFIG_FILE: &str = "log4j.properties";
72-
73-
pub const ZOOKEEPER_LOG_FILE: &str = "zookeeper.log4j.xml";
74-
75-
pub const MAX_ZK_LOG_FILES_SIZE: MemoryQuantity = MemoryQuantity {
76-
value: 10.0,
77-
unit: BinaryMultiple::Mebi,
78-
};
79-
pub const MAX_PREPARE_LOG_FILE_SIZE: MemoryQuantity = MemoryQuantity {
80-
value: 1.0,
81-
unit: BinaryMultiple::Mebi,
82-
};
83-
8469
pub const CONTAINER_IMAGE_BASE_NAME: &str = "zookeeper";
8570

8671
const DEFAULT_SERVER_GRACEFUL_SHUTDOWN_TIMEOUT: Duration = Duration::from_minutes_unchecked(2);

rust/operator-binary/src/zk_controller.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use stackable_operator::{
4040
},
4141
kvp::{LabelError, Labels},
4242
logging::controller::ReconcilerError,
43+
memory::{BinaryMultiple, MemoryQuantity},
4344
product_logging::{
4445
self,
4546
framework::{
@@ -65,9 +66,8 @@ use crate::{
6566
command::create_init_container_command_args,
6667
config::jvm::{construct_non_heap_jvm_args, construct_zk_server_heap_env},
6768
crd::{
68-
JMX_METRICS_PORT_NAME, MAX_PREPARE_LOG_FILE_SIZE, MAX_ZK_LOG_FILES_SIZE,
69-
METRICS_PROVIDER_HTTP_PORT_NAME, STACKABLE_CONFIG_DIR, STACKABLE_DATA_DIR,
70-
STACKABLE_LOG_CONFIG_DIR, STACKABLE_LOG_DIR, STACKABLE_RW_CONFIG_DIR,
69+
JMX_METRICS_PORT_NAME, METRICS_PROVIDER_HTTP_PORT_NAME, STACKABLE_CONFIG_DIR,
70+
STACKABLE_DATA_DIR, STACKABLE_LOG_CONFIG_DIR, STACKABLE_LOG_DIR, STACKABLE_RW_CONFIG_DIR,
7171
ZOOKEEPER_ELECTION_PORT, ZOOKEEPER_ELECTION_PORT_NAME, ZOOKEEPER_LEADER_PORT,
7272
ZOOKEEPER_LEADER_PORT_NAME, ZOOKEEPER_SERVER_PORT_NAME, ZookeeperRole,
7373
security::{self, ZookeeperSecurity},
@@ -90,6 +90,12 @@ pub const ZK_FULL_CONTROLLER_NAME: &str = concatcp!(ZK_CONTROLLER_NAME, '.', OPE
9090
pub const LISTENER_VOLUME_NAME: &str = "listener";
9191
pub const LISTENER_VOLUME_DIR: &str = "/stackable/listener";
9292

93+
/// Maximum size of the `prepare` init container log file (before rotation).
94+
pub const MAX_PREPARE_LOG_FILE_SIZE: MemoryQuantity = MemoryQuantity {
95+
value: 1.0,
96+
unit: BinaryMultiple::Mebi,
97+
};
98+
9399
pub struct Ctx {
94100
pub client: stackable_operator::client::Client,
95101
pub operator_environment: OperatorEnvironmentOptions,
@@ -763,7 +769,10 @@ fn build_server_rolegroup_statefulset(
763769
.add_empty_dir_volume(
764770
"log",
765771
Some(product_logging::framework::calculate_log_volume_size_limit(
766-
&[MAX_ZK_LOG_FILES_SIZE, MAX_PREPARE_LOG_FILE_SIZE],
772+
&[
773+
build::properties::logging::MAX_ZK_LOG_FILES_SIZE,
774+
MAX_PREPARE_LOG_FILE_SIZE,
775+
],
767776
)),
768777
)
769778
.context(AddVolumeSnafu)?

rust/operator-binary/src/zk_controller/build/properties/logging.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
//! Builders for the logging-related files in the rolegroup ConfigMap: the
22
//! product log config (`logback.xml` / `log4j.properties`) and the Vector agent
33
//! config (`vector.yaml`).
4-
//!
5-
//! Moved from the former top-level `product_logging` module so that all ConfigMap
6-
//! contributions live under `zk_controller/build` (mirrors trino-operator and
7-
//! hdfs-operator).
84
95
use std::collections::BTreeMap;
106

117
use snafu::{ResultExt, Snafu};
128
use stackable_operator::{
13-
memory::BinaryMultiple,
9+
memory::{BinaryMultiple, MemoryQuantity},
1410
product_logging::{
1511
self,
1612
spec::{ContainerLogConfig, ContainerLogConfigChoice},
1713
},
1814
role_utils::RoleGroupRef,
1915
};
2016

21-
use crate::crd::{
22-
LOG4J_CONFIG_FILE, LOGBACK_CONFIG_FILE, LoggingFramework, MAX_ZK_LOG_FILES_SIZE,
23-
STACKABLE_LOG_DIR, ZOOKEEPER_LOG_FILE, ZookeeperRole, v1alpha1,
17+
use crate::crd::{LoggingFramework, STACKABLE_LOG_DIR, ZookeeperRole, v1alpha1};
18+
19+
/// The logback config file name (when the product uses the LOGBACK framework).
20+
pub const LOGBACK_CONFIG_FILE: &str = "logback.xml";
21+
/// The log4j config file name (when the product uses the LOG4J framework).
22+
pub const LOG4J_CONFIG_FILE: &str = "log4j.properties";
23+
/// The file the ZooKeeper server logs are written to.
24+
pub const ZOOKEEPER_LOG_FILE: &str = "zookeeper.log4j.xml";
25+
26+
/// Maximum size of the ZooKeeper server log files (before rotation).
27+
pub const MAX_ZK_LOG_FILES_SIZE: MemoryQuantity = MemoryQuantity {
28+
value: 10.0,
29+
unit: BinaryMultiple::Mebi,
2430
};
2531

2632
#[derive(Snafu, Debug)]

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
//! Per-file builders for the ZooKeeper config files.
22
//!
33
//! Each submodule renders the key/value pairs (or file contents) for one file
4-
//! that ends up in the rolegroup ConfigMap. The shared
5-
//! [`writer`](crate::framework::writer) module serializes property maps to the
6-
//! Java-properties on-wire format.
4+
//! that ends up in the rolegroup ConfigMap.
75
86
use std::collections::BTreeMap;
97

0 commit comments

Comments
 (0)