Skip to content

Commit

Permalink
trigger inventory collection after blueprint execution (#5130)
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco authored Feb 26, 2024
1 parent 7fae994 commit d7db26d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
11 changes: 10 additions & 1 deletion nexus/src/app/background/blueprint_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct BlueprintExecutor {
datastore: Arc<DataStore>,
rx_blueprint: watch::Receiver<Option<Arc<(BlueprintTarget, Blueprint)>>>,
nexus_label: String,
tx: watch::Sender<usize>,
}

impl BlueprintExecutor {
Expand All @@ -30,7 +31,12 @@ impl BlueprintExecutor {
>,
nexus_label: String,
) -> BlueprintExecutor {
BlueprintExecutor { datastore, rx_blueprint, nexus_label }
let (tx, _) = watch::channel(0);
BlueprintExecutor { datastore, rx_blueprint, nexus_label, tx }
}

pub fn watcher(&self) -> watch::Receiver<usize> {
self.tx.subscribe()
}
}

Expand Down Expand Up @@ -71,6 +77,9 @@ impl BackgroundTask for BlueprintExecutor {
)
.await;

// Trigger anybody waiting for this to finish.
self.tx.send_modify(|count| *count = *count + 1);

// Return the result as a `serde_json::Value`
match result {
Ok(()) => json!({}),
Expand Down
56 changes: 32 additions & 24 deletions nexus/src/app/background/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,30 +170,6 @@ impl BackgroundTasks {
)
};

// Background task: inventory collector
let task_inventory_collection = {
let collector = inventory_collection::InventoryCollector::new(
datastore.clone(),
resolver,
&nexus_id.to_string(),
config.inventory.nkeep,
config.inventory.disable,
);
let task = driver.register(
String::from("inventory_collection"),
String::from(
"collects hardware and software inventory data from the \
whole system",
),
config.inventory.period_secs,
Box::new(collector),
opctx.child(BTreeMap::new()),
vec![],
);

task
};

// Background task: phantom disk detection
let task_phantom_disks = {
let detector =
Expand Down Expand Up @@ -230,6 +206,7 @@ impl BackgroundTasks {
rx_blueprint.clone(),
nexus_id.to_string(),
);
let rx_blueprint_exec = blueprint_executor.watcher();
let task_blueprint_executor = driver.register(
String::from("blueprint_executor"),
String::from("Executes the target blueprint"),
Expand All @@ -239,6 +216,37 @@ impl BackgroundTasks {
vec![Box::new(rx_blueprint)],
);

// Background task: inventory collector
//
// This currently depends on the "output" of the blueprint executor in
// order to automatically trigger inventory collection whenever the
// blueprint executor runs. In the limit, this could become a problem
// because the blueprint executor might also depend indirectly on the
// inventory collector. In that case, we may need to do something more
// complicated. But for now, this works.
let task_inventory_collection = {
let collector = inventory_collection::InventoryCollector::new(
datastore.clone(),
resolver,
&nexus_id.to_string(),
config.inventory.nkeep,
config.inventory.disable,
);
let task = driver.register(
String::from("inventory_collection"),
String::from(
"collects hardware and software inventory data from the \
whole system",
),
config.inventory.period_secs,
Box::new(collector),
opctx.child(BTreeMap::new()),
vec![Box::new(rx_blueprint_exec)],
);

task
};

let task_service_zone_nat_tracker = {
driver.register(
"service_zone_nat_tracker".to_string(),
Expand Down

0 comments on commit d7db26d

Please sign in to comment.