diff --git a/iox_data_generator/src/bin/iox_data_generator.rs b/iox_data_generator/src/bin/iox_data_generator.rs index f403ac0f90..092ba3e17c 100644 --- a/iox_data_generator/src/bin/iox_data_generator.rs +++ b/iox_data_generator/src/bin/iox_data_generator.rs @@ -18,8 +18,6 @@ use tracing::info; #[tokio::main] async fn main() -> Result<(), Box> { - tracing_subscriber::fmt::init(); - let help = r#"IOx data point generator Examples: @@ -60,6 +58,10 @@ Logging: .takes_value(true) .required(true), ) + .arg(Arg::with_name("PRINT") + .long("print") + .help("Print the generated line protocol from a single sample collection to the terminal") + ) .arg( Arg::with_name("OUTPUT") .short("o") @@ -135,6 +137,11 @@ Logging: ) .get_matches(); + let disable_log_output = matches.is_present("PRINT"); + if !disable_log_output { + tracing_subscriber::fmt::init(); + } + let spec_filename = matches .value_of("SPECIFICATION") // This should never fail if clap is working properly @@ -181,8 +188,10 @@ Logging: ); PointsWriterBuilder::new_api(host, org, bucket, token, create_bucket, org_id).await? + } else if matches.is_present("PRINT") { + PointsWriterBuilder::new_std_out() } else { - panic!("One of --output or --host must be provided."); + panic!("One of --print or --output or --host must be provided."); }; let result = iox_data_generator::generate::( @@ -197,7 +206,11 @@ Logging: .await; match result { - Ok(total_points) => eprintln!("Submitted {} total points", total_points), + Ok(total_points) => { + if !disable_log_output { + eprintln!("Submitted {} total points", total_points); + } + } Err(e) => panic!("Execution failed: \n{}", e), } diff --git a/iox_data_generator/src/write.rs b/iox_data_generator/src/write.rs index 24f83c68f2..fb0966f8d0 100644 --- a/iox_data_generator/src/write.rs +++ b/iox_data_generator/src/write.rs @@ -95,6 +95,7 @@ enum PointsWriterConfig { }, #[cfg(test)] Vector(BTreeMap>>>), + Stdout, } impl PointsWriterBuilder { @@ -157,6 +158,13 @@ impl PointsWriterBuilder { }) } + /// Write points to stdout + pub fn new_std_out() -> Self { + Self { + config: PointsWriterConfig::Stdout, + } + } + /// Generate points but do not write them anywhere pub fn new_no_op(perform_write: bool) -> Self { Self { @@ -193,6 +201,7 @@ impl PointsWriterBuilder { .or_insert_with(|| Arc::new(Mutex::new(Vec::new()))); InnerPointsWriter::Vec(Arc::clone(v)) } + PointsWriterConfig::Stdout => InnerPointsWriter::Stdout, }; PointsWriter { inner_writer } @@ -225,6 +234,7 @@ enum InnerPointsWriter { }, #[cfg(test)] Vec(Arc>>), + Stdout, } impl InnerPointsWriter { @@ -278,6 +288,13 @@ impl InnerPointsWriter { .expect("Should be able to write to vec"); } } + Self::Stdout => { + for point in points { + point + .write_data_point_to(std::io::stdout()) + .expect("should be able to write to stdout"); + } + } } Ok(()) }