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

feat(gateway): allow manual blocking of cch project traffic at high load #1446

Merged
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
4 changes: 2 additions & 2 deletions common/src/models/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub enum ErrorKind {
NotReady,
ServiceUnavailable,
DeleteProjectFailed,
ContainerLimit,
CapacityLimit,
}

impl From<ErrorKind> for ApiError {
Expand Down Expand Up @@ -132,7 +132,7 @@ impl From<ErrorKind> for ApiError {
ErrorKind::Forbidden => (StatusCode::FORBIDDEN, "Forbidden"),
ErrorKind::NotReady => (StatusCode::INTERNAL_SERVER_ERROR, "Service not ready"),
ErrorKind::DeleteProjectFailed => (StatusCode::INTERNAL_SERVER_ERROR, "Deleting project failed"),
ErrorKind::ContainerLimit => (StatusCode::SERVICE_UNAVAILABLE, "Our server is full and cannot create / start projects at this time"),
ErrorKind::CapacityLimit => (StatusCode::SERVICE_UNAVAILABLE, "Our server is at capacity and cannot serve your request at this time"),
};
Self {
message: error_message.to_string(),
Expand Down
12 changes: 8 additions & 4 deletions gateway/src/api/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ async fn create_project(
.saturating_sub(is_cch_project as u32),
);

service.has_capacity(is_cch_project, &claim.tier).await?;
if !claim.is_admin() {
service.has_capacity(is_cch_project, &claim.tier).await?;
}

let project = service
.create_project(
Expand Down Expand Up @@ -442,9 +444,11 @@ async fn route_project(
let project_name = scoped_user.scope;
let is_cch_project = project_name.is_cch_project();

service
.has_capacity(is_cch_project, &scoped_user.user.claim.tier)
.await?;
if !scoped_user.user.claim.is_admin() {
service
.has_capacity(is_cch_project, &scoped_user.user.claim.tier)
.await?;
}

let project = service.find_or_start_project(&project_name, sender).await?;
service
Expand Down
10 changes: 8 additions & 2 deletions gateway/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,13 @@ impl GatewayService {
) -> Result<(), Error> {
let current_container_count = self.count_ready_projects().await?;

let has_capacity = if current_container_count < self.cch_container_limit {
let has_capacity = if is_cch_project
&& std::fs::metadata("/var/lib/shuttle/BLOCK_CCH23_PROJECT_TRAFFIC").is_ok()
{
// If this control file exists, block routing to cch23 projects.
// Used for emergency load mitigation
return Err(Error::from_kind(ErrorKind::CapacityLimit));
} else if current_container_count < self.cch_container_limit {
true
} else if current_container_count < self.soft_container_limit {
!is_cch_project
Expand All @@ -973,7 +979,7 @@ impl GatewayService {
if has_capacity {
Ok(())
} else {
Err(Error::from_kind(ErrorKind::ContainerLimit))
Err(Error::from_kind(ErrorKind::CapacityLimit))
}
}
}
Expand Down