File tree Expand file tree Collapse file tree 8 files changed +67
-1
lines changed Expand file tree Collapse file tree 8 files changed +67
-1
lines changed Original file line number Diff line number Diff line change @@ -119,6 +119,12 @@ pub struct AppState {
119
119
component_allowed_stores : HashMap < String , HashSet < String > > ,
120
120
}
121
121
122
+ impl AppState {
123
+ pub fn store_summary ( & self , label : & str ) -> Option < String > {
124
+ self . store_manager . summary ( label)
125
+ }
126
+ }
127
+
122
128
pub struct InstanceBuilder {
123
129
/// The store manager for the app.
124
130
///
Original file line number Diff line number Diff line change @@ -102,6 +102,14 @@ impl StoreManager for KeyValueAzureCosmos {
102
102
fn is_defined ( & self , _store_name : & str ) -> bool {
103
103
true
104
104
}
105
+
106
+ fn summary ( & self , _store_name : & str ) -> Option < String > {
107
+ let database = self . client . database_client ( ) . database_name ( ) ;
108
+ let collection = self . client . collection_name ( ) ;
109
+ Some ( format ! (
110
+ "Azure CosmosDB database: {database}, collection: {collection}"
111
+ ) )
112
+ }
105
113
}
106
114
107
115
struct AzureCosmosStore {
Original file line number Diff line number Diff line change @@ -47,6 +47,11 @@ impl StoreManager for KeyValueRedis {
47
47
fn is_defined ( & self , _store_name : & str ) -> bool {
48
48
true
49
49
}
50
+
51
+ fn summary ( & self , _store_name : & str ) -> Option < String > {
52
+ let redis:: ConnectionInfo { addr, .. } = self . database_url . as_str ( ) . parse ( ) . ok ( ) ?;
53
+ Some ( format ! ( "Redis at {addr}" ) )
54
+ }
50
55
}
51
56
52
57
struct RedisStore {
Original file line number Diff line number Diff line change @@ -68,6 +68,13 @@ impl StoreManager for KeyValueSqlite {
68
68
fn is_defined ( & self , _store_name : & str ) -> bool {
69
69
true
70
70
}
71
+
72
+ fn summary ( & self , _store_name : & str ) -> Option < String > {
73
+ Some ( match & self . location {
74
+ DatabaseLocation :: InMemory => "a temporary in-memory store" . into ( ) ,
75
+ DatabaseLocation :: Path ( path) => format ! ( "\" {}\" " , path. display( ) ) ,
76
+ } )
77
+ }
71
78
}
72
79
73
80
struct SqliteStore {
Original file line number Diff line number Diff line change @@ -23,6 +23,14 @@ pub use key_value::Error;
23
23
pub trait StoreManager : Sync + Send {
24
24
async fn get ( & self , name : & str ) -> Result < Arc < dyn Store > , Error > ;
25
25
fn is_defined ( & self , store_name : & str ) -> bool ;
26
+
27
+ /// A human-readable summary of the given store's configuration
28
+ ///
29
+ /// Example: "Redis at localhost:1234"
30
+ fn summary ( & self , store_name : & str ) -> Option < String > {
31
+ let _ = store_name;
32
+ None
33
+ }
26
34
}
27
35
28
36
#[ async_trait]
Original file line number Diff line number Diff line change @@ -66,6 +66,10 @@ impl StoreManager for DelegatingStoreManager {
66
66
fn is_defined ( & self , store_name : & str ) -> bool {
67
67
self . delegates . contains_key ( store_name)
68
68
}
69
+
70
+ fn summary ( & self , store_name : & str ) -> Option < String > {
71
+ ( self . default_manager ) ( store_name) ?. summary ( store_name)
72
+ }
69
73
}
70
74
71
75
/// Wrap each `Store` produced by the inner `StoreManager` in an asynchronous, write-behind cache.
@@ -122,6 +126,10 @@ impl<T: StoreManager> StoreManager for CachingStoreManager<T> {
122
126
fn is_defined ( & self , store_name : & str ) -> bool {
123
127
self . inner . is_defined ( store_name)
124
128
}
129
+
130
+ fn summary ( & self , store_name : & str ) -> Option < String > {
131
+ self . inner . summary ( store_name)
132
+ }
125
133
}
126
134
127
135
struct CachingStoreState {
Original file line number Diff line number Diff line change 1
1
mod launch_metadata;
2
+ mod summary;
2
3
3
4
use std:: future:: Future ;
4
5
use std:: path:: { Path , PathBuf } ;
@@ -12,6 +13,7 @@ use spin_common::{arg_parser::parse_kv, sloth};
12
13
use spin_core:: async_trait;
13
14
use spin_factors_executor:: { ComponentLoader , FactorsExecutor } ;
14
15
use spin_runtime_config:: { ResolvedRuntimeConfig , UserProvidedPath } ;
16
+ use summary:: KeyValueDefaultStoreSummaryHook ;
15
17
16
18
use crate :: factors:: { TriggerFactors , TriggerFactorsRuntimeConfig } ;
17
19
use crate :: stdio:: { FollowComponents , StdioLoggingExecutorHooks } ;
@@ -418,7 +420,7 @@ impl<T: Trigger> TriggerAppBuilder<T> {
418
420
) ) ;
419
421
// TODO:
420
422
// builder.hooks(SummariseRuntimeConfigHook::new(&self.runtime_config_file));
421
- // builder.hooks(KeyValuePersistenceMessageHook );
423
+ executor . add_hooks ( KeyValueDefaultStoreSummaryHook ) ;
422
424
// builder.hooks(SqlitePersistenceMessageHook);
423
425
424
426
let configured_app = {
Original file line number Diff line number Diff line change
1
+ use spin_factor_key_value:: KeyValueFactor ;
2
+ use spin_factors_executor:: ExecutorHooks ;
3
+
4
+ use crate :: factors:: TriggerFactors ;
5
+
6
+ pub struct KeyValueDefaultStoreSummaryHook ;
7
+
8
+ impl < U > ExecutorHooks < TriggerFactors , U > for KeyValueDefaultStoreSummaryHook {
9
+ fn configure_app (
10
+ & mut self ,
11
+ configured_app : & spin_factors:: ConfiguredApp < TriggerFactors > ,
12
+ ) -> anyhow:: Result < ( ) > {
13
+ if let Some ( default_store_summary) = configured_app
14
+ . app_state :: < KeyValueFactor > ( )
15
+ . ok ( )
16
+ . and_then ( |kv_state| kv_state. store_summary ( "default" ) )
17
+ {
18
+ println ! ( "Storing default key-value data to {default_store_summary}." ) ;
19
+ }
20
+ Ok ( ( ) )
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments