Skip to content

Commit f699559

Browse files
committed
refactor: consolidate logging to build step
1 parent 0fe526b commit f699559

2 files changed

Lines changed: 41 additions & 30 deletions

File tree

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use snafu::{OptionExt, ResultExt, Snafu};
44
use stackable_operator::{
55
builder::{configmap::ConfigMapBuilder, meta::ObjectMetaBuilder},
66
k8s_openapi::api::core::v1::ConfigMap,
7+
product_logging::framework::VECTOR_CONFIG_FILE,
78
role_utils::RoleGroupRef,
89
};
910

1011
use crate::{
1112
config::writer::PropertiesWriterError,
1213
controller::build::properties::{
13-
ConfigFileName, hbase_env, hbase_site, logging::extend_role_group_config_map,
14-
security_properties, ssl_client, ssl_server,
14+
ConfigFileName, hbase_env, hbase_site, logging, security_properties, ssl_client, ssl_server,
1515
},
1616
crd::{HbaseRole, v1alpha1},
1717
hbase_controller::{ValidatedCluster, build_recommended_labels},
@@ -139,7 +139,14 @@ pub fn build_rolegroup_config_map(
139139
builder.add_data(ConfigFileName::SslClient.to_string(), ssl_client_xml);
140140
}
141141

142-
extend_role_group_config_map(rolegroup_ref, rg.merged_config.logging(), &mut builder);
142+
if let Some(log4j2_properties) = logging::build_log4j2(rg.merged_config.logging()) {
143+
builder.add_data(ConfigFileName::Log4j2.to_string(), log4j2_properties);
144+
}
145+
if let Some(vector_config) =
146+
logging::build_vector_config(rolegroup_ref, rg.merged_config.logging())
147+
{
148+
builder.add_data(VECTOR_CONFIG_FILE, vector_config);
149+
}
143150

144151
builder.build().with_context(|_| AssembleSnafu {
145152
role: rolegroup_ref.role.clone(),

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

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use stackable_operator::{
2-
builder::configmap::ConfigMapBuilder,
32
memory::{BinaryMultiple, MemoryQuantity},
43
product_logging::{
54
self,
@@ -10,10 +9,7 @@ use stackable_operator::{
109
role_utils::RoleGroupRef,
1110
};
1211

13-
use crate::{
14-
controller::build::properties::ConfigFileName,
15-
crd::{Container, v1alpha1},
16-
};
12+
use crate::crd::{Container, v1alpha1};
1713

1814
pub const STACKABLE_LOG_DIR: &str = "/stackable/log";
1915
pub const MAX_HBASE_LOG_FILES_SIZE: MemoryQuantity = MemoryQuantity {
@@ -24,34 +20,42 @@ pub const MAX_HBASE_LOG_FILES_SIZE: MemoryQuantity = MemoryQuantity {
2420
const CONSOLE_CONVERSION_PATTERN: &str = "%d{ISO8601} %-5p [%t] %c{2}: %.1000m%n";
2521
const HBASE_LOG4J2_FILE: &str = "hbase.log4j2.xml";
2622

27-
/// Extend the role group ConfigMap with logging and Vector configurations
28-
pub fn extend_role_group_config_map(
23+
/// Renders `log4j2.properties` for the HBase container.
24+
///
25+
/// Returns `None` when the HBase container does not use the operator's automatic logging
26+
/// configuration (e.g. a custom log ConfigMap is referenced instead), in which case no
27+
/// `log4j2.properties` should be added to the rolegroup `ConfigMap`.
28+
pub fn build_log4j2(logging: &Logging<Container>) -> Option<String> {
29+
match logging.containers.get(&Container::Hbase) {
30+
Some(ContainerLogConfig {
31+
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
32+
}) => Some(log4j_config(log_config)),
33+
_ => None,
34+
}
35+
}
36+
37+
/// Renders the Vector agent config (`vector.yaml`).
38+
///
39+
/// Returns `None` when the Vector agent is disabled for this role group.
40+
pub fn build_vector_config(
2941
rolegroup: &RoleGroupRef<v1alpha1::HbaseCluster>,
3042
logging: &Logging<Container>,
31-
cm_builder: &mut ConfigMapBuilder,
32-
) {
33-
if let Some(ContainerLogConfig {
34-
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
35-
}) = logging.containers.get(&Container::Hbase)
36-
{
37-
cm_builder.add_data(ConfigFileName::Log4j2.to_string(), log4j_config(log_config));
43+
) -> Option<String> {
44+
if !logging.enable_vector_agent {
45+
return None;
3846
}
3947

40-
let vector_log_config = if let Some(ContainerLogConfig {
41-
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
42-
}) = logging.containers.get(&Container::Vector)
43-
{
44-
Some(log_config)
45-
} else {
46-
None
48+
let vector_log_config = match logging.containers.get(&Container::Vector) {
49+
Some(ContainerLogConfig {
50+
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
51+
}) => Some(log_config),
52+
_ => None,
4753
};
4854

49-
if logging.enable_vector_agent {
50-
cm_builder.add_data(
51-
product_logging::framework::VECTOR_CONFIG_FILE,
52-
product_logging::framework::create_vector_config(rolegroup, vector_log_config),
53-
);
54-
}
55+
Some(product_logging::framework::create_vector_config(
56+
rolegroup,
57+
vector_log_config,
58+
))
5559
}
5660

5761
fn log4j_config(log_config: &AutomaticContainerLogConfig) -> String {

0 commit comments

Comments
 (0)