-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathproduct_logging.rs
More file actions
110 lines (98 loc) · 3.56 KB
/
Copy pathproduct_logging.rs
File metadata and controls
110 lines (98 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use snafu::{ResultExt, Snafu};
use stackable_operator::{
builder::configmap::ConfigMapBuilder,
memory::BinaryMultiple,
product_logging::{
self,
spec::{ContainerLogConfig, ContainerLogConfigChoice},
},
role_utils::RoleGroupRef,
};
use crate::crd::{
LOG4J_CONFIG_FILE, LOGBACK_CONFIG_FILE, LoggingFramework, MAX_ZK_LOG_FILES_SIZE,
STACKABLE_LOG_DIR, ZOOKEEPER_LOG_FILE, ZookeeperRole, v1alpha1,
};
#[derive(Snafu, Debug)]
pub enum Error {
#[snafu(display("object has no namespace"))]
ObjectHasNoNamespace,
#[snafu(display("failed to retrieve the ConfigMap {cm_name}"))]
ConfigMapNotFound {
source: stackable_operator::client::Error,
cm_name: String,
},
#[snafu(display("failed to retrieve the entry {entry} for ConfigMap {cm_name}"))]
MissingConfigMapEntry {
entry: &'static str,
cm_name: String,
},
#[snafu(display("crd validation failure"))]
CrdValidationFailure { source: crate::crd::Error },
}
type Result<T, E = Error> = std::result::Result<T, E>;
const CONSOLE_CONVERSION_PATTERN: &str = "%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n";
/// Extend the role group ConfigMap with logging and Vector configurations
pub fn extend_role_group_config_map(
zk: &v1alpha1::ZookeeperCluster,
role: ZookeeperRole,
rolegroup: &RoleGroupRef<v1alpha1::ZookeeperCluster>,
cm_builder: &mut ConfigMapBuilder,
product_version: &str,
) -> Result<()> {
let logging = zk
.logging(&role, rolegroup)
.context(CrdValidationFailureSnafu)?;
if let Some(ContainerLogConfig {
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
}) = logging.containers.get(&v1alpha1::Container::Zookeeper)
{
match zk.logging_framework(product_version) {
LoggingFramework::LOG4J => {
cm_builder.add_data(
LOG4J_CONFIG_FILE,
product_logging::framework::create_log4j_config(
&format!("{STACKABLE_LOG_DIR}/zookeeper"),
ZOOKEEPER_LOG_FILE,
MAX_ZK_LOG_FILES_SIZE
.scale_to(BinaryMultiple::Mebi)
.floor()
.value as u32,
CONSOLE_CONVERSION_PATTERN,
log_config,
),
);
}
LoggingFramework::LOGBACK => {
cm_builder.add_data(
LOGBACK_CONFIG_FILE,
product_logging::framework::create_logback_config(
&format!("{STACKABLE_LOG_DIR}/zookeeper"),
ZOOKEEPER_LOG_FILE,
MAX_ZK_LOG_FILES_SIZE
.scale_to(BinaryMultiple::Mebi)
.floor()
.value as u32,
CONSOLE_CONVERSION_PATTERN,
log_config,
None,
),
);
}
}
}
let vector_log_config = if let Some(ContainerLogConfig {
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
}) = logging.containers.get(&v1alpha1::Container::Vector)
{
Some(log_config)
} else {
None
};
if logging.enable_vector_agent {
cm_builder.add_data(
product_logging::framework::VECTOR_CONFIG_FILE,
product_logging::framework::create_vector_config(rolegroup, vector_log_config),
);
}
Ok(())
}