Skip to content
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

feat(*)!: surface application errors in status #379

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions crates/wadm/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
use wasmcloud_control_interface::InterfaceLinkDefinition;

use crate::{
events::{Event, ProviderStartFailed, ProviderStarted},
events::{ComponentScaleFailed, ComponentScaled, Event, ProviderStartFailed, ProviderStarted},
workers::insert_managed_annotations,
};

Expand Down Expand Up @@ -44,13 +44,14 @@ impl Command {
/// # Return
/// - The first element in the tuple corresponds to the "success" event a host would output after completing this command
/// - The second element in the tuple corresponds to an optional "failure" event that a host could output if processing fails
pub fn corresponding_event(&self, model_name: &str) -> Option<(Event, Option<Event>)> {
pub fn corresponding_event(&self) -> Option<(Event, Option<Event>)> {
match self {
Command::StartProvider(StartProvider {
annotations,
reference,
host_id,
provider_id,
model_name,
..
}) => {
let mut annotations = annotations.to_owned();
Expand All @@ -72,6 +73,39 @@ impl Command {
})),
))
}
Command::ScaleComponent(ScaleComponent {
component_id,
host_id,
count,
reference,
annotations,
model_name,
..
}) => {
let mut annotations = annotations.to_owned();
insert_managed_annotations(&mut annotations, model_name);
Some((
Event::ComponentScaled(ComponentScaled {
component_id: component_id.to_owned(),
host_id: host_id.to_owned(),
max_instances: *count as usize,
image_ref: reference.to_owned(),
annotations: annotations.to_owned(),
// We don't know this field from the command
claims: None,
}),
Some(Event::ComponentScaleFailed(ComponentScaleFailed {
component_id: component_id.to_owned(),
host_id: host_id.to_owned(),
max_instances: *count as usize,
image_ref: reference.to_owned(),
annotations: annotations.to_owned(),
// We don't know these fields from the command
error: String::with_capacity(0),
claims: None,
})),
))
}
_ => None,
}
}
Expand Down
4 changes: 0 additions & 4 deletions crates/wadm/src/events/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ pub struct ComponentScaled {
pub claims: Option<ComponentClaims>,
pub image_ref: String,
pub max_instances: usize,
// TODO: Once we update to the 1.0 release candidate, this will be component_id
pub component_id: String,
#[serde(default)]
pub host_id: String,
Expand All @@ -321,7 +320,6 @@ pub struct ComponentScaleFailed {
pub claims: Option<ComponentClaims>,
pub image_ref: String,
pub max_instances: usize,
// TODO: Once we update to the 1.0 release candidate, this will be component_id
pub component_id: String,
#[serde(default)]
pub host_id: String,
Expand Down Expand Up @@ -463,7 +461,6 @@ event_impl!(ConfigDeleted, "com.wasmcloud.lattice.config_deleted");
pub struct HostStarted {
pub labels: HashMap<String, String>,
pub friendly_name: String,
// TODO: Parse as nkey?
#[serde(default)]
pub id: String,
}
Expand All @@ -478,7 +475,6 @@ event_impl!(
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct HostStopped {
pub labels: HashMap<String, String>,
// TODO: Parse as nkey?
#[serde(default)]
pub id: String,
}
Expand Down
18 changes: 9 additions & 9 deletions crates/wadm/src/scaler/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use super::{
link::{LinkScaler, LinkScalerConfig},
provider::{ProviderSpreadConfig, ProviderSpreadScaler},
},
BackoffAwareScaler,
BackoffWrapper,
};

pub type BoxedScaler = Box<dyn Scaler + Send + Sync + 'static>;
Expand Down Expand Up @@ -504,7 +504,7 @@ where
// wrapped ones (which is good from a Rust API point of view). If
// this starts to become a problem, we can revisit how we handle
// this (probably by requiring that this struct always wraps any
// scaler in the backoff scaler and using custom methods from that
// scaler in the backoff wrapper and using custom methods from that
// type)
Notifications::RegisterExpectedEvents{ name, scaler_id, triggering_event } => {
trace!(%name, "Computing and registering expected events for manifest");
Expand Down Expand Up @@ -606,7 +606,7 @@ where
config_names.append(&mut secret_names.clone());
match (trt.trait_type.as_str(), &trt.properties) {
(SPREADSCALER_TRAIT, TraitProperty::SpreadScaler(p)) => {
Some(Box::new(BackoffAwareScaler::new(
Some(Box::new(BackoffWrapper::new(
ComponentSpreadScaler::new(
snapshot_data.clone(),
props.image.to_owned(),
Expand All @@ -626,7 +626,7 @@ where
)) as BoxedScaler)
}
(DAEMONSCALER_TRAIT, TraitProperty::SpreadScaler(p)) => {
Some(Box::new(BackoffAwareScaler::new(
Some(Box::new(BackoffWrapper::new(
ComponentDaemonScaler::new(
snapshot_data.clone(),
props.image.to_owned(),
Expand Down Expand Up @@ -682,7 +682,7 @@ where
| Properties::Component {
properties: ComponentProperties { id, .. },
} if component.name == p.target.name => {
Some(Box::new(BackoffAwareScaler::new(
Some(Box::new(BackoffWrapper::new(
LinkScaler::new(
snapshot_data.clone(),
LinkScalerConfig {
Expand Down Expand Up @@ -740,7 +740,7 @@ where
);
config_names.append(&mut secret_names.clone());

Some(Box::new(BackoffAwareScaler::new(
Some(Box::new(BackoffWrapper::new(
ProviderSpreadScaler::new(
snapshot_data.clone(),
ProviderSpreadConfig {
Expand Down Expand Up @@ -773,7 +773,7 @@ where
policies,
);
config_names.append(&mut secret_names.clone());
Some(Box::new(BackoffAwareScaler::new(
Some(Box::new(BackoffWrapper::new(
ProviderDaemonScaler::new(
snapshot_data.clone(),
ProviderSpreadConfig {
Expand Down Expand Up @@ -834,7 +834,7 @@ where
Properties::Component { properties: cappy }
if component.name == p.target.name =>
{
Some(Box::new(BackoffAwareScaler::new(
Some(Box::new(BackoffWrapper::new(
LinkScaler::new(
snapshot_data.clone(),
LinkScalerConfig {
Expand Down Expand Up @@ -883,7 +883,7 @@ where
secrets_to_scalers(snapshot_data.clone(), name, &props.secrets, policies);
config_names.append(&mut secret_names.clone());

scalers.push(Box::new(BackoffAwareScaler::new(
scalers.push(Box::new(BackoffWrapper::new(
ProviderSpreadScaler::new(
snapshot_data.clone(),
ProviderSpreadConfig {
Expand Down
Loading