Skip to content

Commit 09de9c3

Browse files
authored
Merge pull request #2788 from lann/summarize-runtime-config
Add summarize_runtime_config
2 parents fe39e66 + 55e5b89 commit 09de9c3

File tree

6 files changed

+53
-3
lines changed

6 files changed

+53
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/runtime-config/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pub struct ResolvedRuntimeConfig<T> {
4242
///
4343
/// `None` is used for an "unset" log directory.
4444
pub log_dir: Option<PathBuf>,
45+
/// The input TOML, for informational summaries.
46+
pub toml: toml::Table,
4547
}
4648

4749
impl<T> ResolvedRuntimeConfig<T>
@@ -140,6 +142,7 @@ where
140142
sqlite_resolver: sqlite_config_resolver,
141143
state_dir: toml_resolver.state_dir()?,
142144
log_dir: toml_resolver.log_dir()?,
145+
toml,
143146
})
144147
}
145148

crates/trigger/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ spin-runtime-config = { path = "../runtime-config" }
4343
spin-telemetry = { path = "../telemetry" }
4444
terminal = { path = "../terminal" }
4545
tokio = { version = "1.23", features = ["fs", "rt"] }
46+
toml = "0.8"
4647
tracing = { workspace = true }
4748

4849
[dev-dependencies]

crates/trigger/src/cli.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use spin_core::async_trait;
1515
use spin_factors_executor::{ComponentLoader, FactorsExecutor};
1616
use spin_runtime_config::{ResolvedRuntimeConfig, UserProvidedPath};
1717
use sqlite_statements::SqlStatementExecutorHook;
18-
use summary::{KeyValueDefaultStoreSummaryHook, SqliteDefaultStoreSummaryHook};
18+
use summary::{
19+
summarize_runtime_config, KeyValueDefaultStoreSummaryHook, SqliteDefaultStoreSummaryHook,
20+
};
1921

2022
use crate::factors::{TriggerFactors, TriggerFactorsRuntimeConfig};
2123
use crate::stdio::{FollowComponents, StdioLoggingExecutorHooks};
@@ -341,6 +343,8 @@ impl<T: Trigger> TriggerAppBuilder<T> {
341343
use_gpu,
342344
)?;
343345

346+
summarize_runtime_config(&runtime_config, runtime_config_path);
347+
344348
runtime_config
345349
.set_initial_key_values(&options.initial_key_values)
346350
.await?;
@@ -421,8 +425,6 @@ impl<T: Trigger> TriggerAppBuilder<T> {
421425
options.follow_components,
422426
log_dir,
423427
));
424-
// TODO:
425-
// builder.hooks(SummariseRuntimeConfigHook::new(&self.runtime_config_file));
426428
executor.add_hooks(KeyValueDefaultStoreSummaryHook);
427429
executor.add_hooks(SqliteDefaultStoreSummaryHook);
428430
executor.add_hooks(SqlStatementExecutorHook::new(options.sqlite_statements));

crates/trigger/src/cli/summary.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,52 @@
1+
use std::path::Path;
2+
3+
use spin_common::ui::quoted_path;
14
use spin_core::async_trait;
25
use spin_factor_key_value::KeyValueFactor;
36
use spin_factor_sqlite::SqliteFactor;
47
use spin_factors_executor::ExecutorHooks;
8+
use spin_runtime_config::ResolvedRuntimeConfig;
9+
use toml::Value;
510

611
use crate::factors::TriggerFactors;
712

13+
pub fn summarize_runtime_config<T>(
14+
runtime_config: &ResolvedRuntimeConfig<T>,
15+
runtime_config_path: Option<&Path>,
16+
) {
17+
let toml = &runtime_config.toml;
18+
let summarize_labeled_typed_tables = |key| {
19+
let mut summaries = vec![];
20+
if let Some(tables) = toml.get(key).and_then(Value::as_table) {
21+
for (label, config) in tables {
22+
if let Some(ty) = config.get("type").and_then(Value::as_str) {
23+
summaries.push(format!("[{key}.{label}: {ty}]"))
24+
}
25+
}
26+
}
27+
summaries
28+
};
29+
30+
let mut summaries = vec![];
31+
// [key_value_store.<label>: <type>]
32+
summaries.extend(summarize_labeled_typed_tables("key_value_store"));
33+
// [sqlite_database.<label>: <type>]
34+
summaries.extend(summarize_labeled_typed_tables("sqlite_database"));
35+
// [llm_compute: <type>]
36+
if let Some(table) = toml.get("llm_compute").and_then(Value::as_table) {
37+
if let Some(ty) = table.get("type").and_then(Value::as_str) {
38+
summaries.push(format!("[llm_compute: {ty}"));
39+
}
40+
}
41+
if !summaries.is_empty() {
42+
let summaries = summaries.join(", ");
43+
let from_path = runtime_config_path
44+
.map(|path| format!("from {}", quoted_path(path)))
45+
.unwrap_or_default();
46+
println!("Using runtime config {summaries} {from_path}");
47+
}
48+
}
49+
850
/// An [`ExecutorHooks`] that prints information about the default KV store.
951
pub struct KeyValueDefaultStoreSummaryHook;
1052

examples/spin-timer/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)