mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-25 04:04:09 +00:00
test: extend remote write value distributions
Signed-off-by: discord9 <discord9@163.com>
This commit is contained in:
@@ -55,6 +55,14 @@ struct Args {
|
||||
value_cardinality: u64,
|
||||
#[arg(long, default_value_t = 0)]
|
||||
value_seed: u64,
|
||||
#[arg(long, default_value_t = 8)]
|
||||
value_run_length: u64,
|
||||
#[arg(long, default_value_t = 100)]
|
||||
value_stall_every: u64,
|
||||
#[arg(long, default_value_t = 16)]
|
||||
value_stall_length: u64,
|
||||
#[arg(long, default_value_t = 5)]
|
||||
value_mixed_every: u64,
|
||||
#[arg(long, default_value_t = 0)]
|
||||
value_sample_offset: u64,
|
||||
#[arg(long)]
|
||||
@@ -69,6 +77,10 @@ enum ValuePattern {
|
||||
Modulo,
|
||||
Unique,
|
||||
SeededRandom,
|
||||
RunLength,
|
||||
QuantizedSignal,
|
||||
SignalWithSporadicStalls,
|
||||
MixedSignalRepeated,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for ValuePattern {
|
||||
@@ -79,6 +91,10 @@ impl std::fmt::Display for ValuePattern {
|
||||
Self::Modulo => write!(f, "modulo"),
|
||||
Self::Unique => write!(f, "unique"),
|
||||
Self::SeededRandom => write!(f, "seeded_random"),
|
||||
Self::RunLength => write!(f, "run_length"),
|
||||
Self::QuantizedSignal => write!(f, "quantized_signal"),
|
||||
Self::SignalWithSporadicStalls => write!(f, "signal_with_sporadic_stalls"),
|
||||
Self::MixedSignalRepeated => write!(f, "mixed_signal_repeated"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,6 +163,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
"step": args.value_step,
|
||||
"cardinality": args.value_cardinality,
|
||||
"seed": args.value_seed,
|
||||
"run_length": args.value_run_length,
|
||||
"stall_every": args.value_stall_every,
|
||||
"stall_length": args.value_stall_length,
|
||||
"mixed_every": args.value_mixed_every,
|
||||
"sample_offset": args.value_sample_offset,
|
||||
"total_samples_per_series": args.value_total_samples_per_series.unwrap_or(args.samples_per_series),
|
||||
},
|
||||
@@ -186,10 +206,9 @@ fn label(name: &str, value: &str) -> Label {
|
||||
|
||||
fn deterministic_value(args: &Args, series_idx: u64, sample_idx: u64) -> f64 {
|
||||
let ordinal = value_ordinal(args, series_idx, sample_idx);
|
||||
let series_sample_ordinal = value_series_sample_ordinal(args, sample_idx);
|
||||
match args.value_pattern {
|
||||
ValuePattern::Linear => {
|
||||
args.value_base + (series_idx % 97) as f64 + sample_idx as f64 * args.value_step
|
||||
}
|
||||
ValuePattern::Linear => linear_value(args, series_idx, series_sample_ordinal),
|
||||
ValuePattern::Constant => args.value_base,
|
||||
ValuePattern::Modulo => {
|
||||
args.value_base + (ordinal % args.value_cardinality.max(1)) as f64 * args.value_step
|
||||
@@ -199,9 +218,40 @@ fn deterministic_value(args: &Args, series_idx: u64, sample_idx: u64) -> f64 {
|
||||
let bucket = splitmix64(ordinal ^ args.value_seed) % args.value_cardinality.max(1);
|
||||
args.value_base + bucket as f64 * args.value_step
|
||||
}
|
||||
ValuePattern::RunLength => {
|
||||
let bucket = (ordinal / args.value_run_length.max(1)) % args.value_cardinality.max(1);
|
||||
args.value_base + bucket as f64 * args.value_step
|
||||
}
|
||||
ValuePattern::QuantizedSignal => {
|
||||
let bucket = ((series_idx % args.value_cardinality.max(1))
|
||||
+ (series_sample_ordinal / args.value_run_length.max(1)))
|
||||
% args.value_cardinality.max(1);
|
||||
args.value_base + bucket as f64 * args.value_step
|
||||
}
|
||||
ValuePattern::SignalWithSporadicStalls => {
|
||||
let stall_every = args.value_stall_every.max(1);
|
||||
let stall_length = args.value_stall_length.min(stall_every);
|
||||
let phase = series_sample_ordinal % stall_every;
|
||||
if phase < stall_length {
|
||||
linear_value(args, series_idx, series_sample_ordinal - phase)
|
||||
} else {
|
||||
linear_value(args, series_idx, series_sample_ordinal)
|
||||
}
|
||||
}
|
||||
ValuePattern::MixedSignalRepeated => {
|
||||
if series_sample_ordinal.is_multiple_of(args.value_mixed_every.max(1)) {
|
||||
args.value_base
|
||||
} else {
|
||||
linear_value(args, series_idx, series_sample_ordinal)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn linear_value(args: &Args, series_idx: u64, series_sample_ordinal: u64) -> f64 {
|
||||
args.value_base + (series_idx % 97) as f64 + series_sample_ordinal as f64 * args.value_step
|
||||
}
|
||||
|
||||
fn value_ordinal(args: &Args, series_idx: u64, sample_idx: u64) -> u64 {
|
||||
let total_samples_per_series = args
|
||||
.value_total_samples_per_series
|
||||
@@ -209,6 +259,10 @@ fn value_ordinal(args: &Args, series_idx: u64, sample_idx: u64) -> u64 {
|
||||
series_idx * total_samples_per_series + args.value_sample_offset + sample_idx
|
||||
}
|
||||
|
||||
fn value_series_sample_ordinal(args: &Args, sample_idx: u64) -> u64 {
|
||||
args.value_sample_offset + sample_idx
|
||||
}
|
||||
|
||||
fn splitmix64(mut value: u64) -> u64 {
|
||||
value = value.wrapping_add(0x9e3779b97f4a7c15);
|
||||
let mut mixed = value;
|
||||
@@ -238,6 +292,10 @@ mod tests {
|
||||
value_step: 0.125,
|
||||
value_cardinality: 97,
|
||||
value_seed: 0,
|
||||
value_run_length: 8,
|
||||
value_stall_every: 100,
|
||||
value_stall_length: 16,
|
||||
value_mixed_every: 5,
|
||||
value_sample_offset: 0,
|
||||
value_total_samples_per_series: None,
|
||||
}
|
||||
@@ -303,4 +361,66 @@ mod tests {
|
||||
args.value_seed = 124;
|
||||
assert_ne!(first, deterministic_value(&args, 4, 5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_length_repeats_each_bucket_for_configured_window() {
|
||||
let mut args = args(ValuePattern::RunLength);
|
||||
args.samples_per_series = 10;
|
||||
args.value_step = 1.0;
|
||||
args.value_cardinality = 4;
|
||||
args.value_run_length = 3;
|
||||
assert_eq!(deterministic_value(&args, 0, 0), 0.0);
|
||||
assert_eq!(deterministic_value(&args, 0, 2), 0.0);
|
||||
assert_eq!(deterministic_value(&args, 0, 3), 1.0);
|
||||
assert_eq!(deterministic_value(&args, 1, 0), 3.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quantized_signal_uses_series_local_quantized_steps() {
|
||||
let mut args = args(ValuePattern::QuantizedSignal);
|
||||
args.value_base = 10.0;
|
||||
args.value_step = 2.0;
|
||||
args.value_cardinality = 5;
|
||||
args.value_run_length = 4;
|
||||
assert_eq!(deterministic_value(&args, 2, 0), 14.0);
|
||||
assert_eq!(deterministic_value(&args, 2, 3), 14.0);
|
||||
assert_eq!(deterministic_value(&args, 2, 4), 16.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quantized_signal_respects_chunk_offset() {
|
||||
let mut args = args(ValuePattern::QuantizedSignal);
|
||||
args.value_step = 1.0;
|
||||
args.value_cardinality = 8;
|
||||
args.value_run_length = 4;
|
||||
args.value_sample_offset = 4;
|
||||
assert_eq!(deterministic_value(&args, 0, 0), 1.0);
|
||||
assert_eq!(deterministic_value(&args, 0, 3), 1.0);
|
||||
assert_eq!(deterministic_value(&args, 0, 4), 2.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sporadic_stalls_hold_value_within_stall_window() {
|
||||
let mut args = args(ValuePattern::SignalWithSporadicStalls);
|
||||
args.value_step = 1.0;
|
||||
args.value_stall_every = 5;
|
||||
args.value_stall_length = 2;
|
||||
assert_eq!(deterministic_value(&args, 0, 0), 0.0);
|
||||
assert_eq!(deterministic_value(&args, 0, 1), 0.0);
|
||||
assert_eq!(deterministic_value(&args, 0, 2), 2.0);
|
||||
assert_eq!(deterministic_value(&args, 0, 5), 5.0);
|
||||
assert_eq!(deterministic_value(&args, 0, 6), 5.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mixed_signal_repeated_inserts_periodic_base_value() {
|
||||
let mut args = args(ValuePattern::MixedSignalRepeated);
|
||||
args.value_base = 100.0;
|
||||
args.value_step = 1.0;
|
||||
args.value_mixed_every = 3;
|
||||
assert_eq!(deterministic_value(&args, 0, 0), 100.0);
|
||||
assert_eq!(deterministic_value(&args, 0, 1), 101.0);
|
||||
assert_eq!(deterministic_value(&args, 0, 2), 102.0);
|
||||
assert_eq!(deterministic_value(&args, 0, 3), 100.0);
|
||||
}
|
||||
}
|
||||
|
||||
+19
-9
@@ -75,21 +75,31 @@ sample values without changing label cardinality or the runner lifecycle:
|
||||
|
||||
```toml
|
||||
[scenario.remote_write.value]
|
||||
pattern = "modulo" # linear, constant, modulo, unique, seeded_random
|
||||
pattern = "quantized_signal" # linear, constant, modulo, unique, seeded_random,
|
||||
# run_length, quantized_signal,
|
||||
# signal_with_sporadic_stalls, mixed_signal_repeated
|
||||
base = 0.0
|
||||
step = 0.125
|
||||
cardinality = 16 # distinct buckets for modulo/seeded_random
|
||||
seed = 12345 # deterministic seeded_random input
|
||||
cardinality = 4096 # buckets for modulo/seeded_random/quantized_signal/run_length
|
||||
seed = 12345 # deterministic seeded_random input
|
||||
run_length = 8 # adjacent samples per bucket for run_length/quantized_signal
|
||||
stall_every = 100 # interval for signal_with_sporadic_stalls
|
||||
stall_length = 16 # held samples inside each stall interval
|
||||
mixed_every = 5 # every Nth sample becomes the repeated base value
|
||||
```
|
||||
|
||||
The default `linear` pattern preserves the helper's historical formula. Use
|
||||
`constant` or low-cardinality `modulo`/`seeded_random` values for repeated-value
|
||||
data shapes, and `unique` or high-cardinality buckets for broad sample-value
|
||||
distributions. This is a generic sample-value control for query/ingestion cases;
|
||||
it does not inspect or assert storage encoding, Parquet footers, or storage
|
||||
policy choices. For chunked remote-write ingestion, the runner passes the sample
|
||||
offset and total sample count to the helper so non-linear value patterns use a
|
||||
stable global sample ordinal across chunks.
|
||||
data shapes, `run_length` for run-heavy low-cardinality series, `quantized_signal`
|
||||
for signal-like values collapsed into a finite bucket set, `signal_with_sporadic_stalls`
|
||||
for mostly continuous signals with periodic flat spots, and `mixed_signal_repeated`
|
||||
for signal-plus-periodic-default mixtures. `unique` or high-cardinality buckets
|
||||
still work for broad sample-value distributions. This is a generic sample-value
|
||||
control for query/ingestion cases; it does not inspect or assert storage
|
||||
encoding, Parquet footers, or storage policy choices. For chunked remote-write
|
||||
ingestion, the runner passes the sample offset and total sample count to the
|
||||
helper so non-linear value patterns use a stable global/per-series ordinal across
|
||||
chunks.
|
||||
|
||||
The runner creates the configured database if needed, writes a per-target
|
||||
frontend config enabling `[prom_store]` with metric engine storage and a non-zero
|
||||
|
||||
@@ -839,6 +839,14 @@ def run_remote_write(generator: Path | None, target: RunTarget, remote: dict[str
|
||||
cmd.extend(["--value-cardinality", str(int(value["cardinality"]))])
|
||||
if "seed" in value:
|
||||
cmd.extend(["--value-seed", str(int(value["seed"]))])
|
||||
if "run_length" in value:
|
||||
cmd.extend(["--value-run-length", str(int(value["run_length"]))])
|
||||
if "stall_every" in value:
|
||||
cmd.extend(["--value-stall-every", str(int(value["stall_every"]))])
|
||||
if "stall_length" in value:
|
||||
cmd.extend(["--value-stall-length", str(int(value["stall_length"]))])
|
||||
if "mixed_every" in value:
|
||||
cmd.extend(["--value-mixed-every", str(int(value["mixed_every"]))])
|
||||
if "sample_offset" in remote:
|
||||
cmd.extend(["--value-sample-offset", str(int(remote["sample_offset"]))])
|
||||
if "total_samples_per_series" in remote:
|
||||
|
||||
Reference in New Issue
Block a user