Skip to content

Commit 78c5594

Browse files
committed
static-timestamped
1 parent 8071239 commit 78c5594

6 files changed

Lines changed: 568 additions & 0 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.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ byte-unit = { version = "5.1", default-features = false, features = [
2222
"byte",
2323
"serde",
2424
] }
25+
chrono = "0.4.42"
2526
sha2 = { version = "0.10", default-features = false }
2627
metrics = { version = "0.24" }
2728
metrics-util = "0.20"

lading_payload/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ description = "A tool for load testing daemons."
1515
[dependencies]
1616
bytes = { workspace = true }
1717
byte-unit = { workspace = true }
18+
chrono = { workspace = true }
1819
opentelemetry-proto = { workspace = true }
1920
prost = { workspace = true }
2021
rand = { workspace = true, features = ["small_rng", "std", "std_rng"] }
@@ -32,6 +33,7 @@ arbitrary = { version = "1", optional = true, features = ["derive"] }
3233
proptest = { workspace = true }
3334
proptest-derive = { workspace = true }
3435
criterion = { version = "0.8", features = ["html_reports"] }
36+
tempfile = { workspace = true }
3537

3638
[features]
3739
default = []

lading_payload/src/block.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ pub enum Error {
6161
/// `StaticChunks` payload creation error
6262
#[error(transparent)]
6363
StaticChunks(#[from] crate::static_chunks::Error),
64+
/// Static timestamp-grouped payload creation error
65+
#[error(transparent)]
66+
StaticTimestamped(#[from] crate::static_timestamped::Error),
6467
/// Error for crate deserialization
6568
#[error("Deserialization error: {0}")]
6669
Deserialize(#[from] crate::Error),
@@ -354,6 +357,27 @@ impl Cache {
354357
total_bytes.get(),
355358
)?
356359
}
360+
crate::Config::StaticTimestamped {
361+
static_path,
362+
timestamp_format,
363+
emit_placeholder,
364+
start_line_index,
365+
} => {
366+
let span = span!(Level::INFO, "fixed", payload = "static-second");
367+
let _guard = span.enter();
368+
let mut serializer = crate::StaticTimestamped::new(
369+
static_path,
370+
timestamp_format,
371+
*emit_placeholder,
372+
*start_line_index,
373+
)?;
374+
construct_block_cache_inner(
375+
&mut rng,
376+
&mut serializer,
377+
maximum_block_bytes,
378+
total_bytes.get(),
379+
)?
380+
}
357381
crate::Config::OpentelemetryTraces(config) => {
358382
let mut pyld = crate::OpentelemetryTraces::with_config(*config, &mut rng)?;
359383
let span = span!(Level::INFO, "fixed", payload = "otel-traces");

lading_payload/src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub use opentelemetry::metric::OpentelemetryMetrics;
2727
pub use opentelemetry::trace::OpentelemetryTraces;
2828
pub use splunk_hec::SplunkHec;
2929
pub use static_chunks::StaticChunks;
30+
pub use static_timestamped::StaticTimestamped;
3031
pub use statik::Static;
3132
pub use syslog::Syslog5424;
3233

@@ -41,6 +42,7 @@ pub mod opentelemetry;
4142
pub mod procfs;
4243
pub mod splunk_hec;
4344
pub mod static_chunks;
45+
pub mod static_timestamped;
4446
pub mod statik;
4547
pub mod syslog;
4648
pub mod trace_agent;
@@ -139,6 +141,23 @@ pub enum Config {
139141
/// all files under it (non-recursively) will be read line by line.
140142
static_path: PathBuf,
141143
},
144+
/// Generates static data grouped by second; each block contains one
145+
/// second's worth of logs as determined by a parsed timestamp prefix.
146+
StaticTimestamped {
147+
/// Defines the file path to read static variant data from. Content is
148+
/// assumed to be line-oriented.
149+
static_path: PathBuf,
150+
/// Chrono-compatible timestamp format string used to parse the leading
151+
/// timestamp in each line.
152+
timestamp_format: String,
153+
/// Emit a minimal placeholder block (single newline) for seconds with
154+
/// no lines. When false, empty seconds are skipped.
155+
#[serde(default)]
156+
emit_placeholder: bool,
157+
/// Optional starting line offset; lines before this index are skipped.
158+
#[serde(default)]
159+
start_line_index: Option<u64>,
160+
},
142161
/// Generates a line of printable ascii characters
143162
Ascii,
144163
/// Generates a json encoded line
@@ -179,6 +198,8 @@ pub enum Payload {
179198
Static(Static),
180199
/// Static file content, chunked into lines that fill blocks as closely as possible.
181200
StaticChunks(StaticChunks),
201+
/// Static file content grouped into one-second blocks based on timestamps
202+
StaticTimestamped(StaticTimestamped),
182203
/// Syslog RFC 5424 format
183204
Syslog(Syslog5424),
184205
/// OpenTelemetry traces
@@ -208,6 +229,7 @@ impl Serialize for Payload {
208229
Payload::SplunkHec(ser) => ser.to_bytes(rng, max_bytes, writer),
209230
Payload::Static(ser) => ser.to_bytes(rng, max_bytes, writer),
210231
Payload::StaticChunks(ser) => ser.to_bytes(rng, max_bytes, writer),
232+
Payload::StaticTimestamped(ser) => ser.to_bytes(rng, max_bytes, writer),
211233
Payload::Syslog(ser) => ser.to_bytes(rng, max_bytes, writer),
212234
Payload::OtelTraces(ser) => ser.to_bytes(rng, max_bytes, writer),
213235
Payload::OtelLogs(ser) => ser.to_bytes(rng, max_bytes, writer),

0 commit comments

Comments
 (0)