Skip to content

Commit 73d02ef

Browse files
Add function for calculating the size limit of log volumes
1 parent 5d2ca16 commit 73d02ef

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- Add a function for calculating the size limit of log volumes ([#621]).
10+
11+
[#621]: https://github.com/stackabletech/operator-rs/pull/621
12+
713
## [0.43.0] - 2023-07-06
814

915
### Added

src/product_logging/framework.rs

+52-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
33
use std::cmp;
44

5-
use k8s_openapi::api::core::v1::ResourceRequirements;
6-
75
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,
1014
};
1115

1216
use super::spec::{
@@ -26,6 +30,50 @@ const SHUTDOWN_FILE: &str = "shutdown";
2630
/// File name of the Vector config file
2731
pub const VECTOR_CONFIG_FILE: &str = "vector.toml";
2832

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+
2977
/// Create a Bash command which filters stdout and stderr according to the given log configuration
3078
/// and additionally stores the output in log files
3179
///

0 commit comments

Comments
 (0)