Skip to content

Commit

Permalink
Merge pull request #40 from wack/robbie/multi-308
Browse files Browse the repository at this point in the history
Plumb AWS config to ingress.
  • Loading branch information
RobbieMcKinstry authored Nov 24, 2024
2 parents 5885ef5 + 405859e commit c0f3e26
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 19 deletions.
13 changes: 12 additions & 1 deletion src/adapters/ingresses/apig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ pub struct AwsApiGateway {
lambda_artifact: Vec<u8>,
apig_client: GatewayClient,
lambda_client: LambdaClient,
gateway_name: String,
stage_name: String,
lambda_name: String,
}

impl AwsApiGateway {
/// Given a path to the lambda, create a new APIG Ingress.
pub async fn new(artifact_path: PathBuf) -> Result<Self> {
pub async fn new(
artifact_path: PathBuf,
gateway_name: &str,
stage_name: &str,
lambda_name: &str,
) -> Result<Self> {
let artifact = read_file(artifact_path).await?;
// Now, configure the AWS SDKs.
// TODO: Extract Config into a single location so we don't have to
Expand All @@ -37,6 +45,9 @@ impl AwsApiGateway {
lambda_artifact: artifact,
apig_client,
lambda_client,
gateway_name: gateway_name.to_owned(),
stage_name: stage_name.to_owned(),
lambda_name: lambda_name.to_owned(),
})
}

Expand Down
2 changes: 2 additions & 0 deletions src/adapters/ingresses/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use async_trait::async_trait;
use miette::Result;

pub use apig::AwsApiGateway;

/// Ingresses are responsible for (1) controlling how much traffic the canary
/// gets (hence the name ingress, since it functions like a virtual LB) and
/// (2) deploying, yanking, and promoting both the canary and the baseline.
Expand Down
24 changes: 12 additions & 12 deletions src/adapters/monitors/cloudwatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,53 +159,53 @@ impl Monitor for CloudWatch {

let control_count_future = self.query_cloudwatch(
ApiMetric::Count,
"Releases",
"prod",
&self.gateway_name,
&self.stage_name,
Group::Control,
now,
five_mins_ago,
);

let control_4xx_future = self.query_cloudwatch(
ApiMetric::Error4XX,
"Releases",
"prod",
&self.gateway_name,
&self.stage_name,
Group::Control,
now,
five_mins_ago,
);

let control_5xx_future = self.query_cloudwatch(
ApiMetric::Error5XX,
"Releases",
"prod",
&self.gateway_name,
&self.stage_name,
Group::Control,
now,
five_mins_ago,
);

let canary_count_future = self.query_cloudwatch(
ApiMetric::Count,
"Releases",
"prod",
&self.gateway_name,
&self.stage_name,
Group::Experimental,
now,
five_mins_ago,
);

let canary_4xx_future = self.query_cloudwatch(
ApiMetric::Error4XX,
"Releases",
"prod",
&self.gateway_name,
&self.stage_name,
Group::Experimental,
now,
five_mins_ago,
);

let canary_5xx_future = self.query_cloudwatch(
ApiMetric::Error5XX,
"Releases",
"prod",
&self.gateway_name,
&self.stage_name,
Group::Experimental,
now,
five_mins_ago,
Expand Down
13 changes: 11 additions & 2 deletions src/cmd/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::adapters::ChiSquareEngine;
use crate::adapters::{CloudWatch, MockIngress};
use crate::adapters::{AwsApiGateway, CloudWatch};
use crate::config::deploy::DeploySubcommand;
use crate::Pipeline;
use miette::Result;
Expand All @@ -10,6 +10,7 @@ pub struct Deploy {
artifact_path: PathBuf,
gateway_name: String,
stage_name: String,
lambda_name: String,
}

impl Deploy {
Expand All @@ -21,6 +22,7 @@ impl Deploy {
artifact_path: args.artifact_path,
gateway_name: args.aws_apig_name,
stage_name: args.aws_apig_stage,
lambda_name: args.aws_lambda,
}
}

Expand All @@ -29,12 +31,19 @@ impl Deploy {
pub async fn dispatch(self) -> Result<()> {
// • Load the monitor from the user's config.
let monitor = CloudWatch::new(&self.gateway_name, &self.stage_name).await;
let ingress = AwsApiGateway::new(
self.artifact_path,
&self.gateway_name,
&self.stage_name,
&self.lambda_name,
)
.await?;
// • TODO: Create the ingress, passing in the path to the deployment artifact.
// • Set up our deployment pipeline.
Pipeline::builder()
.monitor(Box::new(monitor))
.engine(ChiSquareEngine::new())
.ingress(MockIngress)
.ingress(Box::new(ingress))
.build()
// Run the pipeline to completion.
.run()
Expand Down
7 changes: 5 additions & 2 deletions src/config/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ pub struct DeploySubcommand {
#[arg(value_name = "FILE")]
pub artifact_path: PathBuf,
/// The name of the AWS API Gateway to deploy to.
#[arg(long, env)]
#[arg(long, env = "MULTI_AWS_APIG_NAME")]
pub aws_apig_name: String,
/// The name of the AWS API Gateway stage
#[arg(long, env)]
#[arg(long, env = "MULTI_AWS_APIG_STAGE")]
pub aws_apig_stage: String,
/// The name of the AWS Lambda function to update.
#[arg(long, env = "MULTI_AWS_LAMBDA")]
pub aws_lambda: String,
}
4 changes: 2 additions & 2 deletions src/pipeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ impl Pipeline {
#[builder]
pub fn new(
monitor: ResponseMonitor,
ingress: impl Ingress + 'static,
ingress: Box<dyn Ingress>,
engine: impl DecisionEngine<CategoricalObservation<5, ResponseStatusCode>> + 'static,
) -> Self {
Self {
engine: Box::new(engine),
ingress: Box::new(ingress),
ingress,
monitor,
}
}
Expand Down

0 comments on commit c0f3e26

Please sign in to comment.