Skip to content

Commit c110043

Browse files
committed
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
1 parent 2117416 commit c110043

2 files changed

Lines changed: 354 additions & 9 deletions

File tree

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)