Skip to content

Commit 4192248

Browse files
committed
adapt custom logging to resolve RemoteLogIO handler
1 parent 1133eb3 commit 4192248

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

rust/operator-binary/src/airflow_controller.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ fn build_rolegroup_config_map(
806806
container,
807807
&Container::Vector,
808808
&mut cm_builder,
809+
resolved_product_image,
809810
)
810811
.context(InvalidLoggingConfigSnafu {
811812
cm_name: rolegroup.object_name(),

rust/operator-binary/src/product_logging.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fmt::{Display, Write};
33
use snafu::Snafu;
44
use stackable_operator::{
55
builder::configmap::ConfigMapBuilder,
6+
commons::product_image_selection::ResolvedProductImage,
67
kube::Resource,
78
product_logging::{
89
self,
@@ -43,6 +44,7 @@ pub fn extend_config_map_with_log_config<C, K>(
4344
main_container: &C,
4445
vector_container: &C,
4546
cm_builder: &mut ConfigMapBuilder,
47+
resolved_product_image: &ResolvedProductImage,
4648
) -> Result<()>
4749
where
4850
C: Clone + Ord + Display,
@@ -53,7 +55,10 @@ where
5355
}) = logging.containers.get(main_container)
5456
{
5557
let log_dir = format!("{STACKABLE_LOG_DIR}/{main_container}");
56-
cm_builder.add_data(LOG_CONFIG_FILE, create_airflow_config(log_config, &log_dir));
58+
cm_builder.add_data(
59+
LOG_CONFIG_FILE,
60+
create_airflow_config(log_config, &log_dir, resolved_product_image),
61+
);
5762
}
5863

5964
let vector_log_config = if let Some(ContainerLogConfig {
@@ -75,7 +80,11 @@ where
7580
Ok(())
7681
}
7782

78-
fn create_airflow_config(log_config: &AutomaticContainerLogConfig, log_dir: &str) -> String {
83+
fn create_airflow_config(
84+
log_config: &AutomaticContainerLogConfig,
85+
log_dir: &str,
86+
resolved_product_image: &ResolvedProductImage,
87+
) -> String {
7988
let loggers_config = log_config
8089
.loggers
8190
.iter()
@@ -92,18 +101,28 @@ LOGGING_CONFIG['loggers']['{name}']['level'] = {level}
92101
output
93102
});
94103

104+
let remote_task_log = if resolved_product_image.product_version.starts_with("3") {
105+
"
106+
# This will cause the relevant RemoteLogIO handler to be initialized
107+
REMOTE_TASK_LOG = airflow_local_settings.REMOTE_TASK_LOG
108+
log = logging.getLogger(__name__)
109+
log.info('Custom logging remote task log %s', REMOTE_TASK_LOG)
110+
"
111+
} else {
112+
""
113+
};
114+
95115
format!(
96116
"\
97117
import logging
98118
import os
99119
from copy import deepcopy
100-
from airflow.config_templates.airflow_local_settings import DEFAULT_LOGGING_CONFIG
120+
from airflow.config_templates import airflow_local_settings
101121
102122
os.makedirs('{log_dir}', exist_ok=True)
103123
104-
LOGGING_CONFIG = deepcopy(DEFAULT_LOGGING_CONFIG)
105-
106-
REMOTE_TASK_LOG = None
124+
LOGGING_CONFIG = deepcopy(airflow_local_settings.DEFAULT_LOGGING_CONFIG)
125+
{remote_task_log}
107126
108127
LOGGING_CONFIG.setdefault('loggers', {{}})
109128
for logger_name, logger_config in LOGGING_CONFIG['loggers'].items():

0 commit comments

Comments
 (0)