Skip to content

Commit 24e8859

Browse files
committed
feat(server): implement log rotation based on size and retention
- implemented log rotation based on size and retention as the title; - implemented configurable attributions and imported breaking changes; - added units and integration test in logger.rs and intergration mod; - added documentations and imported new dependencies, etc. Details can be looked up at Apache Iggy #2452
1 parent 4d31047 commit 24e8859

File tree

16 files changed

+1009
-38
lines changed

16 files changed

+1009
-38
lines changed

Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DEPENDENCIES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ foreign-types-shared: 0.1.1, "Apache-2.0 OR MIT",
293293
form_urlencoded: 1.2.2, "Apache-2.0 OR MIT",
294294
fragile: 2.0.1, "Apache-2.0",
295295
fs-err: 3.2.2, "Apache-2.0 OR MIT",
296+
fs2: 0.4.3, "Apache-2.0 OR MIT",
296297
fs_extra: 1.3.0, "MIT",
297298
fsevent-sys: 4.1.0, "MIT",
298299
funty: 2.0.0, "MIT",
@@ -661,6 +662,7 @@ rmcp-macros: 0.14.0, "Apache-2.0",
661662
rmp: 0.8.15, "MIT",
662663
rmp-serde: 1.3.1, "MIT",
663664
roaring: 0.11.3, "Apache-2.0 OR MIT",
665+
rolling-file: 0.2.0, "Apache-2.0 OR MIT",
664666
route-recognizer: 0.3.1, "MIT",
665667
rsa: 0.9.10, "Apache-2.0 OR MIT",
666668
rust-embed: 8.11.0, "MIT",

core/common/src/utils/byte_size.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ impl IggyByteSize {
137137
format!("{:.2}", self.0.get_appropriate_unit(UnitType::Decimal))
138138
}
139139

140+
/// Subtract another IggyByteSize value, return 0 if the result is negative.
141+
pub fn saturating_sub(&self, other: &Self) -> Self {
142+
let self_bytes = self.as_bytes_u64();
143+
let other_bytes = other.as_bytes_u64();
144+
IggyByteSize::new(self_bytes.saturating_sub(other_bytes))
145+
}
146+
140147
/// Calculates the throughput based on the provided duration and returns a human-readable string.
141148
pub(crate) fn _as_human_throughput_string(&self, duration: &IggyDuration) -> String {
142149
if duration.is_zero() {

core/common/src/utils/duration.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,35 @@ use std::{
2929

3030
pub const SEC_IN_MICRO: u64 = 1_000_000;
3131

32+
/// A struct for representing time durations with various utility functions.
33+
///
34+
/// This struct wraps `std::time::Duration` and uses the `humantime` crate for parsing and formatting
35+
/// human-readable duration strings. It also implements serialization and deserialization via the `serde` crate.
36+
///
37+
/// # Example
38+
///
39+
/// ```
40+
/// use iggy_common::IggyDuration;
41+
/// use std::str::FromStr;
42+
///
43+
/// let duration = IggyDuration::from(3661_000_000_u64); // 3661 seconds in microseconds
44+
/// assert_eq!(3661, duration.as_secs());
45+
/// assert_eq!("1h 1m 1s", duration.as_human_time_string());
46+
/// assert_eq!("1h 1m 1s", format!("{}", duration));
47+
///
48+
/// let duration = IggyDuration::from(0_u64);
49+
/// assert_eq!(0, duration.as_secs());
50+
/// assert_eq!("0s", duration.as_human_time_string());
51+
/// assert_eq!("0s", format!("{}", duration));
52+
///
53+
/// let duration = IggyDuration::from_str("1h 1m 1s").unwrap();
54+
/// assert_eq!(3661, duration.as_secs());
55+
/// assert_eq!("1h 1m 1s", duration.as_human_time_string());
56+
/// assert_eq!("1h 1m 1s", format!("{}", duration));
57+
///
58+
/// let duration = IggyDuration::from_str("unlimited").unwrap();
59+
/// assert_eq!(0, duration.as_secs());
60+
/// ```
3261
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
3362
pub struct IggyDuration {
3463
duration: Duration,

core/integration/src/test_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ impl TestServer {
120120
Ok(parallelism) => {
121121
let available_cpus = parallelism.get();
122122
if available_cpus >= 4 {
123-
let mut rng = rand::thread_rng();
123+
let mut rng = rand::rng();
124124
let max_start = available_cpus - 4;
125-
let start = rng.gen_range(0..=max_start);
125+
let start = rng.random_range(0..=max_start);
126126
let end = start + 4;
127127
format!("{}..{}", start, end)
128128
} else {

0 commit comments

Comments
 (0)