Skip to content

Commit

Permalink
update aws-throwaway dep (#1311)
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai authored Aug 29, 2023
1 parent 952501b commit 04df935
Show file tree
Hide file tree
Showing 10 changed files with 377 additions and 327 deletions.
645 changes: 338 additions & 307 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ rand_distr = "0.4.1"
clap = { version = "4.0.4", features = ["cargo", "derive"] }
async-trait = "0.1.30"
typetag = "0.2.5"
aws-throwaway = "0.1.1"
tokio-bin-process = "0.3.0"
aws-throwaway = "0.2.0"
tokio-bin-process = "0.3.0"
10 changes: 6 additions & 4 deletions ec2-cargo/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use aws_throwaway::{ec2_instance::Ec2Instance, Aws, InstanceType};
use aws_throwaway::{Aws, CleanupResources, Ec2Instance, Ec2InstanceDefinition, InstanceType};
use cargo_metadata::{Metadata, MetadataCommand};
use clap::Parser;
use rustyline::DefaultEditor;
Expand Down Expand Up @@ -34,14 +34,16 @@ async fn main() {
let cargo_meta = MetadataCommand::new().exec().unwrap();
let args = Args::parse();
if args.cleanup {
Aws::cleanup_resources_static().await;
Aws::cleanup_resources_static(CleanupResources::AllResources).await;
println!("All AWS throwaway resources have been deleted");
return;
}

let aws = Aws::new().await;
let aws = Aws::new(CleanupResources::AllResources).await;
let instance_type = InstanceType::from(args.instance_type.as_str());
let instance = aws.create_ec2_instance(instance_type, 40).await;
let instance = aws
.create_ec2_instance(Ec2InstanceDefinition::new(instance_type).volume_size_gigabytes(40))
.await;

println!(
"If something goes wrong with setup you can ssh into the machine by:\n{}",
Expand Down
11 changes: 8 additions & 3 deletions shotover-proxy/benches/windsock/aws/cloud.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use async_trait::async_trait;
use aws_throwaway::Aws;
use aws_throwaway::{Aws, CleanupResources};
use windsock::cloud::Cloud;

use super::AWS;
use super::{AWS, AWS_THROWAWAY_TAG};

pub struct AwsCloud;

Expand All @@ -19,7 +19,12 @@ impl Cloud for AwsCloud {
// 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().await,
None => {
Aws::cleanup_resources_static(CleanupResources::WithAppTag(
AWS_THROWAWAY_TAG.to_owned(),
))
.await
}
}
}
}
24 changes: 18 additions & 6 deletions shotover-proxy/benches/windsock/aws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
pub mod cloud;

use async_once_cell::OnceCell;
use aws_throwaway::{ec2_instance::Ec2Instance, Aws, InstanceType};
use aws_throwaway::{Aws, Ec2Instance, InstanceType};
use aws_throwaway::{CleanupResources, Ec2InstanceDefinition};
use regex::Regex;
use std::fmt::Write;
use std::time::Duration;
Expand All @@ -17,6 +18,8 @@ use tokio_bin_process::bin_path;
use tokio_bin_process::event::{Event, Level};
use windsock::ReportArchive;

static AWS_THROWAWAY_TAG: &str = "windsock";

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

pub struct WindsockAws {
Expand All @@ -33,7 +36,7 @@ impl WindsockAws {
shotover_instance: RwLock::new(None),
bencher_instance: RwLock::new(None),
docker_instances: RwLock::new(vec![]),
aws: Aws::new().await,
aws: Aws::new(CleanupResources::WithAppTag(AWS_THROWAWAY_TAG.to_owned())).await,
}
})
.await
Expand All @@ -50,7 +53,10 @@ impl WindsockAws {
let instance = Arc::new(Ec2InstanceWithBencher {
instance: self
.aws
.create_ec2_instance(get_compatible_instance_type(), 8)
.create_ec2_instance(
Ec2InstanceDefinition::new(get_compatible_instance_type())
.volume_size_gigabytes(8),
)
.await,
});
instance
Expand Down Expand Up @@ -83,8 +89,11 @@ sudo apt-get install -y sysstat"#,
}
let instance = self
.aws
// databases will need more storage than the shotover or bencher instances
.create_ec2_instance(get_compatible_instance_type(), 40)
.create_ec2_instance(
Ec2InstanceDefinition::new(get_compatible_instance_type())
// databases will need more storage than the shotover or bencher instances
.volume_size_gigabytes(40),
)
.await;
instance
.ssh()
Expand Down Expand Up @@ -116,7 +125,10 @@ curl -sSL https://get.docker.com/ | sudo sh"#,
let instance = Arc::new(Ec2InstanceWithShotover {
instance: self
.aws
.create_ec2_instance(get_compatible_instance_type(), 8)
.create_ec2_instance(
Ec2InstanceDefinition::new(get_compatible_instance_type())
.volume_size_gigabytes(8),
)
.await,
});
instance
Expand Down
2 changes: 1 addition & 1 deletion shotover-proxy/benches/windsock/cassandra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
};
use anyhow::Result;
use async_trait::async_trait;
use aws_throwaway::ec2_instance::Ec2Instance;
use aws_throwaway::Ec2Instance;
use cdrs_tokio::{
cluster::{
session::{
Expand Down
2 changes: 1 addition & 1 deletion shotover-proxy/benches/windsock/kafka.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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;
use aws_throwaway::Ec2Instance;
use futures::StreamExt;
use rdkafka::config::ClientConfig;
use rdkafka::consumer::{Consumer, StreamConsumer};
Expand Down
2 changes: 1 addition & 1 deletion shotover-proxy/benches/windsock/profilers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::common::Shotover;
use aws_throwaway::ec2_instance::Ec2Instance;
use aws_throwaway::Ec2Instance;
use std::{collections::HashMap, path::PathBuf};
use test_helpers::{flamegraph::Perf, shotover_process::BinProcess};
use tokio::sync::mpsc::UnboundedReceiver;
Expand Down
2 changes: 1 addition & 1 deletion shotover-proxy/benches/windsock/profilers/sar.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This module provides abstractions for getting system usage from the unix command `sar`, on ubuntu it is contained within the package `sysstat`.

use aws_throwaway::ec2_instance::Ec2Instance;
use aws_throwaway::Ec2Instance;
use std::{collections::HashMap, process::Stdio};
use time::OffsetDateTime;
use tokio::{
Expand Down
2 changes: 1 addition & 1 deletion shotover-proxy/benches/windsock/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};
use anyhow::{anyhow, Context, Result};
use async_trait::async_trait;
use aws_throwaway::ec2_instance::Ec2Instance;
use aws_throwaway::Ec2Instance;
use fred::{
prelude::*,
rustls::{Certificate, ClientConfig, PrivateKey, RootCertStore},
Expand Down

0 comments on commit 04df935

Please sign in to comment.