Skip to content

Commit

Permalink
feat(*)!: prevent querying inventory for new heartbeat
Browse files Browse the repository at this point in the history
Signed-off-by: Brooks Townsend <[email protected]>

rip out last #191 artifact

Signed-off-by: Brooks Townsend <[email protected]>

cleanup

Signed-off-by: Brooks Townsend <[email protected]>
  • Loading branch information
brooksmtownsend committed Jan 10, 2024
1 parent 0686159 commit b66d9b3
Show file tree
Hide file tree
Showing 10 changed files with 724 additions and 679 deletions.
47 changes: 36 additions & 11 deletions src/events/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{
use cloudevents::{AttributesReader, Data, Event as CloudEvent, EventBuilder, EventBuilderV10};
use serde::{Deserialize, Serialize};
use thiserror::Error;
use wasmcloud_control_interface::{ActorDescription, LabelsMap, ProviderDescriptions};

use crate::model::Manifest;

Expand Down Expand Up @@ -553,27 +554,51 @@ event_impl!(
id
);

// TODO(#TODO): Remove once wasmCloud v0.82 is released
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum BackwardsCompatActors {
V81(HashMap<String, usize>),
V82(Vec<ActorDescription>),
}

// TODO(#TODO): Remove once wasmCloud v0.82 is released
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum BackwardsCompatProviders {
V81(Vec<ProviderInfo>),
V82(ProviderDescriptions),
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct HostHeartbeat {
pub actors: HashMap<String, usize>,
pub friendly_name: String,
pub labels: HashMap<String, String>,
/// Actors running on this host.
pub actors: BackwardsCompatActors,
/// Providers running on this host
pub providers: BackwardsCompatProviders,
/// The host's unique ID
#[serde(default, alias = "id")]
pub host_id: String,
/// The host's cluster issuer public key
#[serde(default)]
pub annotations: BTreeMap<String, String>,
pub providers: Vec<ProviderInfo>,
pub uptime_human: String,
pub uptime_seconds: usize,
pub issuer: String,
/// The host's human-readable friendly name
pub friendly_name: String,
/// The host's labels
pub labels: LabelsMap,
/// The host version
pub version: semver::Version,
// TODO: Parse as nkey?
#[serde(default)]
pub id: String,
/// The host uptime in human-readable form
pub uptime_human: String,
/// The host uptime in seconds
pub uptime_seconds: u64,
}

event_impl!(
HostHeartbeat,
"com.wasmcloud.lattice.host_heartbeat",
source,
id
host_id
);

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
Expand Down
16 changes: 5 additions & 11 deletions src/scaler/daemonscaler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ mod test {
actors: HashMap::new(),
friendly_name: "hey".to_string(),
labels: HashMap::new(),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand Down Expand Up @@ -633,7 +632,6 @@ mod test {
("cloud".to_string(), "fake".to_string()),
("region".to_string(), "us-brooks-1".to_string()),
]),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand All @@ -658,7 +656,6 @@ mod test {
("region".to_string(), "us-midwest-4".to_string()),
("label".to_string(), "value".to_string()),
]),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand All @@ -679,7 +676,6 @@ mod test {
("cloud".to_string(), "purgatory".to_string()),
("location".to_string(), "edge".to_string()),
]),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand Down Expand Up @@ -866,7 +862,6 @@ mod test {
("cloud".to_string(), "fake".to_string()),
("region".to_string(), "us-brooks-1".to_string()),
]),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand All @@ -888,7 +883,6 @@ mod test {
("region".to_string(), "us-brooks-1".to_string()),
("label".to_string(), "value".to_string()),
]),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand All @@ -901,10 +895,10 @@ mod test {
// Don't care about these events
assert!(blobby_daemonscaler
.handle_event(&Event::ProviderStarted(ProviderStarted {
annotations: BTreeMap::new(),
claims: ProviderClaims::default(),
contract_id: "".to_string(),
image_ref: "".to_string(),
annotations: BTreeMap::default(),
instance_id: "".to_string(),
link_name: "".to_string(),
public_key: "".to_string(),
Expand Down Expand Up @@ -939,18 +933,18 @@ mod test {

// Let a new host come online, should match the spread
let modifying_event = HostHeartbeat {
actors: HashMap::new(),
actors: crate::events::BackwardsCompatActors::V82(vec![]),
friendly_name: "hey".to_string(),
issuer: "".to_string(),
labels: HashMap::from_iter([
("cloud".to_string(), "purgatory".to_string()),
("location".to_string(), "edge".to_string()),
("region".to_string(), "us-brooks-1".to_string()),
]),
annotations: BTreeMap::new(),
providers: vec![],
providers: crate::events::BackwardsCompatProviders::V82(vec![]),
uptime_seconds: 123,
version: semver::Version::new(0, 63, 1),
id: host_id_three.to_string(),
host_id: host_id_three.to_string(),
uptime_human: "time_is_a_human_construct".to_string(),
};

Expand Down
2 changes: 0 additions & 2 deletions src/scaler/daemonscaler/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ mod test {
("cloud".to_string(), "fake".to_string()),
("region".to_string(), "us-noneofyourbusiness-1".to_string()),
]),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand All @@ -415,7 +414,6 @@ mod test {
("cloud".to_string(), "real".to_string()),
("region".to_string(), "us-yourhouse-1".to_string()),
]),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand Down
14 changes: 7 additions & 7 deletions src/scaler/spreadscaler/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,11 @@ mod test {
linkscaler_values_hash = compute_linkscaler_values_hash(&[("foo".to_string(), "nope".to_string())].into())
);

assert_ne!(scaler.id(), id, "LinkScaler ID should be different when scalers have different configured values");

assert_ne!(
scaler.id(),
id,
"LinkScaler ID should be different when scalers have different configured values"
);

let scaler = LinkScaler::new(
create_store(&lattice_id, &actor_ref, &provider_ref).await,
Expand All @@ -412,7 +415,6 @@ mod test {
provider_link_name = "default",
actor_reference = actor_ref,
provider_reference = provider_ref,

);

assert_eq!(scaler.id(), id, "LinkScaler ID should be the same when their type, model name, provider link name, actor reference, and provider reference are the same and they both have no values configured");
Expand All @@ -430,12 +432,10 @@ mod test {
);

assert_ne!(scaler.id(), id, "Expected LinkScaler values hash to differiantiate scalers with the same type, model name, provider link name, actor reference, and provider reference");
let mut scaler_id_tokens= scaler.id().split('-');
let mut scaler_id_tokens = scaler.id().split('-');
scaler_id_tokens.next_back();
let scaler_id_tokens = scaler_id_tokens.collect::<Vec<&str>>().join("-");
assert_eq!(scaler_id_tokens, id, "Excluding the values hash, the LinkScaler ID should be the same when scalers have the same type, model name, provider link name, actor reference, and provider reference");


}

#[tokio::test]
Expand Down Expand Up @@ -563,7 +563,7 @@ mod test {
("cloud".to_string(), "fake".to_string()),
("region".to_string(), "us-brooks-1".to_string()),
]),
annotations: BTreeMap::new(),

providers: HashSet::from_iter([ProviderInfo {
contract_id: "wasmcloud:httpserver".to_string(),
link_name: "default".to_string(),
Expand Down
14 changes: 3 additions & 11 deletions src/scaler/spreadscaler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,6 @@ mod test {
actors: HashMap::new(),
friendly_name: "hey".to_string(),
labels: HashMap::new(),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand Down Expand Up @@ -889,7 +888,6 @@ mod test {
("cloud".to_string(), "fake".to_string()),
("region".to_string(), "us-brooks-1".to_string()),
]),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand All @@ -914,7 +912,6 @@ mod test {
("region".to_string(), "us-midwest-4".to_string()),
("label".to_string(), "value".to_string()),
]),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand All @@ -935,7 +932,6 @@ mod test {
("cloud".to_string(), "purgatory".to_string()),
("location".to_string(), "edge".to_string()),
]),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand Down Expand Up @@ -1048,7 +1044,6 @@ mod test {
("region".to_string(), "east".to_string()),
("resilient".to_string(), "true".to_string()),
]),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand Down Expand Up @@ -1141,7 +1136,7 @@ mod test {
actors: HashMap::from_iter([(actor_id.to_string(), 10)]),
friendly_name: "hey".to_string(),
labels: HashMap::new(),
annotations: BTreeMap::new(),

providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand All @@ -1155,7 +1150,7 @@ mod test {
actors: HashMap::from_iter([(actor_id.to_string(), 10)]),
friendly_name: "hey2".to_string(),
labels: HashMap::new(),
annotations: BTreeMap::new(),

providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand Down Expand Up @@ -1369,7 +1364,6 @@ mod test {
("cloud".to_string(), "fake".to_string()),
("region".to_string(), "us-brooks-1".to_string()),
]),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand All @@ -1391,7 +1385,6 @@ mod test {
("region".to_string(), "us-midwest-4".to_string()),
("label".to_string(), "value".to_string()),
]),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand All @@ -1412,7 +1405,6 @@ mod test {
("cloud".to_string(), "purgatory".to_string()),
("location".to_string(), "edge".to_string()),
]),
annotations: BTreeMap::new(),
providers: HashSet::new(),
uptime_seconds: 123,
version: None,
Expand All @@ -1426,8 +1418,8 @@ mod test {
// Don't care about these events
assert!(blobby_spreadscaler
.handle_event(&Event::ProviderStarted(ProviderStarted {
annotations: BTreeMap::new(),
claims: ProviderClaims::default(),
annotations: BTreeMap::default(),
contract_id: "".to_string(),
image_ref: "".to_string(),
instance_id: "".to_string(),
Expand Down
Loading

0 comments on commit b66d9b3

Please sign in to comment.