From 203459f79a252aa65039d945ebdfce94c4ce8056 Mon Sep 17 00:00:00 2001 From: Jarrod Overson Date: Tue, 31 Oct 2023 19:17:23 -0400 Subject: [PATCH] fix: fixed max_import_size on imports --- crates/wick/wick-runtime/src/components.rs | 2 +- crates/wick/wick-runtime/src/runtime.rs | 4 ++++ .../src/runtime/scope/child_init.rs | 6 +++++- .../wick/wick-runtime/src/runtime/scope/init.rs | 17 +++++++++++++---- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/crates/wick/wick-runtime/src/components.rs b/crates/wick/wick-runtime/src/components.rs index 898374e6..f455dd47 100644 --- a/crates/wick/wick-runtime/src/components.rs +++ b/crates/wick/wick-runtime/src/components.rs @@ -146,7 +146,7 @@ pub(crate) async fn init_manifest_component( opts.rng_seed = rng.seed(); let uuid = rng.uuid(); - let _scope = init_child(uuid, manifest.clone(), id.clone(), opts).await?; + let _scope = init_child(uuid, manifest.clone(), id.clone(), opts, kind.max_packet_size()).await?; let component = Arc::new(scope_component::ScopeComponent::new(uuid)); let service = NativeComponentService::new(component); diff --git a/crates/wick/wick-runtime/src/runtime.rs b/crates/wick/wick-runtime/src/runtime.rs index 10e3a50f..27349799 100644 --- a/crates/wick/wick-runtime/src/runtime.rs +++ b/crates/wick/wick-runtime/src/runtime.rs @@ -41,6 +41,9 @@ pub struct RuntimeInit { #[builder(setter(custom = true))] pub(crate) initial_components: ComponentRegistry, + + #[builder(default)] + pub(crate) max_packet_size: Option, } impl Runtime { @@ -248,6 +251,7 @@ impl RuntimeBuilder { Runtime::new( seed.unwrap_or_else(new_seed), RuntimeInit { + max_packet_size: self.max_packet_size.flatten(), manifest: definition, allow_latest: self.allow_latest.unwrap_or_default(), allowed_insecure: self.allowed_insecure.unwrap_or_default(), diff --git a/crates/wick/wick-runtime/src/runtime/scope/child_init.rs b/crates/wick/wick-runtime/src/runtime/scope/child_init.rs index 23121418..a5a9a65f 100644 --- a/crates/wick/wick-runtime/src/runtime/scope/child_init.rs +++ b/crates/wick/wick-runtime/src/runtime/scope/child_init.rs @@ -17,16 +17,18 @@ pub(crate) struct ChildInit { pub(crate) allowed_insecure: Vec, pub(crate) root_config: Option, pub(crate) provided: Option, + pub(crate) max_packet_size: Option, #[allow(unused)] pub(crate) span: Span, } impl std::fmt::Debug for ChildInit { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("ComponentInitOptions") + f.debug_struct("ChildInit") .field("rng_seed", &self.rng_seed) .field("runtime_id", &self.runtime_id) .field("allow_latest", &self.allow_latest) + .field("max_packet_size", &self.max_packet_size) .field("allowed_insecure", &self.allowed_insecure) .field("root_config", &self.root_config) .field("provided", &self.provided.as_ref().map(|p| p.inner().keys())) @@ -39,6 +41,7 @@ pub(crate) fn init_child( manifest: ComponentConfiguration, namespace: String, opts: ChildInit, + max_packet_size: Option, ) -> BoxFuture<'static, Result> { let child_span = info_span!(parent:&opts.span,"scope",id=%namespace); let mut components = ComponentRegistry::default(); @@ -61,6 +64,7 @@ pub(crate) fn init_child( constraints: Default::default(), span: child_span, initial_components: components, + max_packet_size, }; let init = ScopeInit::new_with_id(Some(opts.runtime_id), uid, opts.rng_seed, config); diff --git a/crates/wick/wick-runtime/src/runtime/scope/init.rs b/crates/wick/wick-runtime/src/runtime/scope/init.rs index cd76de3e..53214ffb 100644 --- a/crates/wick/wick-runtime/src/runtime/scope/init.rs +++ b/crates/wick/wick-runtime/src/runtime/scope/init.rs @@ -27,6 +27,7 @@ pub(crate) struct ScopeInit { pub(crate) constraints: Vec, pub(crate) initial_components: ComponentRegistry, pub(crate) span: Span, + pub(crate) max_packet_size: Option, } impl ScopeInit { @@ -43,6 +44,7 @@ impl ScopeInit { constraints: config.constraints, initial_components: config.initial_components, span: config.span, + max_packet_size: config.max_packet_size, } } @@ -59,10 +61,16 @@ impl ScopeInit { constraints: config.constraints, initial_components: config.initial_components, span: config.span, + max_packet_size: config.max_packet_size, } } - pub(super) fn child_init(&self, root_config: Option, provided: Option) -> ChildInit { + pub(super) fn child_init( + &self, + root_config: Option, + provided: Option, + max_packet_size: Option, + ) -> ChildInit { ChildInit { rng_seed: self.rng.seed(), runtime_id: self.id, @@ -71,6 +79,7 @@ impl ScopeInit { allowed_insecure: self.allowed_insecure.clone(), provided, span: self.span.clone(), + max_packet_size, } } @@ -106,7 +115,7 @@ impl ScopeInit { Some(config.extends()) } else { // Instantiate non-composite component as an exposed, standalone component. - let child_init = self.child_init(self.manifest.root_config().cloned(), None); + let child_init = self.child_init(self.manifest.root_config().cloned(), None, self.max_packet_size); self .span @@ -120,7 +129,7 @@ impl ScopeInit { provided.insert(req.id().to_owned(), Entity::component(req.id()).url()); } - let component = init_impl(&self.manifest, ns.clone(), child_init, None, provided).await?; + let component = init_impl(&self.manifest, ns.clone(), child_init, self.max_packet_size, provided).await?; component.expose(); expect_signature_match( @@ -144,7 +153,7 @@ impl ScopeInit { ) -> Result { for binding in self.manifest.import() { let provided = generate_provides_handlers(binding.kind().provide(), &components)?; - let component_init = self.child_init(binding.kind().config().cloned(), Some(provided)); + let component_init = self.child_init(binding.kind().config().cloned(), Some(provided), self.max_packet_size); if let Some(component) = instantiate_import(binding, component_init, self.manifest.resolver()).await? { if let Some(extends) = extends { if extends.iter().any(|n| n == component.namespace()) {