Skip to content

Commit

Permalink
feat(config): Add Edge app bootstraping config
Browse files Browse the repository at this point in the history
  • Loading branch information
theduke committed Jun 3, 2024
1 parent c37723b commit 6775a48
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 24 deletions.
32 changes: 9 additions & 23 deletions lib/config/src/app/healthcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,26 @@ pub enum HealthCheckV1 {
schemars::JsonSchema, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone, Debug,
)]
pub struct HealthCheckHttpV1 {
/// Path to the health check endpoint.
pub path: String,
/// HTTP method to use for the health check.
///
/// Defaults to GET.
#[serde(skip_serializing_if = "Option::is_none")]
pub method: Option<String>,
#[serde(flatten)]
pub request: super::HttpRequest,

/// Interval for the health check.
///
/// Format: 1s, 5m, 11h, ...
///
/// Defaults to 60s.
#[serde(skip_serializing_if = "Option::is_none")]
pub interval: Option<String>,
/// Timeout for the health check.
///
/// Deaults to 120s.
///
/// Format: 1s, 5m, 11h, ...
#[serde(skip_serializing_if = "Option::is_none")]
pub timeout: Option<String>,

/// Number of retries before the health check is considered unhealthy.
///
/// Defaults to 1.
#[serde(skip_serializing_if = "Option::is_none")]
pub unhealthy_threshold: Option<u32>,

/// Number of retries before the health check is considered healthy again.
///
/// Defaults to 1.
#[serde(skip_serializing_if = "Option::is_none")]
pub healthy_threshold: Option<u32>,
/// Expected status codes that are considered a pass for the health check.
#[serde(skip_serializing_if = "Vec::is_empty")]
pub expected_status_codes: Vec<u16>,
/// Optional text that is in the body of the response that is considered a pass for the health check.
#[serde(skip_serializing_if = "Option::is_none")]
pub expected_body_includes: Option<String>,
/// Regular expression tested against the body that is considered a pass for the health check
#[serde(skip_serializing_if = "Option::is_none")]
pub expected_body_regex: Option<String>,
}
43 changes: 43 additions & 0 deletions lib/config/src/app/http.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/// Defines an HTTP request.
#[derive(
schemars::JsonSchema, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone, Debug,
)]
pub struct HttpRequest {
/// Request path.
pub path: String,

/// HTTP method.
///
/// Defaults to GET.
#[serde(skip_serializing_if = "Option::is_none")]
pub method: Option<String>,

/// Request body as a string.
pub body: Option<String>,

/// Request timeout.
///
/// Format: 1s, 5m, 11h, ...
#[serde(skip_serializing_if = "Option::is_none")]
pub timeout: Option<String>,

pub expect: Option<HttpRequestExpect>,
}

/// Validation checks for an [`HttpRequest`].
#[derive(
schemars::JsonSchema, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone, Debug,
)]
pub struct HttpRequestExpect {
/// Expected HTTP status codes.
#[serde(skip_serializing_if = "Vec::is_empty")]
pub status_codes: Vec<u16>,

/// Text that must be present in the response body.
#[serde(skip_serializing_if = "Option::is_none")]
pub body_includes: Option<String>,

/// Regular expression that must match against the response body.
#[serde(skip_serializing_if = "Option::is_none")]
pub body_regex: Option<String>,
}
32 changes: 31 additions & 1 deletion lib/config/src/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//! User-facing app.yaml file config: [`AppConfigV1`].

mod healthcheck;
mod http;

pub use self::healthcheck::{HealthCheckHttpV1, HealthCheckV1};
pub use self::{
healthcheck::{HealthCheckHttpV1, HealthCheckV1},
http::HttpRequest,
};

use std::collections::HashMap;

Expand Down Expand Up @@ -187,6 +191,9 @@ pub struct AppConfigCapabilityMapV1 {
/// Instance memory settings.
#[serde(skip_serializing_if = "Option::is_none")]
pub memory: Option<AppConfigCapabilityMemoryV1>,

/// Enables app bootstrapping with startup snapshots.
pub instaboot: Option<AppConfigCapabilityInstaBootV1>,
}

/// Memory capability settings.
Expand All @@ -206,6 +213,29 @@ pub struct AppConfigCapabilityMemoryV1 {
pub limit: Option<ByteSize>,
}

/// Enables accelerated instance boot times with startup snapshots.
///
/// How it works:
/// The Edge runtime will create a pre-initialized snapshot of apps that is
/// ready to serve requests
/// Your app will then restore from the generated snapshot, which has the
/// potential to significantly speed up cold starts.
///
/// To drive the initialization, multiple http requests can be specified.
/// All the specified requests will be sent to the app before the snapshot is
/// created, allowing the app to pre-load files, pre initialize caches, ...
#[derive(
serde::Serialize, serde::Deserialize, schemars::JsonSchema, Clone, Debug, PartialEq, Eq,
)]
pub struct AppConfigCapabilityInstaBootV1 {
/// HTTP requests to perform during startup snapshot creation.
/// Apps can perform all the appropriate warmup logic in these requests.
///
/// NOTE: if no requests are configured, then a single HTTP
/// request to '/' will be performed instead.
pub requests: Vec<HttpRequest>,
}

#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;
Expand Down

0 comments on commit 6775a48

Please sign in to comment.