Skip to content

Commit 8076d51

Browse files
committed
fix: use product_logging mod
1 parent fa148a6 commit 8076d51

3 files changed

Lines changed: 64 additions & 43 deletions

File tree

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

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,22 @@ use stackable_operator::{
4040
kvp::Labels,
4141
product_logging::{
4242
self,
43-
framework::{
44-
LoggingError, create_vector_shutdown_file_command, remove_vector_shutdown_file_command,
45-
},
43+
framework::{create_vector_shutdown_file_command, remove_vector_shutdown_file_command},
4644
spec::{
4745
AutomaticContainerLogConfig, ConfigMapLogConfig, ContainerLogConfig,
4846
ContainerLogConfigChoice, CustomContainerLogConfig,
4947
},
5048
},
5149
utils::{COMMON_BASH_TRAP_FUNCTIONS, cluster_info::KubernetesClusterInfo},
5250
v2::{
53-
builder::pod::container::new_container_builder,
51+
builder::pod::container::{EnvVarSet, new_container_builder},
52+
product_logging::framework::{
53+
STACKABLE_LOG_DIR, ValidatedContainerLogConfigChoice, VectorContainerLogConfig,
54+
vector_container,
55+
},
5456
types::{
5557
common::Port,
56-
kubernetes::{ContainerName, VolumeName},
58+
kubernetes::{ConfigMapName, ContainerName, VolumeName},
5759
operator::RoleGroupName,
5860
},
5961
},
@@ -67,11 +69,11 @@ use crate::{
6769
self,
6870
jvm::{self, construct_global_jvm_args, construct_role_specific_jvm_args},
6971
kerberos::KERBEROS_CONTAINER_PATH,
70-
properties::logging::{
72+
properties::product_logging::{
7173
FORMAT_NAMENODES_LOG4J_CONFIG_FILE, FORMAT_ZOOKEEPER_LOG4J_CONFIG_FILE,
7274
HDFS_LOG4J_CONFIG_FILE, MAX_FORMAT_NAMENODE_LOG_FILE_SIZE,
7375
MAX_FORMAT_ZOOKEEPER_LOG_FILE_SIZE, MAX_HDFS_LOG_FILE_SIZE,
74-
MAX_WAIT_NAMENODES_LOG_FILE_SIZE, MAX_ZKFC_LOG_FILE_SIZE, STACKABLE_LOG_DIR,
76+
MAX_WAIT_NAMENODES_LOG_FILE_SIZE, MAX_ZKFC_LOG_FILE_SIZE,
7577
WAIT_FOR_NAMENODES_LOG4J_CONFIG_FILE, ZKFC_LOG4J_CONFIG_FILE,
7678
},
7779
},
@@ -98,6 +100,12 @@ constant!(pub(crate) TLS_STORE_VOLUME_NAME: VolumeName = "tls");
98100
pub(crate) const TLS_STORE_PASSWORD: &str = "changeit";
99101
constant!(pub(crate) KERBEROS_VOLUME_NAME: VolumeName = "kerberos");
100102

103+
constant!(VECTOR_CONTAINER_NAME: ContainerName = "vector");
104+
// The volume the rolegroup ConfigMap (including the static `vector.yaml`) is mounted into.
105+
constant!(VECTOR_CONFIG_VOLUME_NAME: VolumeName = "hdfs-config");
106+
// The volume holding the product logs that Vector tails.
107+
constant!(VECTOR_LOG_VOLUME_NAME: VolumeName = "log");
108+
101109
type Result<T, E = Error> = std::result::Result<T, E>;
102110

103111
#[derive(Snafu, Debug, EnumDiscriminants)]
@@ -128,9 +136,6 @@ pub enum Error {
128136
source: ListenerOperatorVolumeSourceBuilderError,
129137
},
130138

131-
#[snafu(display("failed to configure logging"))]
132-
ConfigureLogging { source: LoggingError },
133-
134139
#[snafu(display("failed to add needed volume"))]
135140
AddVolume { source: builder::pod::Error },
136141

@@ -141,6 +146,11 @@ pub enum Error {
141146

142147
#[snafu(display("vector agent is enabled but vector aggregator ConfigMap is missing"))]
143148
VectorAggregatorConfigMapMissing,
149+
150+
#[snafu(display("invalid Vector log config ConfigMap name"))]
151+
ParseVectorLogConfigMapName {
152+
source: stackable_operator::v2::macros::attributed_string_type::Error,
153+
},
144154
}
145155

146156
/// ContainerConfig contains information to create all main, side and init containers for
@@ -233,35 +243,45 @@ impl ContainerConfig {
233243
labels,
234244
)?);
235245

236-
// Vector side container
246+
// Vector sidecar container.
237247
if merged_config.vector_logging_enabled() {
238-
match &cluster
248+
let vector_aggregator_config_map_name = cluster
239249
.cluster_config
240250
.logging
241251
.vector_aggregator_config_map_name
242-
{
243-
Some(vector_aggregator_config_map_name) => {
244-
pb.add_container(
245-
product_logging::framework::vector_container(
246-
&cluster.image,
247-
ContainerConfig::HDFS_CONFIG_VOLUME_MOUNT_NAME,
248-
ContainerConfig::STACKABLE_LOG_VOLUME_MOUNT_NAME,
249-
Some(&merged_config.vector_logging()),
250-
ResourceRequirementsBuilder::new()
251-
.with_cpu_request("250m")
252-
.with_cpu_limit("500m")
253-
.with_memory_request("128Mi")
254-
.with_memory_limit("128Mi")
255-
.build(),
256-
vector_aggregator_config_map_name.as_ref(),
257-
)
258-
.context(ConfigureLoggingSnafu)?,
259-
);
260-
}
261-
None => {
262-
VectorAggregatorConfigMapMissingSnafu.fail()?;
263-
}
264-
}
252+
.clone()
253+
.context(VectorAggregatorConfigMapMissingSnafu)?;
254+
255+
let log_config = match &*merged_config.vector_logging() {
256+
ContainerLogConfig {
257+
choice:
258+
Some(ContainerLogConfigChoice::Custom(CustomContainerLogConfig {
259+
custom: ConfigMapLogConfig { config_map },
260+
})),
261+
} => ValidatedContainerLogConfigChoice::Custom(
262+
ConfigMapName::from_str(config_map)
263+
.context(ParseVectorLogConfigMapNameSnafu)?,
264+
),
265+
ContainerLogConfig {
266+
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
267+
} => ValidatedContainerLogConfigChoice::Automatic(log_config.clone()),
268+
_ => ValidatedContainerLogConfigChoice::Automatic(
269+
AutomaticContainerLogConfig::default(),
270+
),
271+
};
272+
273+
pb.add_container(vector_container(
274+
&VECTOR_CONTAINER_NAME,
275+
&cluster.image,
276+
&VectorContainerLogConfig {
277+
log_config,
278+
vector_aggregator_config_map_name,
279+
},
280+
&cluster.resource_names(role, role_group_name),
281+
&VECTOR_CONFIG_VOLUME_NAME,
282+
&VECTOR_LOG_VOLUME_NAME,
283+
EnvVarSet::new(),
284+
));
265285
}
266286

267287
if let Some(authentication_config) = cluster.authentication_config() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::controller::build::container::{TLS_STORE_DIR, TLS_STORE_PASSWORD};
88
pub mod core_site;
99
pub mod hadoop_policy;
1010
pub mod hdfs_site;
11-
pub mod logging;
11+
pub mod product_logging;
1212
pub mod security_properties;
1313
pub mod ssl_client;
1414
pub mod ssl_server;

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use crate::{
1515
build::{
1616
self,
1717
properties::{
18-
ConfigFileName, core_site, hadoop_policy, hdfs_site, logging, security_properties,
19-
ssl_client, ssl_server,
18+
ConfigFileName, core_site, hadoop_policy, hdfs_site, product_logging,
19+
security_properties, ssl_client, ssl_server,
2020
},
2121
},
2222
},
@@ -105,13 +105,14 @@ pub fn build_rolegroup_config_map(
105105
)?,
106106
);
107107

108-
for (log_config_file, log4j_config) in logging::build_log4j_configs(merged_config) {
108+
for (log_config_file, log4j_config) in product_logging::build_log4j_configs(merged_config) {
109109
builder.add_data(log_config_file, log4j_config);
110110
}
111-
if let Some(vector_config) =
112-
logging::build_vector_config(cluster, role, role_group_name, merged_config)
113-
{
114-
builder.add_data(VECTOR_CONFIG_FILE, vector_config);
111+
if merged_config.vector_logging_enabled() {
112+
builder.add_data(
113+
VECTOR_CONFIG_FILE,
114+
product_logging::vector_config_file_content(),
115+
);
115116
}
116117

117118
builder.build().with_context(|_| AssembleSnafu {

0 commit comments

Comments
 (0)