From 989b8021d5e455eca678f6ddea0f07de3f3190d7 Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Thu, 17 Aug 2023 14:51:17 +1000 Subject: [PATCH 1/2] use precompiled bin --- shotover-proxy/examples/windsock/cassandra.rs | 4 +++- shotover-proxy/examples/windsock/kafka.rs | 19 ++++++------------- shotover-proxy/examples/windsock/main.rs | 1 + shotover-proxy/examples/windsock/redis.rs | 19 ++++++------------- shotover-proxy/examples/windsock/shotover.rs | 11 +++++++++++ 5 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 shotover-proxy/examples/windsock/shotover.rs diff --git a/shotover-proxy/examples/windsock/cassandra.rs b/shotover-proxy/examples/windsock/cassandra.rs index d36e1075e..32a1caf19 100644 --- a/shotover-proxy/examples/windsock/cassandra.rs +++ b/shotover-proxy/examples/windsock/cassandra.rs @@ -40,6 +40,7 @@ use test_helpers::{ shotover_process::ShotoverProcessBuilder, }; use tokio::sync::mpsc::UnboundedSender; +use tokio_bin_process::bin_path; use windsock::{Bench, BenchParameters, BenchTask, Profiling, Report}; const ROW_COUNT: usize = 1000; @@ -549,8 +550,9 @@ impl Bench for CassandraBench { let shotover = match self.shotover { Shotover::Standard => Some( ShotoverProcessBuilder::new_with_topology(&format!("{config_dir}/topology.yaml")) - .with_cores(core_count.shotover as u32) + .with_bin(bin_path!("shotover-proxy")) .with_profile(profiler.shotover_profile()) + .with_cores(core_count.shotover as u32) .start() .await, ), diff --git a/shotover-proxy/examples/windsock/kafka.rs b/shotover-proxy/examples/windsock/kafka.rs index 838b5e45c..1dd036015 100644 --- a/shotover-proxy/examples/windsock/kafka.rs +++ b/shotover-proxy/examples/windsock/kafka.rs @@ -1,6 +1,7 @@ use crate::aws::{Ec2InstanceWithDocker, Ec2InstanceWithShotover}; use crate::common::{rewritten_file, Shotover}; use crate::profilers::{self, CloudProfilerRunner, ProfilerRunner}; +use crate::shotover::shotover_process; use anyhow::Result; use async_trait::async_trait; use aws_throwaway::ec2_instance::Ec2Instance; @@ -12,7 +13,7 @@ use rdkafka::util::Timeout; use std::path::Path; use std::sync::Arc; use std::{collections::HashMap, time::Duration}; -use test_helpers::{docker_compose::docker_compose, shotover_process::ShotoverProcessBuilder}; +use test_helpers::docker_compose::docker_compose; use tokio::{sync::mpsc::UnboundedSender, task::JoinHandle, time::Instant}; use windsock::{Bench, BenchParameters, Profiling, Report}; @@ -124,20 +125,12 @@ impl Bench for KafkaBench { let mut profiler = ProfilerRunner::new(self.name(), profiling); let shotover = match self.shotover { - Shotover::Standard => Some( - ShotoverProcessBuilder::new_with_topology(&format!("{config_dir}/topology.yaml")) - .with_profile(profiler.shotover_profile()) - .start() - .await, - ), + Shotover::Standard => { + Some(shotover_process(&format!("{config_dir}/topology.yaml"), &profiler).await) + } Shotover::None => None, Shotover::ForcedMessageParsed => Some( - ShotoverProcessBuilder::new_with_topology(&format!( - "{config_dir}/topology-encode.yaml" - )) - .with_profile(profiler.shotover_profile()) - .start() - .await, + shotover_process(&format!("{config_dir}/topology-encode.yaml"), &profiler).await, ), }; diff --git a/shotover-proxy/examples/windsock/main.rs b/shotover-proxy/examples/windsock/main.rs index e6a050887..46168839c 100644 --- a/shotover-proxy/examples/windsock/main.rs +++ b/shotover-proxy/examples/windsock/main.rs @@ -4,6 +4,7 @@ mod common; mod kafka; mod profilers; mod redis; +mod shotover; use crate::cassandra::*; use crate::common::*; diff --git a/shotover-proxy/examples/windsock/redis.rs b/shotover-proxy/examples/windsock/redis.rs index 6ad3ff077..9c0e1e6d7 100644 --- a/shotover-proxy/examples/windsock/redis.rs +++ b/shotover-proxy/examples/windsock/redis.rs @@ -2,6 +2,7 @@ use crate::{ aws::{Ec2InstanceWithDocker, Ec2InstanceWithShotover, RunningShotover, WindsockAws}, common::{rewritten_file, Shotover}, profilers::{self, CloudProfilerRunner, ProfilerRunner}, + shotover::shotover_process, }; use anyhow::{anyhow, Context, Result}; use async_trait::async_trait; @@ -23,7 +24,7 @@ use std::{ }; use test_helpers::{ docker_compose::docker_compose, - shotover_process::{Count, EventMatcher, Level, ShotoverProcessBuilder}, + shotover_process::{Count, EventMatcher, Level}, }; use tokio::sync::mpsc::UnboundedSender; use windsock::{Bench, BenchParameters, BenchTask, Profiling, Report}; @@ -203,19 +204,11 @@ impl Bench for RedisBench { let _compose = docker_compose(&format!("{config_dir}/docker-compose.yaml")); let mut profiler = ProfilerRunner::new(self.name(), profiling); let shotover = match self.shotover { - Shotover::Standard => Some( - ShotoverProcessBuilder::new_with_topology(&format!("{config_dir}/topology.yaml")) - .with_profile(profiler.shotover_profile()) - .start() - .await, - ), + Shotover::Standard => { + Some(shotover_process(&format!("{config_dir}/topology.yaml"), &profiler).await) + } Shotover::ForcedMessageParsed => Some( - ShotoverProcessBuilder::new_with_topology(&format!( - "{config_dir}/topology-encode.yaml" - )) - .with_profile(profiler.shotover_profile()) - .start() - .await, + shotover_process(&format!("{config_dir}/topology-encode.yaml"), &profiler).await, ), Shotover::None => None, }; diff --git a/shotover-proxy/examples/windsock/shotover.rs b/shotover-proxy/examples/windsock/shotover.rs new file mode 100644 index 000000000..ea53392f6 --- /dev/null +++ b/shotover-proxy/examples/windsock/shotover.rs @@ -0,0 +1,11 @@ +use crate::profilers::ProfilerRunner; +use test_helpers::shotover_process::ShotoverProcessBuilder; +use tokio_bin_process::{bin_path, BinProcess}; + +pub async fn shotover_process(topology_path: &str, profiler: &ProfilerRunner) -> BinProcess { + ShotoverProcessBuilder::new_with_topology(topology_path) + .with_bin(bin_path!("shotover-proxy")) + .with_profile(profiler.shotover_profile()) + .start() + .await +} From 6ee96f830140764a6f69cf7d75468016211591e7 Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Thu, 17 Aug 2023 16:17:21 +1000 Subject: [PATCH 2/2] move windsock to bench --- .cargo/config.toml | 3 +- shotover-proxy/Cargo.toml | 4 +++ .../windsock/aws/cloud.rs | 0 .../{examples => benches}/windsock/aws/mod.rs | 29 ++----------------- .../windsock/cassandra.rs | 0 .../{examples => benches}/windsock/common.rs | 0 .../{examples => benches}/windsock/kafka.rs | 0 .../{examples => benches}/windsock/main.rs | 0 .../windsock/profilers.rs | 0 .../windsock/profilers/sar.rs | 0 .../{examples => benches}/windsock/readme.md | 0 .../{examples => benches}/windsock/redis.rs | 0 .../windsock/shotover.rs | 0 shotover-proxy/build.rs | 7 ----- 14 files changed, 9 insertions(+), 34 deletions(-) rename shotover-proxy/{examples => benches}/windsock/aws/cloud.rs (100%) rename shotover-proxy/{examples => benches}/windsock/aws/mod.rs (90%) rename shotover-proxy/{examples => benches}/windsock/cassandra.rs (100%) rename shotover-proxy/{examples => benches}/windsock/common.rs (100%) rename shotover-proxy/{examples => benches}/windsock/kafka.rs (100%) rename shotover-proxy/{examples => benches}/windsock/main.rs (100%) rename shotover-proxy/{examples => benches}/windsock/profilers.rs (100%) rename shotover-proxy/{examples => benches}/windsock/profilers/sar.rs (100%) rename shotover-proxy/{examples => benches}/windsock/readme.md (100%) rename shotover-proxy/{examples => benches}/windsock/redis.rs (100%) rename shotover-proxy/{examples => benches}/windsock/shotover.rs (100%) delete mode 100644 shotover-proxy/build.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index dfcc19e05..eff45697d 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -8,4 +8,5 @@ rustflags = [ linker = "aarch64-linux-gnu-gcc" [alias] -windsock = "run --release --example windsock --" +windsock = "test --release --bench windsock --features alpha-transforms --" +windsock-debug = "test --bench windsock --features alpha-transforms --" diff --git a/shotover-proxy/Cargo.toml b/shotover-proxy/Cargo.toml index ab272c1a7..53698b921 100644 --- a/shotover-proxy/Cargo.toml +++ b/shotover-proxy/Cargo.toml @@ -58,3 +58,7 @@ time = { version = "0.3.25" } # Include WIP alpha transforms in the public API alpha-transforms = ["shotover/alpha-transforms"] cassandra-cpp-driver-tests = ["test-helpers/cassandra-cpp-driver-tests"] + +[[bench]] +name = "windsock" +harness = false diff --git a/shotover-proxy/examples/windsock/aws/cloud.rs b/shotover-proxy/benches/windsock/aws/cloud.rs similarity index 100% rename from shotover-proxy/examples/windsock/aws/cloud.rs rename to shotover-proxy/benches/windsock/aws/cloud.rs diff --git a/shotover-proxy/examples/windsock/aws/mod.rs b/shotover-proxy/benches/windsock/aws/mod.rs similarity index 90% rename from shotover-proxy/examples/windsock/aws/mod.rs rename to shotover-proxy/benches/windsock/aws/mod.rs index 1ba783913..df567361c 100644 --- a/shotover-proxy/examples/windsock/aws/mod.rs +++ b/shotover-proxy/benches/windsock/aws/mod.rs @@ -13,6 +13,7 @@ use std::{ }; use test_helpers::docker_compose::get_image_waiters; use tokio::sync::RwLock; +use tokio_bin_process::bin_path; use tokio_bin_process::event::{Event, Level}; use windsock::ReportArchive; @@ -128,35 +129,11 @@ sudo apt-get install -y sysstat"#, ) .await; - // PROFILE is set in build.rs from PROFILE listed in https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts - let profile = if env!("PROFILE") == "release" { - "release" - } else { - "dev" - }; - let output = tokio::process::Command::new(env!("CARGO")) - .args(["build", "--all-features", "--profile", profile]) - .output() - .await - .unwrap(); - if !output.status.success() { - let stdout = String::from_utf8(output.stdout).unwrap(); - let stderr = String::from_utf8(output.stderr).unwrap(); - panic!("Bench run failed:\nstdout:\n{stdout}\nstderr:\n{stderr}") - } + let local_shotover_path = bin_path!("shotover-proxy"); instance .instance .ssh() - .push_file( - &std::env::current_exe() - .unwrap() - .parent() - .unwrap() - .parent() - .unwrap() - .join("shotover-proxy"), - Path::new("shotover-bin"), - ) + .push_file(local_shotover_path, Path::new("shotover-bin")) .await; instance .instance diff --git a/shotover-proxy/examples/windsock/cassandra.rs b/shotover-proxy/benches/windsock/cassandra.rs similarity index 100% rename from shotover-proxy/examples/windsock/cassandra.rs rename to shotover-proxy/benches/windsock/cassandra.rs diff --git a/shotover-proxy/examples/windsock/common.rs b/shotover-proxy/benches/windsock/common.rs similarity index 100% rename from shotover-proxy/examples/windsock/common.rs rename to shotover-proxy/benches/windsock/common.rs diff --git a/shotover-proxy/examples/windsock/kafka.rs b/shotover-proxy/benches/windsock/kafka.rs similarity index 100% rename from shotover-proxy/examples/windsock/kafka.rs rename to shotover-proxy/benches/windsock/kafka.rs diff --git a/shotover-proxy/examples/windsock/main.rs b/shotover-proxy/benches/windsock/main.rs similarity index 100% rename from shotover-proxy/examples/windsock/main.rs rename to shotover-proxy/benches/windsock/main.rs diff --git a/shotover-proxy/examples/windsock/profilers.rs b/shotover-proxy/benches/windsock/profilers.rs similarity index 100% rename from shotover-proxy/examples/windsock/profilers.rs rename to shotover-proxy/benches/windsock/profilers.rs diff --git a/shotover-proxy/examples/windsock/profilers/sar.rs b/shotover-proxy/benches/windsock/profilers/sar.rs similarity index 100% rename from shotover-proxy/examples/windsock/profilers/sar.rs rename to shotover-proxy/benches/windsock/profilers/sar.rs diff --git a/shotover-proxy/examples/windsock/readme.md b/shotover-proxy/benches/windsock/readme.md similarity index 100% rename from shotover-proxy/examples/windsock/readme.md rename to shotover-proxy/benches/windsock/readme.md diff --git a/shotover-proxy/examples/windsock/redis.rs b/shotover-proxy/benches/windsock/redis.rs similarity index 100% rename from shotover-proxy/examples/windsock/redis.rs rename to shotover-proxy/benches/windsock/redis.rs diff --git a/shotover-proxy/examples/windsock/shotover.rs b/shotover-proxy/benches/windsock/shotover.rs similarity index 100% rename from shotover-proxy/examples/windsock/shotover.rs rename to shotover-proxy/benches/windsock/shotover.rs diff --git a/shotover-proxy/build.rs b/shotover-proxy/build.rs deleted file mode 100644 index a566c2b4c..000000000 --- a/shotover-proxy/build.rs +++ /dev/null @@ -1,7 +0,0 @@ -use std::env; - -fn main() { - let profile = env::var("PROFILE").unwrap(); - println!("cargo:rustc-env=PROFILE={profile}"); - println!("cargo:rerun-if-changed=build.rs"); -}