-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathproduct_logging.rs
More file actions
77 lines (70 loc) · 2.17 KB
/
product_logging.rs
File metadata and controls
77 lines (70 loc) · 2.17 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
use snafu::Snafu;
use stackable_opa_operator::crd::v1alpha1;
use stackable_operator::{
builder::configmap::ConfigMapBuilder,
product_logging::{
self,
spec::{ContainerLogConfig, ContainerLogConfigChoice, LogLevel, Logging},
},
role_utils::RoleGroupRef,
};
#[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("vectorAggregatorConfigMapName must be set"))]
MissingVectorAggregatorAddress,
}
type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(strum::Display)]
#[strum(serialize_all = "UPPERCASE")]
pub enum BundleBuilderLogLevel {
Trace,
Debug,
Info,
Warn,
Error,
}
impl From<LogLevel> for BundleBuilderLogLevel {
fn from(level: LogLevel) -> Self {
match level {
LogLevel::TRACE => Self::Trace,
LogLevel::DEBUG => Self::Debug,
LogLevel::INFO => Self::Info,
LogLevel::WARN => Self::Warn,
LogLevel::ERROR | LogLevel::FATAL | LogLevel::NONE => Self::Error,
}
}
}
/// Extend the role group ConfigMap with logging and Vector configurations
pub fn extend_role_group_config_map(
rolegroup: &RoleGroupRef<v1alpha1::OpaCluster>,
logging: &Logging<v1alpha1::Container>,
cm_builder: &mut ConfigMapBuilder,
) -> Result<()> {
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(())
}