Skip to content

Commit

Permalink
Merge branch 'main' into cassandra-5
Browse files Browse the repository at this point in the history
  • Loading branch information
conorbros authored Feb 8, 2024
2 parents a59c2be + 67795d0 commit 2bfb610
Show file tree
Hide file tree
Showing 19 changed files with 407 additions and 126 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 41 additions & 22 deletions shotover-proxy/benches/windsock/cassandra/bench.rs

Large diffs are not rendered by default.

129 changes: 93 additions & 36 deletions shotover-proxy/benches/windsock/cloud/aws.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use anyhow::Result;
use aws_throwaway::{Aws, Ec2Instance, InstanceType};
use aws_throwaway::{CleanupResources, Ec2InstanceDefinition};
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::fmt::Write;
use std::time::Duration;
use std::{
Expand All @@ -22,6 +24,8 @@ impl AwsInstances {
pub async fn new() -> Self {
AwsInstances {
aws: Aws::builder(CleanupResources::WithAppTag(AWS_THROWAWAY_TAG.to_owned()))
// shotover metrics port
.expose_ports_to_internet(vec![9001])
.build()
.await,
}
Expand All @@ -32,38 +36,47 @@ impl AwsInstances {
.await
}

pub async fn create_bencher_instances(&self, count: usize) -> Vec<Arc<Ec2InstanceWithBencher>> {
pub async fn create_bencher_instances(
&self,
benches_will_run: bool,
count: usize,
) -> Vec<Arc<Ec2InstanceWithBencher>> {
let mut futures = vec![];
for _ in 0..count {
futures.push(self.create_bencher_instance());
futures.push(self.create_bencher_instance(benches_will_run));
}
futures::future::join_all(futures).await
}

pub async fn create_shotover_instances(
&self,
benches_will_run: bool,
count: usize,
) -> Vec<Arc<Ec2InstanceWithShotover>> {
let mut futures = vec![];
for _ in 0..count {
futures.push(self.create_shotover_instance());
futures.push(self.create_shotover_instance(benches_will_run));
}
futures::future::join_all(futures).await
}

pub async fn create_docker_instances(
&self,
benches_will_run: bool,
include_shotover: bool,
count: usize,
) -> Vec<Arc<Ec2InstanceWithDocker>> {
let mut futures = vec![];
for _ in 0..count {
futures.push(self.create_docker_instance(include_shotover));
futures.push(self.create_docker_instance(benches_will_run, include_shotover));
}
futures::future::join_all(futures).await
}

pub async fn create_bencher_instance(&self) -> Arc<Ec2InstanceWithBencher> {
pub async fn create_bencher_instance(
&self,
benches_will_run: bool,
) -> Arc<Ec2InstanceWithBencher> {
let instance = Arc::new(Ec2InstanceWithBencher {
instance: self
.aws
Expand All @@ -82,19 +95,17 @@ sudo apt-get update
sudo apt-get install -y sysstat"#,
)
.await;
instance
.instance
.ssh()
.push_file(
std::env::current_exe().unwrap().as_ref(),
Path::new("windsock"),
)
.await;

if benches_will_run {
instance.upload_bencher().await;
}

instance
}

pub async fn create_docker_instance(
&self,
benches_will_run: bool,
include_shotover: bool,
) -> Arc<Ec2InstanceWithDocker> {
let instance = self
Expand All @@ -119,22 +130,20 @@ curl -sSL https://get.docker.com/ | sudo sh"#,
)
.await;

let local_shotover_path = bin_path!("shotover-proxy");
if include_shotover {
instance
.ssh()
.push_file(local_shotover_path, Path::new("shotover-bin"))
.await;
instance
.ssh()
.push_file(Path::new("config/config.yaml"), Path::new("config.yaml"))
.await;
if include_shotover && benches_will_run {
upload_shotover(&instance).await;
}

Arc::new(Ec2InstanceWithDocker { instance })
Arc::new(Ec2InstanceWithDocker {
instance,
include_shotover,
})
}

pub async fn create_shotover_instance(&self) -> Arc<Ec2InstanceWithShotover> {
pub async fn create_shotover_instance(
&self,
benches_will_run: bool,
) -> Arc<Ec2InstanceWithShotover> {
let instance = Arc::new(Ec2InstanceWithShotover {
instance: self
.aws
Expand All @@ -154,17 +163,9 @@ sudo apt-get install -y sysstat"#,
)
.await;

let local_shotover_path = bin_path!("shotover-proxy");
instance
.instance
.ssh()
.push_file(local_shotover_path, Path::new("shotover-bin"))
.await;
instance
.instance
.ssh()
.push_file(Path::new("config/config.yaml"), Path::new("config.yaml"))
.await;
if benches_will_run {
upload_shotover(&instance.instance).await;
}

instance
}
Expand All @@ -175,11 +176,22 @@ sudo apt-get install -y sysstat"#,
}

/// Despite the name can also run shotover
#[derive(Serialize, Deserialize)]
pub struct Ec2InstanceWithDocker {
pub instance: Ec2Instance,
pub include_shotover: bool,
}

impl Ec2InstanceWithDocker {
pub async fn reinit(&mut self) -> Result<()> {
self.instance.init().await?;
if self.include_shotover {
upload_shotover(&self.instance).await;
}

Ok(())
}

pub async fn run_container(&self, image: &str, envs: &[(String, String)]) {
// cleanup old resources
// TODO: we need a way to ensure there are no shotover resources running.
Expand Down Expand Up @@ -275,11 +287,28 @@ fn get_compatible_instance_type() -> InstanceType {
}
}

#[derive(Serialize, Deserialize)]
pub struct Ec2InstanceWithBencher {
pub instance: Ec2Instance,
}

impl Ec2InstanceWithBencher {
pub async fn reinit(&mut self) -> Result<()> {
self.instance.init().await?;
self.upload_bencher().await;
Ok(())
}

pub async fn upload_bencher(&self) {
self.instance
.ssh()
.push_file(
std::env::current_exe().unwrap().as_ref(),
Path::new("windsock"),
)
.await;
}

pub async fn run_bencher(&self, args: &str, name: &str) {
self.instance
.ssh()
Expand All @@ -292,11 +321,19 @@ impl Ec2InstanceWithBencher {
}
}

#[derive(Serialize, Deserialize)]
pub struct Ec2InstanceWithShotover {
pub instance: Ec2Instance,
}

impl Ec2InstanceWithShotover {
pub async fn reinit(&mut self) -> Result<()> {
self.instance.init().await?;
upload_shotover(&self.instance).await;

Ok(())
}

pub async fn run_shotover(self: Arc<Self>, topology: &str) -> RunningShotover {
self.instance
.ssh()
Expand Down Expand Up @@ -386,3 +423,23 @@ impl RunningShotover {
}
}
}

pub async fn upload_shotover(instance: &Ec2Instance) {
let local_shotover_path = bin_path!("shotover-proxy");

// a leftover shotover-bin process can prevent uploading to shotover-bin
// so we need to kill any such processes before uploading
instance
.ssh()
.shell("killall -w shotover-bin > /dev/null || true")
.await;

instance
.ssh()
.push_file(local_shotover_path, Path::new("shotover-bin"))
.await;
instance
.ssh()
.push_file(Path::new("config/config.yaml"), Path::new("config.yaml"))
.await;
}
Loading

0 comments on commit 2bfb610

Please sign in to comment.