From cce90e8f39fa2f2da3310dabf17bd6b8a1b7fa8d Mon Sep 17 00:00:00 2001 From: Arshia Ghafoori Date: Tue, 11 Mar 2025 21:16:47 +0400 Subject: [PATCH] Update app.yaml schema with instaboot mode and async_threads setting --- .../jsonschema/types/AppConfigV1.schema.json | 71 +++++++++++++++++++ lib/config/src/app/mod.rs | 48 +++++++++++++ lib/wasix/src/runners/wasi_common.rs | 2 +- 3 files changed, 120 insertions(+), 1 deletion(-) diff --git a/docs/schema/generated/jsonschema/types/AppConfigV1.schema.json b/docs/schema/generated/jsonschema/types/AppConfigV1.schema.json index 2d9499ebb..86cafdf8c 100644 --- a/docs/schema/generated/jsonschema/types/AppConfigV1.schema.json +++ b/docs/schema/generated/jsonschema/types/AppConfigV1.schema.json @@ -161,6 +161,18 @@ } ] }, + "mode": { + "description": "The method to use to generate the instaboot snapshot for the instance.", + "default": null, + "anyOf": [ + { + "$ref": "#/definitions/InstabootSnapshotModeV1" + }, + { + "type": "null" + } + ] + }, "requests": { "description": "HTTP requests to perform during startup snapshot creation. Apps can perform all the appropriate warmup logic in these requests.\n\nNOTE: if no requests are configured, then a single HTTP request to '/' will be performed instead.", "type": "array", @@ -195,6 +207,17 @@ "type": "null" } ] + }, + "runtime": { + "description": "Runtime settings.", + "anyOf": [ + { + "$ref": "#/definitions/AppConfigCapabilityRuntimeV1" + }, + { + "type": "null" + } + ] } }, "additionalProperties": true @@ -212,6 +235,26 @@ } } }, + "AppConfigCapabilityRuntimeV1": { + "description": "Runtime capability settings.", + "type": "object", + "properties": { + "async_threads": { + "description": "Whether to enable asynchronous threads/deep sleeping.", + "type": [ + "boolean", + "null" + ] + }, + "engine": { + "description": "Engine to use for an instance, e.g. wasmer_cranelift, wasmer_llvm, etc.", + "type": [ + "string", + "null" + ] + } + } + }, "AppScalingConfigV1": { "type": "object", "properties": { @@ -543,6 +586,34 @@ } } }, + "InstabootSnapshotModeV1": { + "description": "How will an instance be bootstrapped?", + "oneOf": [ + { + "description": "Start the instance without any snapshot triggers. Once the requests are done, use [`snapshot_and_stop`](wasmer_wasix::WasiProcess::snapshot_and_stop) to capture a snapshot and shut the instance down.", + "type": "string", + "enum": [ + "bootstrap" + ] + }, + { + "description": "Explicitly enable the given snapshot triggers before starting the instance. The instance's process will have its stop_running_after_checkpoint flag set, so the first snapshot will cause the instance to shut down.", + "type": "object", + "required": [ + "triggers" + ], + "properties": { + "triggers": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": false + } + ] + }, "Job": { "description": "Job configuration.", "type": "object", diff --git a/lib/config/src/app/mod.rs b/lib/config/src/app/mod.rs index c0ce1544e..8718c129c 100644 --- a/lib/config/src/app/mod.rs +++ b/lib/config/src/app/mod.rs @@ -198,6 +198,10 @@ pub struct AppConfigCapabilityMapV1 { #[serde(skip_serializing_if = "Option::is_none")] pub memory: Option, + /// Runtime settings. + #[serde(skip_serializing_if = "Option::is_none")] + pub runtime: Option, + /// Enables app bootstrapping with startup snapshots. #[serde(skip_serializing_if = "Option::is_none")] pub instaboot: Option, @@ -227,6 +231,19 @@ pub struct AppConfigCapabilityMemoryV1 { pub limit: Option, } +/// Runtime capability settings. +#[derive( + serde::Serialize, serde::Deserialize, schemars::JsonSchema, Clone, Debug, PartialEq, Eq, +)] +pub struct AppConfigCapabilityRuntimeV1 { + /// Engine to use for an instance, e.g. wasmer_cranelift, wasmer_llvm, etc. + #[serde(skip_serializing_if = "Option::is_none")] + pub engine: Option, + /// Whether to enable asynchronous threads/deep sleeping. + #[serde(skip_serializing_if = "Option::is_none")] + pub async_threads: Option, +} + /// Enables accelerated instance boot times with startup snapshots. /// /// How it works: @@ -242,6 +259,10 @@ pub struct AppConfigCapabilityMemoryV1 { serde::Serialize, serde::Deserialize, schemars::JsonSchema, Clone, Debug, PartialEq, Eq, )] pub struct AppConfigCapabilityInstaBootV1 { + /// The method to use to generate the instaboot snapshot for the instance. + #[serde(default)] + pub mode: Option, + /// HTTP requests to perform during startup snapshot creation. /// Apps can perform all the appropriate warmup logic in these requests. /// @@ -260,6 +281,33 @@ pub struct AppConfigCapabilityInstaBootV1 { pub max_age: Option, } +/// How will an instance be bootstrapped? +#[derive( + serde::Serialize, + serde::Deserialize, + PartialEq, + Eq, + Hash, + Clone, + Debug, + schemars::JsonSchema, + Default, +)] +#[serde(rename_all = "snake_case")] +pub enum InstabootSnapshotModeV1 { + /// Start the instance without any snapshot triggers. Once the requests are done, + /// use [`snapshot_and_stop`](wasmer_wasix::WasiProcess::snapshot_and_stop) to + /// capture a snapshot and shut the instance down. + #[default] + Bootstrap, + + /// Explicitly enable the given snapshot triggers before starting the instance. + /// The instance's process will have its stop_running_after_checkpoint flag set, + /// so the first snapshot will cause the instance to shut down. + // FIXME: make this strongly typed + Triggers(Vec), +} + /// App redirect configuration. #[derive( serde::Serialize, serde::Deserialize, schemars::JsonSchema, Clone, Debug, PartialEq, Eq, diff --git a/lib/wasix/src/runners/wasi_common.rs b/lib/wasix/src/runners/wasi_common.rs index 489bcb08f..dbd3a496e 100644 --- a/lib/wasix/src/runners/wasi_common.rs +++ b/lib/wasix/src/runners/wasi_common.rs @@ -14,7 +14,7 @@ use webc::metadata::annotations::Wasi as WasiAnnotation; use crate::{ bin_factory::BinaryPackage, capabilities::Capabilities, - journal::{self, DynJournal, DynReadableJournal, SnapshotTrigger}, + journal::{DynJournal, DynReadableJournal, SnapshotTrigger}, WasiEnvBuilder, };