Skip to content

Commit

Permalink
Add canary promoting
Browse files Browse the repository at this point in the history
  • Loading branch information
EricGhildyal committed Nov 21, 2024
1 parent 39ec82c commit 226029f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/adapters/ingresses/apig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::utils::load_default_aws_config;

use super::Ingress;
use async_trait::async_trait;
use aws_sdk_apigateway::types::{Op, PatchOperation};
use miette::miette;
use miette::{IntoDiagnostic, Result};
use tokio::{fs::File, io::AsyncReadExt};
Expand Down Expand Up @@ -104,6 +105,36 @@ impl AwsApiGateway {

Ok(())
}

pub async fn promote_apig_canary(&self, api_id: &str, stage_name: &str) -> Result<()> {
// 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)
.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 All @@ -128,4 +159,10 @@ impl Ingress for AwsApiGateway {

Ok(())
}

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

Ok(())
}
}
6 changes: 5 additions & 1 deletion src/adapters/ingresses/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait Ingress {

// TODO: define the other methods on this type.
// async fn yank_canary(&mut self) -> Result<()>;
// async fn promote_canary(&mut self) -> Result<()>;
async fn promote_canary(&mut self) -> Result<()>;
// async fn set_canary_traffic(&mut self, percent: u8);
}

Expand All @@ -22,6 +22,10 @@ impl Ingress for MockIngress {
async fn deploy(&mut self) -> Result<()> {
todo!()
}

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

impl From<MockIngress> for BoxIngress {
Expand Down

0 comments on commit 226029f

Please sign in to comment.