diff --git a/lib/config/src/app/healthcheck.rs b/lib/config/src/app/healthcheck.rs index 5866b88af2b..a69832d575d 100644 --- a/lib/config/src/app/healthcheck.rs +++ b/lib/config/src/app/healthcheck.rs @@ -11,13 +11,9 @@ 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, + #[serde(flatten)] + pub request: super::HttpRequest, + /// Interval for the health check. /// /// Format: 1s, 5m, 11h, ... @@ -25,26 +21,16 @@ pub struct HealthCheckHttpV1 { /// Defaults to 60s. #[serde(skip_serializing_if = "Option::is_none")] pub interval: Option, - /// Timeout for the health check. - /// - /// Deaults to 120s. - /// - /// Format: 1s, 5m, 11h, ... - #[serde(skip_serializing_if = "Option::is_none")] - pub timeout: Option, + /// Number of retries before the health check is considered unhealthy. + /// + /// Defaults to 1. #[serde(skip_serializing_if = "Option::is_none")] pub unhealthy_threshold: Option, + /// 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, - /// Expected status codes that are considered a pass for the health check. - #[serde(skip_serializing_if = "Vec::is_empty")] - pub expected_status_codes: Vec, - /// 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, - /// 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, } diff --git a/lib/config/src/app/http.rs b/lib/config/src/app/http.rs new file mode 100644 index 00000000000..69e454d4b06 --- /dev/null +++ b/lib/config/src/app/http.rs @@ -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, + + /// Request body as a string. + pub body: Option, + + /// Request timeout. + /// + /// Format: 1s, 5m, 11h, ... + #[serde(skip_serializing_if = "Option::is_none")] + pub timeout: Option, + + pub expect: Option, +} + +/// 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, + + /// Text that must be present in the response body. + #[serde(skip_serializing_if = "Option::is_none")] + pub body_includes: Option, + + /// Regular expression that must match against the response body. + #[serde(skip_serializing_if = "Option::is_none")] + pub body_regex: Option, +} diff --git a/lib/config/src/app/mod.rs b/lib/config/src/app/mod.rs index 49db3f41eff..60c856fa926 100644 --- a/lib/config/src/app/mod.rs +++ b/lib/config/src/app/mod.rs @@ -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; @@ -187,6 +191,9 @@ pub struct AppConfigCapabilityMapV1 { /// Instance memory settings. #[serde(skip_serializing_if = "Option::is_none")] pub memory: Option, + + /// Enables app bootstrapping with startup snapshots. + pub instaboot: Option, } /// Memory capability settings. @@ -206,6 +213,29 @@ pub struct AppConfigCapabilityMemoryV1 { pub limit: Option, } +/// 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, +} + #[cfg(test)] mod tests { use pretty_assertions::assert_eq;