From 55e5b893afd71260fc921eb846064abf2670b84a Mon Sep 17 00:00:00 2001 From: Lann Martin Date: Thu, 29 Aug 2024 14:33:38 -0400 Subject: [PATCH] Add summarize_runtime_config Signed-off-by: Lann Martin --- Cargo.lock | 1 + crates/runtime-config/src/lib.rs | 3 +++ crates/trigger/Cargo.toml | 1 + crates/trigger/src/cli.rs | 8 +++--- crates/trigger/src/cli/summary.rs | 42 +++++++++++++++++++++++++++++++ examples/spin-timer/Cargo.lock | 1 + 6 files changed, 53 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d29228be9..ad3850d08f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7984,6 +7984,7 @@ dependencies = [ "tempfile", "terminal", "tokio", + "toml 0.8.14", "tracing", ] diff --git a/crates/runtime-config/src/lib.rs b/crates/runtime-config/src/lib.rs index 2691ec4aa7..22484c4092 100644 --- a/crates/runtime-config/src/lib.rs +++ b/crates/runtime-config/src/lib.rs @@ -42,6 +42,8 @@ pub struct ResolvedRuntimeConfig { /// /// `None` is used for an "unset" log directory. pub log_dir: Option, + /// The input TOML, for informational summaries. + pub toml: toml::Table, } impl ResolvedRuntimeConfig @@ -140,6 +142,7 @@ where sqlite_resolver: sqlite_config_resolver, state_dir: toml_resolver.state_dir()?, log_dir: toml_resolver.log_dir()?, + toml, }) } diff --git a/crates/trigger/Cargo.toml b/crates/trigger/Cargo.toml index 9f92388555..66fb9a7646 100644 --- a/crates/trigger/Cargo.toml +++ b/crates/trigger/Cargo.toml @@ -43,6 +43,7 @@ spin-runtime-config = { path = "../runtime-config" } spin-telemetry = { path = "../telemetry" } terminal = { path = "../terminal" } tokio = { version = "1.23", features = ["fs", "rt"] } +toml = "0.8" tracing = { workspace = true } [dev-dependencies] diff --git a/crates/trigger/src/cli.rs b/crates/trigger/src/cli.rs index d2d25ce99b..c3defd6964 100644 --- a/crates/trigger/src/cli.rs +++ b/crates/trigger/src/cli.rs @@ -15,7 +15,9 @@ use spin_core::async_trait; use spin_factors_executor::{ComponentLoader, FactorsExecutor}; use spin_runtime_config::{ResolvedRuntimeConfig, UserProvidedPath}; use sqlite_statements::SqlStatementExecutorHook; -use summary::{KeyValueDefaultStoreSummaryHook, SqliteDefaultStoreSummaryHook}; +use summary::{ + summarize_runtime_config, KeyValueDefaultStoreSummaryHook, SqliteDefaultStoreSummaryHook, +}; use crate::factors::{TriggerFactors, TriggerFactorsRuntimeConfig}; use crate::stdio::{FollowComponents, StdioLoggingExecutorHooks}; @@ -341,6 +343,8 @@ impl TriggerAppBuilder { use_gpu, )?; + summarize_runtime_config(&runtime_config, runtime_config_path); + runtime_config .set_initial_key_values(&options.initial_key_values) .await?; @@ -421,8 +425,6 @@ impl TriggerAppBuilder { options.follow_components, log_dir, )); - // TODO: - // builder.hooks(SummariseRuntimeConfigHook::new(&self.runtime_config_file)); executor.add_hooks(KeyValueDefaultStoreSummaryHook); executor.add_hooks(SqliteDefaultStoreSummaryHook); executor.add_hooks(SqlStatementExecutorHook::new(options.sqlite_statements)); diff --git a/crates/trigger/src/cli/summary.rs b/crates/trigger/src/cli/summary.rs index 50906daf5f..f8e21eb39a 100644 --- a/crates/trigger/src/cli/summary.rs +++ b/crates/trigger/src/cli/summary.rs @@ -1,10 +1,52 @@ +use std::path::Path; + +use spin_common::ui::quoted_path; use spin_core::async_trait; use spin_factor_key_value::KeyValueFactor; use spin_factor_sqlite::SqliteFactor; use spin_factors_executor::ExecutorHooks; +use spin_runtime_config::ResolvedRuntimeConfig; +use toml::Value; use crate::factors::TriggerFactors; +pub fn summarize_runtime_config( + runtime_config: &ResolvedRuntimeConfig, + runtime_config_path: Option<&Path>, +) { + let toml = &runtime_config.toml; + let summarize_labeled_typed_tables = |key| { + let mut summaries = vec![]; + if let Some(tables) = toml.get(key).and_then(Value::as_table) { + for (label, config) in tables { + if let Some(ty) = config.get("type").and_then(Value::as_str) { + summaries.push(format!("[{key}.{label}: {ty}]")) + } + } + } + summaries + }; + + let mut summaries = vec![]; + // [key_value_store.