Skip to content

Commit

Permalink
Merge branch 'main' into add-v5-benches
Browse files Browse the repository at this point in the history
  • Loading branch information
conorbros committed Jan 29, 2024
2 parents 8a690f6 + 0d7165e commit fbfa94c
Show file tree
Hide file tree
Showing 15 changed files with 262 additions and 488 deletions.
85 changes: 15 additions & 70 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions ec2-cargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ aws-throwaway.workspace = true
tracing-appender.workspace = true
shellfish = { version = "0.9.0", features = ["async"] }
cargo_metadata = "0.18.0"
shell-quote = "0.5.0"
18 changes: 12 additions & 6 deletions ec2-cargo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ fi
println!("All AWS throwaway resources have been deleted")
}

async fn test(state: &mut State, mut args: Vec<String>) -> Result<(), Box<dyn Error>> {
async fn test(state: &mut State, args: Vec<String>) -> Result<(), Box<dyn Error>> {
rsync_push_shotover(state).await;
args.remove(0);
let args = args.join(" ");
let args = process_args(args);
let mut receiver = state
.instance
.ssh()
Expand All @@ -156,10 +155,9 @@ cargo nextest run {} 2>&1
Ok(())
}

async fn windsock(state: &mut State, mut args: Vec<String>) -> Result<(), Box<dyn Error>> {
async fn windsock(state: &mut State, args: Vec<String>) -> Result<(), Box<dyn Error>> {
rsync_push_shotover(state).await;
args.remove(0);
let args = args.join(" ");
let args = process_args(args);
let mut receiver = state
.instance
.ssh()
Expand All @@ -186,6 +184,14 @@ cargo windsock {} 2>&1
Ok(())
}

fn process_args(mut args: Vec<String>) -> String {
args.remove(0);
args.iter()
.map(|x| String::from_utf8(shell_quote::Bash::quote(x)).unwrap())
.collect::<Vec<_>>()
.join(" ")
}

async fn rsync_push_shotover(state: &State) {
let instance = &state.instance;
let project_root_dir = &state.cargo_meta.workspace_root;
Expand Down
2 changes: 0 additions & 2 deletions shotover-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ rand_distr.workspace = true
async-trait.workspace = true
tracing-subscriber.workspace = true
tracing-appender.workspace = true
async-once-cell = "0.5.2"
fred = { version = "8.0.0", features = ["enable-rustls"] }
tokio-bin-process.workspace = true
rustls-pemfile = "2.0.0"
Expand All @@ -55,7 +54,6 @@ cql-ws = { git = "https://github.com/shotover/cql-ws" }
opensearch = "2.1.0"
serde_json = "1.0.103"
time = { version = "0.3.25" }
inferno = { version = "0.11.15", default-features = false, features = ["multithreaded", "nameattr"] }
hyper.workspace = true
shell-quote.workspace = true

Expand Down
6 changes: 3 additions & 3 deletions shotover-proxy/benches/windsock/cassandra.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
aws::{
cloud::{CloudResources, CloudResourcesRequired},
Ec2InstanceWithDocker, Ec2InstanceWithShotover, RunningShotover,
cloud::{
CloudResources, CloudResourcesRequired, Ec2InstanceWithDocker, Ec2InstanceWithShotover,
RunningShotover,
},
common::{self, Shotover},
profilers::{self, CloudProfilerRunner, ProfilerRunner},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
//! Windsock specific logic built on top of aws_throwaway
pub mod cloud;

use async_once_cell::OnceCell;
use aws_throwaway::{Aws, Ec2Instance, InstanceType};
use aws_throwaway::{CleanupResources, Ec2InstanceDefinition};
use regex::Regex;
Expand All @@ -19,23 +14,22 @@ use windsock::ReportArchive;

static AWS_THROWAWAY_TAG: &str = "windsock";

static AWS: OnceCell<WindsockAws> = OnceCell::new();

/// TODO: move WindsockAws into a private module so only AwsCloud has access to it.
pub struct WindsockAws {
pub struct AwsInstances {
aws: Aws,
}

impl WindsockAws {
pub async fn get() -> &'static Self {
AWS.get_or_init(async move {
WindsockAws {
aws: Aws::builder(CleanupResources::WithAppTag(AWS_THROWAWAY_TAG.to_owned()))
.build()
.await,
}
})
.await
impl AwsInstances {
pub async fn new() -> Self {
AwsInstances {
aws: Aws::builder(CleanupResources::WithAppTag(AWS_THROWAWAY_TAG.to_owned()))
.build()
.await,
}
}

pub async fn cleanup() {
Aws::cleanup_resources_static(CleanupResources::WithAppTag(AWS_THROWAWAY_TAG.to_owned()))
.await
}

pub async fn create_bencher_instances(&self, count: usize) -> Vec<Arc<Ec2InstanceWithBencher>> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
use super::{
Ec2InstanceWithBencher, Ec2InstanceWithDocker, Ec2InstanceWithShotover, AWS, AWS_THROWAWAY_TAG,
//! Windsock specific logic built on top of aws_throwaway
mod aws;

pub use aws::{
Ec2InstanceWithBencher, Ec2InstanceWithDocker, Ec2InstanceWithShotover, RunningShotover,
};

use async_trait::async_trait;
use aws_throwaway::{Aws, CleanupResources};
use aws::AwsInstances;
use std::sync::Arc;
use windsock::cloud::{BenchInfo, Cloud};

pub struct AwsCloud;
pub struct AwsCloud {
aws: Option<AwsInstances>,
}

impl AwsCloud {
pub fn new_boxed() -> Box<
dyn Cloud<CloudResourcesRequired = CloudResourcesRequired, CloudResources = CloudResources>,
> {
Box::new(AwsCloud)
Box::new(AwsCloud { aws: None })
}
}

#[async_trait(?Send)]
impl Cloud for AwsCloud {
type CloudResourcesRequired = CloudResourcesRequired;
type CloudResources = CloudResources;
async fn cleanup_resources(&self) {
match AWS.get() {
async fn cleanup_resources(&mut self) {
match &self.aws {
// AWS is initialized, it'll be faster to cleanup resources making use of the initialization
Some(aws) => aws.cleanup_resources().await,
// AWS is not initialized, it'll be faster to cleanup resources skipping initialization
None => {
Aws::cleanup_resources_static(CleanupResources::WithAppTag(
AWS_THROWAWAY_TAG.to_owned(),
))
.await
}
None => AwsInstances::cleanup().await,
}
}

async fn create_resources(&self, required: Vec<CloudResourcesRequired>) -> CloudResources {
async fn create_resources(&mut self, required: Vec<CloudResourcesRequired>) -> CloudResources {
let required = required.into_iter().fold(
CloudResourcesRequired::default(),
CloudResourcesRequired::combine,
);
println!("Creating AWS resources: {required:#?}");

// TODO: make Option<WindsockAws> field of AwsCloud
let aws = crate::aws::WindsockAws::get().await;
if self.aws.is_none() {
self.aws = Some(crate::cloud::AwsInstances::new().await);
}

let aws = self.aws.as_ref().unwrap();
let (docker, mut bencher, shotover) = futures::join!(
aws.create_docker_instances(
required.include_shotover_in_docker_instance,
Expand All @@ -61,15 +65,15 @@ impl Cloud for AwsCloud {
}

fn order_benches(
&self,
&mut self,
benches: Vec<BenchInfo<CloudResourcesRequired>>,
) -> Vec<BenchInfo<CloudResourcesRequired>> {
// TODO: put benches with most resources first
benches
}

async fn adjust_resources(
&self,
&mut self,
_benches: &[BenchInfo<CloudResourcesRequired>],
_bench_index: usize,
resources: &mut CloudResources,
Expand Down
Loading

0 comments on commit fbfa94c

Please sign in to comment.