Skip to content

Commit

Permalink
Merge pull request #38 from wack/eric/multi-314
Browse files Browse the repository at this point in the history
MULTI-314: Add canary promotion
  • Loading branch information
EricGhildyal authored Nov 26, 2024
2 parents 6c4aeb1 + 9bbe840 commit 4766c25
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/adapters/ingresses/apig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,38 @@ impl AwsApiGateway {

Ok(())
}

pub async fn promote_apig_canary(&self, api_name: &str, stage_name: &str) -> Result<()> {
let api = self.get_api_id_by_name(api_name).await?;

// Overwrite the main deployment's ID with the canary's
let replace_deployment_op = PatchOperation::builder()
.op(Op::Copy)
.from("/canarySettings/deploymentId")
.path("/deploymentId")
.build();

// Reset canary traffic to 0% so we're ready for another release
let reset_traffic_op = PatchOperation::builder()
.op(Op::Replace)
.path("/canarySettings/percentTraffic")
// Note: this must be a string to pass into Value, but it's actually an f64 in AWS
.value("0.0")
.build();

// Send request to update stage
self.apig_client
.update_stage()
.rest_api_id(api.id.unwrap_or_default())
.stage_name(stage_name)
.patch_operations(replace_deployment_op)
.patch_operations(reset_traffic_op)
.send()
.await
.into_diagnostic()?;

Ok(())
}
}

/// given a path to a file, load it as an array of bytes.
Expand Down Expand Up @@ -228,4 +260,10 @@ impl Ingress for AwsApiGateway {

Ok(())
}

async fn promote_canary(&mut self) -> Result<()> {
self.promote_apig_canary("Releases", "prod").await?;

Ok(())
}
}
7 changes: 7 additions & 0 deletions src/adapters/ingresses/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub trait Ingress {
async fn rollback_canary(&mut self) -> Result<()>;
// async fn promote_canary(&mut self) -> Result<()>;
async fn set_canary_traffic(&mut self, percent: WholePercent) -> Result<()>;
// async fn yank_canary(&mut self) -> Result<()>;
async fn promote_canary(&mut self) -> Result<()>;
// async fn set_canary_traffic(&mut self, percent: u8);
}

pub struct MockIngress;
Expand All @@ -33,6 +36,10 @@ impl Ingress for MockIngress {
async fn rollback_canary(&mut self) -> Result<()> {
todo!()
}

async fn promote_canary(&mut self) -> Result<()> {
todo!()
}
}

impl From<MockIngress> for BoxIngress {
Expand Down

0 comments on commit 4766c25

Please sign in to comment.