Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MULTI-314: Add canary promotion #38

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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