Skip to content

Commit 63d820c

Browse files
committed
refactor: move logging mod to controller, remove util mod
1 parent b4fd4dc commit 63d820c

12 files changed

Lines changed: 86 additions & 79 deletions

File tree

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,29 @@ use stackable_operator::{
66
utils::COMMON_BASH_TRAP_FUNCTIONS,
77
};
88

9-
use crate::{
10-
crd::{
11-
KafkaPodDescriptor, STACKABLE_CONFIG_DIR, STACKABLE_KERBEROS_KRB5_PATH,
12-
role::{broker::BROKER_PROPERTIES_FILE, controller::CONTROLLER_PROPERTIES_FILE},
13-
security::KafkaTlsSecurity,
14-
},
15-
product_logging::{BROKER_ID_POD_MAP_DIR, STACKABLE_LOG_DIR},
9+
use crate::crd::{
10+
BROKER_ID_POD_MAP_DIR, KafkaPodDescriptor, LOG4J_CONFIG_FILE, LOG4J2_CONFIG_FILE,
11+
STACKABLE_CONFIG_DIR, STACKABLE_KERBEROS_KRB5_PATH, STACKABLE_LOG_CONFIG_DIR,
12+
STACKABLE_LOG_DIR,
13+
role::{broker::BROKER_PROPERTIES_FILE, controller::CONTROLLER_PROPERTIES_FILE},
14+
security::KafkaTlsSecurity,
1615
};
1716

17+
/// The JVM options selecting the Kafka log4j/log4j2 config file. Kafka 3.x uses log4j,
18+
/// Kafka 4.0 and higher use log4j2.
19+
pub fn kafka_log_opts(product_version: &str) -> String {
20+
if product_version.starts_with("3.") {
21+
format!("-Dlog4j.configuration=file:{STACKABLE_LOG_CONFIG_DIR}/{LOG4J_CONFIG_FILE}")
22+
} else {
23+
format!("-Dlog4j2.configurationFile=file:{STACKABLE_LOG_CONFIG_DIR}/{LOG4J2_CONFIG_FILE}")
24+
}
25+
}
26+
27+
/// The env var carrying the Kafka log4j options (see [`kafka_log_opts`]).
28+
pub fn kafka_log_opts_env_var() -> String {
29+
"KAFKA_LOG4J_OPTS".to_string()
30+
}
31+
1832
/// Returns the commands to start the main Kafka container
1933
pub fn broker_kafka_container_commands(
2034
kraft_mode: bool,

rust/operator-binary/src/controller.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use stackable_operator::{
1515
core::{DeserializeGuard, error_boundary},
1616
runtime::{controller::Action, reflector::ObjectRef},
1717
},
18+
kvp::ObjectLabels,
1819
logging::controller::ReconcilerError,
20+
memory::{BinaryMultiple, MemoryQuantity},
1921
role_utils::{GenericRoleConfig, RoleGroupRef},
2022
shared::time::Duration,
2123
status::condition::{
@@ -53,6 +55,34 @@ use crate::{
5355
pub const KAFKA_CONTROLLER_NAME: &str = "kafkacluster";
5456
pub const KAFKA_FULL_CONTROLLER_NAME: &str = concatcp!(KAFKA_CONTROLLER_NAME, '.', OPERATOR_NAME);
5557

58+
/// The maximum size of a single Kafka log file before it is rotated.
59+
pub const MAX_KAFKA_LOG_FILES_SIZE: MemoryQuantity = MemoryQuantity {
60+
value: 10.0,
61+
unit: BinaryMultiple::Mebi,
62+
};
63+
64+
/// Build recommended values for labels.
65+
///
66+
/// Generic over the owner `T` so the owner can be either the raw `KafkaCluster` or the
67+
/// [`ValidatedCluster`] (which also implements `Resource`).
68+
pub fn build_recommended_labels<'a, T>(
69+
owner: &'a T,
70+
controller_name: &'a str,
71+
app_version: &'a str,
72+
role: &'a str,
73+
role_group: &'a str,
74+
) -> ObjectLabels<'a, T> {
75+
ObjectLabels {
76+
owner,
77+
app_name: APP_NAME,
78+
app_version,
79+
operator_name: OPERATOR_NAME,
80+
controller_name,
81+
role,
82+
role_group,
83+
}
84+
}
85+
5686
pub struct Ctx {
5787
pub client: stackable_operator::client::Client,
5888
pub operator_environment: OperatorEnvironmentOptions,

rust/operator-binary/src/controller/build/config_map.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ use stackable_operator::{
88
};
99

1010
use crate::{
11-
controller::{KAFKA_CONTROLLER_NAME, ValidatedCluster, ValidatedRoleGroupConfig},
11+
controller::{
12+
KAFKA_CONTROLLER_NAME, ValidatedCluster, ValidatedRoleGroupConfig,
13+
build::properties::logging::role_group_config_map_data, build_recommended_labels,
14+
},
1215
crd::{
1316
JVM_SECURITY_PROPERTIES_FILE, MetadataManager, STACKABLE_LISTENER_BOOTSTRAP_DIR,
1417
STACKABLE_LISTENER_BROKER_DIR,
1518
listener::{KafkaListenerConfig, node_address_cmd},
1619
role::AnyConfig,
1720
v1alpha1,
1821
},
19-
product_logging::role_group_config_map_data,
20-
utils::build_recommended_labels,
2122
};
2223

2324
#[derive(Snafu, Debug)]

rust/operator-binary/src/controller/build/discovery.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ use stackable_operator::{
99
};
1010

1111
use crate::{
12-
controller::{KAFKA_CONTROLLER_NAME, ValidatedCluster},
12+
controller::{KAFKA_CONTROLLER_NAME, ValidatedCluster, build_recommended_labels},
1313
crd::{role::KafkaRole, v1alpha1},
14-
utils::build_recommended_labels,
1514
};
1615

1716
#[derive(Snafu, Debug)]

rust/operator-binary/src/product_logging.rs renamed to rust/operator-binary/src/controller/build/properties/logging.rs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Renders the logging config files (`log4j.properties` / `log4j2.properties` and the
2+
//! Vector agent config) assembled into the rolegroup `ConfigMap`.
3+
14
use std::{borrow::Cow, collections::BTreeMap, fmt::Display};
25

36
use stackable_operator::{
@@ -9,41 +12,21 @@ use stackable_operator::{
912
role_utils::RoleGroupRef,
1013
};
1114

12-
use crate::crd::{
13-
role::{AnyConfig, broker::BrokerContainer, controller::ControllerContainer},
14-
v1alpha1,
15+
use crate::{
16+
controller::MAX_KAFKA_LOG_FILES_SIZE,
17+
crd::{
18+
LOG4J_CONFIG_FILE, LOG4J2_CONFIG_FILE, STACKABLE_LOG_DIR,
19+
role::{AnyConfig, broker::BrokerContainer, controller::ControllerContainer},
20+
v1alpha1,
21+
},
1522
};
1623

17-
pub const BROKER_ID_POD_MAP_DIR: &str = "/stackable/broker-id-pod-map";
18-
pub const STACKABLE_LOG_CONFIG_DIR: &str = "/stackable/log_config";
19-
pub const STACKABLE_LOG_DIR: &str = "/stackable/log";
20-
// log4j
21-
const LOG4J_CONFIG_FILE: &str = "log4j.properties";
2224
const KAFKA_LOG4J_FILE: &str = "kafka.log4j.xml";
23-
// log4j2
24-
const LOG4J2_CONFIG_FILE: &str = "log4j2.properties";
2525
const KAFKA_LOG4J2_FILE: &str = "kafka.log4j2.xml";
26-
// max size
27-
pub const MAX_KAFKA_LOG_FILES_SIZE: MemoryQuantity = MemoryQuantity {
28-
value: 10.0,
29-
unit: BinaryMultiple::Mebi,
30-
};
3126

3227
const CONSOLE_CONVERSION_PATTERN_LOG4J: &str = "[%d] %p %m (%c)%n";
3328
const CONSOLE_CONVERSION_PATTERN_LOG4J2: &str = "%d{ISO8601} %p [%t] %c - %m%n";
3429

35-
pub fn kafka_log_opts(product_version: &str) -> String {
36-
if product_version.starts_with("3.") {
37-
format!("-Dlog4j.configuration=file:{STACKABLE_LOG_CONFIG_DIR}/{LOG4J_CONFIG_FILE}")
38-
} else {
39-
format!("-Dlog4j2.configurationFile=file:{STACKABLE_LOG_CONFIG_DIR}/{LOG4J2_CONFIG_FILE}")
40-
}
41-
}
42-
43-
pub fn kafka_log_opts_env_var() -> String {
44-
"KAFKA_LOG4J_OPTS".to_string()
45-
}
46-
4730
/// Get the role group ConfigMap data with logging and Vector configurations
4831
pub fn role_group_config_map_data(
4932
product_version: &str,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
pub mod broker_properties;
44
pub mod controller_properties;
5+
pub mod logging;
56

67
use crate::crd::{KafkaPodDescriptor, role::KafkaRole};
78

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ pub const STACKABLE_CONFIG_DIR: &str = "/stackable/config";
6060
// kerberos
6161
pub const STACKABLE_KERBEROS_DIR: &str = "/stackable/kerberos";
6262
pub const STACKABLE_KERBEROS_KRB5_PATH: &str = "/stackable/kerberos/krb5.conf";
63+
// logging
64+
pub const STACKABLE_LOG_DIR: &str = "/stackable/log";
65+
pub const STACKABLE_LOG_CONFIG_DIR: &str = "/stackable/log_config";
66+
pub const BROKER_ID_POD_MAP_DIR: &str = "/stackable/broker-id-pod-map";
67+
pub const LOG4J_CONFIG_FILE: &str = "log4j.properties";
68+
pub const LOG4J2_CONFIG_FILE: &str = "log4j2.properties";
6369

6470
#[derive(Snafu, Debug)]
6571
pub enum Error {

rust/operator-binary/src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ mod crd;
4646
mod framework;
4747
mod kerberos;
4848
mod operations;
49-
mod product_logging;
5049
mod resource;
51-
mod utils;
5250
mod webhooks;
5351

5452
mod built_info {

rust/operator-binary/src/resource/listener.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ use stackable_operator::{
44
};
55

66
use crate::{
7-
controller::{KAFKA_CONTROLLER_NAME, ValidatedCluster},
7+
controller::{KAFKA_CONTROLLER_NAME, ValidatedCluster, build_recommended_labels},
88
crd::{role::broker::BrokerConfig, security::KafkaTlsSecurity, v1alpha1},
9-
utils::build_recommended_labels,
109
};
1110

1211
#[derive(Snafu, Debug)]

rust/operator-binary/src/resource/service.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ use stackable_operator::{
88
};
99

1010
use crate::{
11-
controller::{KAFKA_CONTROLLER_NAME, ValidatedCluster},
11+
controller::{KAFKA_CONTROLLER_NAME, ValidatedCluster, build_recommended_labels},
1212
crd::{APP_NAME, METRICS_PORT, METRICS_PORT_NAME, security::KafkaTlsSecurity, v1alpha1},
13-
utils::build_recommended_labels,
1413
};
1514

1615
#[derive(Snafu, Debug)]

0 commit comments

Comments
 (0)