2
2
3
3
use std:: cmp;
4
4
5
- use k8s_openapi:: api:: core:: v1:: ResourceRequirements ;
6
-
7
5
use crate :: {
8
- builder:: ContainerBuilder , commons:: product_image_selection:: ResolvedProductImage ,
9
- k8s_openapi:: api:: core:: v1:: Container , kube:: Resource , role_utils:: RoleGroupRef ,
6
+ builder:: ContainerBuilder ,
7
+ commons:: product_image_selection:: ResolvedProductImage ,
8
+ k8s_openapi:: {
9
+ api:: core:: v1:: { Container , ResourceRequirements } ,
10
+ apimachinery:: pkg:: api:: resource:: Quantity ,
11
+ } ,
12
+ kube:: Resource ,
13
+ role_utils:: RoleGroupRef ,
10
14
} ;
11
15
12
16
use super :: spec:: {
@@ -26,6 +30,50 @@ const SHUTDOWN_FILE: &str = "shutdown";
26
30
/// File name of the Vector config file
27
31
pub const VECTOR_CONFIG_FILE : & str = "vector.toml" ;
28
32
33
+ /// Calculate the size limit for the log volume.
34
+ ///
35
+ /// The size limit must be much larger than the sum of the given maximum log file sizes for the
36
+ /// following reasons:
37
+ /// - The log file rollover occurs when the log file exceeds the maximum log file size. Depending
38
+ /// on the size of the last log entries, the file can be several kilobytes larger than defined.
39
+ /// - The actual disk usage depends on the block size of the file system.
40
+ /// - OpenShift sometimes reserves more than twice the amount of blocks than needed. For instance,
41
+ /// a ZooKeeper log file with 4,127,151 bytes occupied 4,032 blocks. Then log entries were written
42
+ /// and the actual file size increased to 4,132,477 bytes which occupied 8,128 blocks.
43
+ ///
44
+ /// # Example
45
+ ///
46
+ /// ```
47
+ /// use stackable_operator::{
48
+ /// builder::{
49
+ /// PodBuilder,
50
+ /// meta::ObjectMetaBuilder,
51
+ /// },
52
+ /// };
53
+ /// # use stackable_operator::product_logging::framework::calculate_log_volume_size_limit;
54
+ ///
55
+ /// pub const MAX_INIT_CONTAINER_LOG_FILES_SIZE_IN_MIB: u32 = 1;
56
+ /// pub const MAX_MAIN_CONTAINER_LOG_FILES_SIZE_IN_MIB: u32 = 10;
57
+ ///
58
+ /// PodBuilder::new()
59
+ /// .metadata(ObjectMetaBuilder::default().build())
60
+ /// .add_empty_dir_volume(
61
+ /// "log",
62
+ /// Some(product_logging::framework::calculate_log_volume_size_limit(
63
+ /// &[
64
+ /// MAX_INIT_CONTAINER_LOG_FILES_SIZE_IN_MIB,
65
+ /// MAX_MAIN_CONTAINER_LOG_FILES_SIZE_IN_MIB,
66
+ /// ],
67
+ /// )),
68
+ /// )
69
+ /// .build()
70
+ /// .unwrap();
71
+ /// ```
72
+ pub fn calculate_log_volume_size_limit ( max_log_files_size_in_mib : & [ u32 ] ) -> Quantity {
73
+ let log_volume_size_limit_in_mib = max_log_files_size_in_mib. iter ( ) . sum :: < u32 > ( ) * 3 ;
74
+ Quantity ( format ! ( "{log_volume_size_limit_in_mib}Mi" ) )
75
+ }
76
+
29
77
/// Create a Bash command which filters stdout and stderr according to the given log configuration
30
78
/// and additionally stores the output in log files
31
79
///
0 commit comments