Skip to content

Commit f56a10f

Browse files
committed
Summarise runtime config
Signed-off-by: itowlson <[email protected]>
1 parent adc1329 commit f56a10f

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

crates/trigger/src/cli.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use spin_common::{arg_parser::parse_kv, sloth};
99
use crate::network::Network;
1010
use crate::runtime_config::llm::LLmOptions;
1111
use crate::runtime_config::sqlite::SqlitePersistenceMessageHook;
12+
use crate::runtime_config::SummariseRuntimeConfigHook;
1213
use crate::stdio::StdioLoggingTriggerHooks;
1314
use crate::{
1415
loader::TriggerLoader,
@@ -208,6 +209,7 @@ where
208209

209210
builder.hooks(StdioLoggingTriggerHooks::new(self.follow_components()));
210211
builder.hooks(Network::default());
212+
builder.hooks(SummariseRuntimeConfigHook::new(&self.runtime_config_file));
211213
builder.hooks(KeyValuePersistenceMessageHook);
212214
builder.hooks(SqlitePersistenceMessageHook);
213215

crates/trigger/src/runtime_config.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use serde::Deserialize;
1515
use spin_common::ui::quoted_path;
1616
use spin_sqlite::Connection;
1717

18+
use crate::TriggerHooks;
19+
1820
use self::{
1921
key_value::{KeyValueStore, KeyValueStoreOpts},
2022
llm::LlmComputeOpts,
@@ -259,6 +261,77 @@ fn resolve_config_path(path: &Path, config_opts: &RuntimeConfigOpts) -> Result<P
259261
Ok(base_path.join(path))
260262
}
261263

264+
pub(crate) struct SummariseRuntimeConfigHook {
265+
runtime_config_file: Option<PathBuf>,
266+
}
267+
268+
impl SummariseRuntimeConfigHook {
269+
pub(crate) fn new(runtime_config_file: &Option<PathBuf>) -> Self {
270+
Self {
271+
runtime_config_file: runtime_config_file.clone(),
272+
}
273+
}
274+
}
275+
276+
impl TriggerHooks for SummariseRuntimeConfigHook {
277+
fn app_loaded(
278+
&mut self,
279+
_app: &spin_app::App,
280+
runtime_config: &RuntimeConfig,
281+
_resolver: &Arc<spin_expressions::PreparedResolver>,
282+
) -> anyhow::Result<()> {
283+
if let Some(path) = &self.runtime_config_file {
284+
let mut opts = vec![];
285+
for opt in runtime_config.opts_layers() {
286+
for (id, opt) in &opt.key_value_stores {
287+
opts.push(Self::summarise_kv(id, opt));
288+
}
289+
for (id, opt) in &opt.sqlite_databases {
290+
opts.push(Self::summarise_sqlite(id, opt));
291+
}
292+
for opt in &opt.llm_compute {
293+
opts.push(Self::summarise_llm(opt));
294+
}
295+
}
296+
if !opts.is_empty() {
297+
let opts_text = opts.join(", ");
298+
println!(
299+
"Using {opts_text} runtime config from {}",
300+
quoted_path(path)
301+
);
302+
}
303+
}
304+
Ok(())
305+
}
306+
}
307+
308+
impl SummariseRuntimeConfigHook {
309+
fn summarise_kv(id: &str, opt: &KeyValueStoreOpts) -> String {
310+
let source = match opt {
311+
KeyValueStoreOpts::Spin(_) => "spin",
312+
KeyValueStoreOpts::Redis(_) => "redis",
313+
KeyValueStoreOpts::AzureCosmos(_) => "cosmos",
314+
};
315+
format!("[key_value_store.{id}: {}]", source)
316+
}
317+
318+
fn summarise_sqlite(id: &str, opt: &SqliteDatabaseOpts) -> String {
319+
let source = match opt {
320+
SqliteDatabaseOpts::Spin(_) => "spin",
321+
SqliteDatabaseOpts::Libsql(_) => "libsql",
322+
};
323+
format!("[sqlite_database.{id}: {}]", source)
324+
}
325+
326+
fn summarise_llm(opt: &LlmComputeOpts) -> String {
327+
let source = match opt {
328+
LlmComputeOpts::Spin => "spin",
329+
LlmComputeOpts::RemoteHttp(_) => "remote-http",
330+
};
331+
format!("[llm_compute: {}]", source)
332+
}
333+
}
334+
262335
#[cfg(test)]
263336
mod tests {
264337
use std::io::Write;

0 commit comments

Comments
 (0)