Skip to content

Commit f456fd4

Browse files
authored
feat: add BooleanValue::Toggle and FloatValue::SequentialWithInc (#26178)
1 parent d6abd8d commit f456fd4

2 files changed

Lines changed: 40 additions & 8 deletions

File tree

influxdb3_load_generator/src/line_protocol_generator.rs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use crate::specification::{DataSpec, FieldKind, MeasurementSpec};
55
use chrono::{DateTime, Local};
66
use influxdb3_client::{Client, Precision};
77
use rand::distributions::Alphanumeric;
8-
use rand::rngs::SmallRng;
9-
use rand::{Rng, RngCore, SeedableRng};
8+
use rand::{Rng, RngCore};
109
use std::collections::HashMap;
1110
use std::io::Write;
1211
use std::ops::Add;
@@ -133,9 +132,15 @@ fn create_measurement<'a>(
133132
key: Arc::clone(&key),
134133
copy_id,
135134
null_probability,
136-
field_value: FieldValue::Boolean(BooleanValue::Random(
137-
SmallRng::from_entropy(),
138-
)),
135+
field_value: FieldValue::Boolean(BooleanValue::Random),
136+
});
137+
}
138+
FieldKind::BoolToggle => {
139+
fields.push(Field {
140+
key: Arc::clone(&key),
141+
copy_id,
142+
null_probability,
143+
field_value: FieldValue::Boolean(BooleanValue::Toggle(false)),
139144
});
140145
}
141146
FieldKind::String(s) => {
@@ -215,6 +220,17 @@ fn create_measurement<'a>(
215220
})),
216221
});
217222
}
223+
FieldKind::FloatSeqWithInc(inc) => {
224+
fields.push(Field {
225+
key: Arc::clone(&key),
226+
copy_id,
227+
null_probability,
228+
field_value: FieldValue::Float(FloatValue::SequentialWithInc {
229+
next: 0f64,
230+
inc: *inc,
231+
}),
232+
});
233+
}
218234
}
219235
}
220236
}
@@ -458,6 +474,10 @@ impl Field {
458474
let v: f64 = rng.gen_range(range.clone());
459475
write!(w, "{:.3}", v)?;
460476
}
477+
FloatValue::SequentialWithInc { next, inc } => {
478+
write!(w, "{:.10}", next)?;
479+
*next += *inc;
480+
}
461481
},
462482
FieldValue::String(s) => match s {
463483
StringValue::Fixed(v) => write!(w, "\"{}\"", v)?,
@@ -476,10 +496,14 @@ impl Field {
476496
}
477497
},
478498
FieldValue::Boolean(f) => match f {
479-
BooleanValue::Random(rng) => {
499+
BooleanValue::Random => {
480500
let v: bool = rng.r#gen();
481501
write!(w, "{}", v)?;
482502
}
503+
BooleanValue::Toggle(current) => {
504+
write!(w, "{current}")?;
505+
*current = !*current;
506+
}
483507
},
484508
}
485509

@@ -498,6 +522,7 @@ pub enum IntegerValue {
498522
pub enum FloatValue {
499523
Fixed(f64),
500524
Random(Range<f64>),
525+
SequentialWithInc { next: f64, inc: f64 },
501526
}
502527

503528
#[derive(Clone, Debug)]
@@ -507,9 +532,10 @@ pub enum StringValue {
507532
Sequential(Arc<str>, u64),
508533
}
509534

510-
#[derive(Clone, Debug)]
535+
#[derive(Clone, Copy, Debug)]
511536
pub enum BooleanValue {
512-
Random(SmallRng),
537+
Random,
538+
Toggle(bool),
513539
}
514540

515541
struct ByteCounter<W> {
@@ -722,6 +748,7 @@ pub struct Output {
722748
#[cfg(test)]
723749
mod tests {
724750
use chrono::TimeZone;
751+
use rand::{SeedableRng, rngs::SmallRng};
725752

726753
use super::*;
727754
use crate::specification::{FieldSpec, TagSpec};

influxdb3_load_generator/src/specification.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ pub struct FieldSpec {
130130
pub enum FieldKind {
131131
/// generates a random bool for the value of this field
132132
Bool(bool),
133+
/// repeatedly toggles a boolean field value with the initial value being `false`
134+
BoolToggle,
133135
/// output this string value for every line this field is present
134136
String(String),
135137
/// generate a random string of this length for every line this field is present
@@ -147,6 +149,9 @@ pub enum FieldKind {
147149
Float(f64),
148150
/// generate a random float in this range for every line this field is present
149151
FloatRange(f64, f64),
152+
/// generate sequential floating point numbers with sequential values generated as increments
153+
/// of the specified floating point number, starting from 0
154+
FloatSeqWithInc(f64),
150155
}
151156

152157
#[derive(Debug, Deserialize, Serialize)]

0 commit comments

Comments
 (0)