Skip to content

Commit d002aeb

Browse files
authored
feat: add time-based rotation to RotatingWriter (#136) (#179)
* feat: add time-based rotation to RotatingWriter (#136) RotatingWriter now rotates segments based on wall-clock time in addition to file size. Rotation triggers when *either* condition is met: - File exceeds `max_file_size` bytes (existing behavior) - A wall-clock-aligned time boundary is crossed (new) The default rotation period is 60 seconds, aligned to round minute boundaries (e.g. if the writer starts at 14:03:22, the first rotation fires at 14:04:00). This is configurable via the builder: RotatingWriter::builder() .rotation_period(Duration::from_secs(300)) // every 5 min Time-aligned segments produce clean S3 key paths when using the `worker-s3` feature (keys already use `{YYYY-MM-DD}/{HHMM}` bucketing). Edge cases: - Time rotation is skipped when no real events have been written (avoids empty sealed segments) - `single_file()` disables time rotation (Duration::MAX) - Eviction budget is respected with frequent time rotations Closes #136 * feat: add time-based rotation to RotatingWriter (#136) RotatingWriter now rotates segments based on wall-clock time in addition to file size. Rotation triggers when *either* condition is met: - File exceeds `max_file_size` bytes (existing behavior) - A wall-clock-aligned time boundary is crossed (new) The default rotation period is 60 seconds, aligned to round minute boundaries (e.g. if the writer starts at 14:03:22, the first rotation fires at 14:04:00). This is configurable via the builder: RotatingWriter::builder() .rotation_period(Duration::from_secs(300)) // every 5 min Time-aligned segments produce clean S3 key paths when using the `worker-s3` feature (keys already use `{YYYY-MM-DD}/{HHMM}` bucketing). Edge cases: - Time rotation is skipped when no real events have been written (avoids empty sealed segments) - `single_file()` disables time rotation (Duration::MAX) - Eviction budget is respected with frequent time rotations Closes #136 * PR feedback
1 parent 03212e0 commit d002aeb

4 files changed

Lines changed: 375 additions & 11 deletions

File tree

Cargo.lock

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

dial9-tokio-telemetry/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ flate2 = { version = "1" }
3838
time = { version = "0.3", features = ["formatting", "macros"], optional = true }
3939
metrique-writer = "0.1"
4040
metrique = { version = "0.1.23", features = ["local-format"] }
41+
metrique-timesource = "0.1"
4142

4243
[features]
4344
analysis = []
@@ -50,7 +51,9 @@ assert2 = { workspace = true }
5051
criterion = "0.5"
5152
clap = { version = "4", features = ["derive"] }
5253
hdrhistogram = "7"
54+
metrique-timesource = { version = "0.1", features = ["custom-timesource", "tokio"] }
5355
metrique-writer = { version = "0.1", features = ["test-util"] }
56+
tokio = { version = "1.51.0", features = ["test-util"] }
5457
proptest = "1"
5558
tempfile = "3"
5659
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

dial9-tokio-telemetry/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ fn main() -> std::io::Result<()> {
3232
.base_path("/tmp/my_traces/trace.bin")
3333
.max_file_size(1024 * 1024) // rotate after 1 MiB per file
3434
.max_total_size(5 * 1024 * 1024) // keep at most 5 MiB on disk
35+
// .rotation_period(std::time::Duration::from_secs(300)) // optional: rotate every 5 min (default: 60 s)
3536
.build()?;
3637

3738
let mut builder = tokio::runtime::Builder::new_multi_thread();
@@ -49,6 +50,8 @@ fn main() -> std::io::Result<()> {
4950

5051
Events are 6–16 bytes on the wire, and a typical request generates ~20–35 bytes of trace data (a few poll events plus park/unpark). At 10k requests/sec that's well under 1 MB/s — `RotatingWriter` caps total disk usage so you can leave it running indefinitely. Typical CPU overhead is under 5%.
5152

53+
Segments rotate on size *or* time, whichever comes first. Time boundaries are wall-clock-aligned (e.g. a 60 s period rotates at the top of each minute), which produces clean S3 key paths when using the `worker-s3` feature.
54+
5255
## Can I use this in prod?
5356
dial9-tokio-telemetry is designed for always-on production use, but it's still early software. Measure overhead and validate behavior in your environment before deploying to production.
5457

@@ -202,7 +205,7 @@ handle.disable();
202205

203206
### Writers
204207

205-
`RotatingWriter` rotates files and evicts old ones to stay within a total size budget. For quick experiments, `RotatingWriter::single_file(path)` writes a single file with no rotation.
208+
`RotatingWriter` rotates files based on size and time, and evicts old ones to stay within a total size budget. By default, segments rotate every 60 seconds (wall-clock-aligned) or when they exceed `max_file_size`, whichever comes first. For quick experiments, `RotatingWriter::single_file(path)` writes a single file with no rotation.
206209

207210
### Analyzing traces
208211

0 commit comments

Comments
 (0)