-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Trigger
trait generic over RuntimeFactors
#2790
Conversation
crates/runtime-config/src/lib.rs
Outdated
@@ -19,7 +19,9 @@ use spin_factors::runtime_config::toml::GetTomlValue as _; | |||
use spin_factors::{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file can largely be ignored for review should you wish to as it's mostly just surface level refactoring.
let mut core_engine_builder = { | ||
self.trigger.update_core_config(&mut self.engine_config)?; | ||
|
||
spin_core::Engine::builder(&self.engine_config)? | ||
}; | ||
self.trigger.add_to_linker(core_engine_builder.linker())?; | ||
|
||
let runtime_config_path = options.runtime_config_file; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this logic has been moved to the RuntimeFactorsBuilder
implementation in spin-cli
.
@@ -0,0 +1,42 @@ | |||
use anyhow::Context as _; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file might seem to be an unnecessary change, but it was the easiest way to continue to support setting key-value pairs on start up. I imagine even if we don't accept this PR, we'll want to implement this change.
|
||
use crate::factors::TriggerFactors; | ||
|
||
pub fn summarize_runtime_config<T>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this has been moved to the spin-cli
crate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conceptually, I am 100% in favor of this change — it is a huge step in the direction of allowing embedders to assemble their own runtime that makes zero assumptions about the world they are targeting (and more specifically, making it trivial to build a trigger that does not implicitly assume the Spin world).
Thank you for the work that went into this!
(I plan to review in more detail and test this soon, but wanted to share my initial thoughts early on)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initial pass
let app_variables = trigger_app | ||
.configured_app() | ||
.app_state::<VariablesFactor>() | ||
.context("RedisTrigger depends on VariablesFactor")?; | ||
|
||
let app = trigger_app.app(); | ||
let trigger_type = <Self as Trigger<F>>::TYPE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could probably avoid this awkwardness by adding a Trigger::trigger_type() -> &'static str
method. 🤷
@@ -0,0 +1,41 @@ | |||
[package] | |||
name = "spin-runtime-factors" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably need a different name here given that RuntimeFactors
is already a thing...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fully agree. I'd love to have a succienct way to differentiate between generic "any Spin runtime code" vs. code specific to a specific runtime. One could be tempted to call this spin-cli-runtime-factors
, but I think that's almost too specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been thinking that "the spin up
runtime" might be a good way to refer to this most-opinionated layer of the runtime. Maybe spin-up-runtime-factors
here?
9fef2b1
to
c661f97
Compare
@@ -46,82 +49,85 @@ pub struct ResolvedRuntimeConfig<T> { | |||
pub toml: toml::Table, | |||
} | |||
|
|||
impl<T> ResolvedRuntimeConfig<T> { | |||
pub fn summarize(&self, runtime_config_path: Option<&Path>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving this code here seems a bit odd. Is this crate intended to be tightly coupled to the Spin CLI?
If it stays here, maybe rename to something like print_summary
to make its purpose more clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I agree - though the inlining it is also not great. If someone wants to create an alternate RuntimeFactorsBuilder
and still print out this summary (which I would expect since they're already going to get all other logging for free), they'll have to copy this code from the spin-runtime-factors
crate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this more - I think as the crate stands today, this is the best place for this. This has a high chance to change though as we start tweaking things.
@@ -0,0 +1,41 @@ | |||
[package] | |||
name = "spin-runtime-factors" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been thinking that "the spin up
runtime" might be a good way to refer to this most-opinionated layer of the runtime. Maybe spin-up-runtime-factors
here?
c661f97
to
de1172b
Compare
Signed-off-by: Ryan Levick <[email protected]>
Signed-off-by: Ryan Levick <[email protected]>
Signed-off-by: Ryan Levick <[email protected]>
Signed-off-by: Ryan Levick <[email protected]>
Signed-off-by: Ryan Levick <[email protected]>
Signed-off-by: Ryan Levick <[email protected]>
Signed-off-by: Ryan Levick <[email protected]>
Signed-off-by: Ryan Levick <[email protected]>
Signed-off-by: Ryan Levick <[email protected]>
Signed-off-by: Ryan Levick <[email protected]>
Signed-off-by: Lann Martin <[email protected]>
Signed-off-by: Ryan Levick <[email protected]>
Signed-off-by: Ryan Levick <[email protected]>
de1172b
to
786e803
Compare
For the Spin CLI this change should be a no-op, but it does open up lots of possibilities for future changes including custom runtimes that benefit from all generic functionality Spin has (e.g., logging, telemetry, etc.) without having to opt into a specific wit world all guests must target.
The main change is that
Trigger
is now generic theRuntimeFactors
type. This means that the set ofFactor
s a Spin runtime can support is no longer hard coded to theTriggerFactors
type (which contains implementations for thefermyon:spin/imports
world). The decision of whichRuntimeFactors
type to use is pushed all the way to the edge of the system. Now thespin-cli
crate is whereTriggerFactors
is plugged in. In the future, we may add configuration knobs to tweak whichRuntimeFactors
type gets plugged in allowing users of the Spin runtime to decide what worlds they wish to support.The
HttpTrigger
andRedisTrigger
are now also generic overRuntimeFactors
meaning that they should be easily pluggable into custom runtimes. Making triggers generic over whichRuntimeFactors
they support should be easy, but it also allows hardcoding that decision should the trigger author wish to do so.The key to all of this working is the
RuntimeFactorsBuilder
which makes constructing and configuring aRuntimeFactors
type generic. This includes the ability for implementors of this trait to specify custom CLI arguments that are just used for configuring theRuntimeFactors
type.In the generic trigger code, there are a few places where a
RuntimeFactors
type is expected to have a certainFactor
in its collection. This has been changed to a dynamic query that allows generic code to do something if aRuntimeFactors
contains a certainFactor
. This is accomplished through the newHasInstanceBuilder
trait.