Skip to content

Add bg task for collecting chicken switches from DB #8462

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

andrewjstone
Copy link
Contributor

Wire up the task watcher into the planner so that it only runs when the planner_enabled switch is set to `true.

Fixes #8253

Wire up the task watcher into the planner so that it only runs when the
`planner_enabled` switch is set to `true.

Fixes #8253
@andrewjstone andrewjstone requested a review from jgallagher June 26, 2025 19:16
@andrewjstone
Copy link
Contributor Author

Manual testing:

➜  omicron git:(ajs/chicken-switch-bg-task) cargo run -p omicron-omdb nexus --nexus-internal-url='http://[::1]:12221' chicken-switches show current
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.87s
     Running `target/debug/omdb nexus '--nexus-internal-url=http://[::1]:12221' chicken-switches show current`
note: using Nexus URL http://[::1]:12221
No chicken switches enabled

➜  omicron git:(ajs/chicken-switch-bg-task) cargo run -p omicron-omdb nexus --nexus-internal-url='http://[::1]:12221' background-tasks show blueprint_planner
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.78s
     Running `target/debug/omdb nexus '--nexus-internal-url=http://[::1]:12221' background-tasks show blueprint_planner`
note: using Nexus URL http://[::1]:12221
task: "blueprint_planner"
  configured period: every 1m
  currently executing: no
  last completed activation: iter 8, triggered by a periodic timer firing
    started at 2025-06-26T21:23:41.949Z (16s ago) and ran for 0ms
    blueprint planning explicitly disabled by config!
    
➜  omicron git:(ajs/chicken-switch-bg-task) cargo run -p omicron-omdb nexus --nexus-internal-url='http://[::1]:12221' chicken-switches set --planner-enabled true -w
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.86s
     Running `target/debug/omdb nexus '--nexus-internal-url=http://[::1]:12221' chicken-switches set --planner-enabled true -w`
note: using Nexus URL http://[::1]:12221
Chicken switches updated at version 1

➜  omicron git:(ajs/chicken-switch-bg-task) cargo run -p omicron-omdb nexus --nexus-internal-url='http://[::1]:12221' chicken-switches show current
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.78s
     Running `target/debug/omdb nexus '--nexus-internal-url=http://[::1]:12221' chicken-switches show current`
note: using Nexus URL http://[::1]:12221
Reconfigurator Chicken Switches:
    version: 1
    modified time: 2025-06-26 21:24:31.546880 UTC
    planner enabled: true

➜  omicron git:(ajs/chicken-switch-bg-task) cargo run -p omicron-omdb nexus --nexus-internal-url='http://[::1]:12221' background-tasks show blueprint_planner
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.81s
     Running `target/debug/omdb nexus '--nexus-internal-url=http://[::1]:12221' background-tasks show blueprint_planner`
note: using Nexus URL http://[::1]:12221
task: "blueprint_planner"
  configured period: every 1m
  currently executing: no
  last completed activation: iter 11, triggered by a dependent task completing
    started at 2025-06-26T21:24:42.200Z (23s ago) and ran for 99ms
    plan unchanged from parent 0a6670a1-ccf9-4062-be6d-5f6e6821e644
    
➜  omicron git:(ajs/chicken-switch-bg-task) cargo run -p omicron-omdb nexus --nexus-internal-url='http://[::1]:12221' chicken-switches set --planner-enabled false -w
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.82s
     Running `target/debug/omdb nexus '--nexus-internal-url=http://[::1]:12221' chicken-switches set --planner-enabled false -w`
note: using Nexus URL http://[::1]:12221
Chicken switches updated at version 2

➜  omicron git:(ajs/chicken-switch-bg-task) cargo run -p omicron-omdb nexus --nexus-internal-url='http://[::1]:12221' chicken-switches show current
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.80s
     Running `target/debug/omdb nexus '--nexus-internal-url=http://[::1]:12221' chicken-switches show current`
note: using Nexus URL http://[::1]:12221
Reconfigurator Chicken Switches:
    version: 2
    modified time: 2025-06-26 21:25:38.912297 UTC
    planner enabled: false

➜  omicron git:(ajs/chicken-switch-bg-task) cargo run -p omicron-omdb nexus --nexus-internal-url='http://[::1]:12221' background-tasks show blueprint_planner
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.94s
     Running `target/debug/omdb nexus '--nexus-internal-url=http://[::1]:12221' background-tasks show blueprint_planner`
note: using Nexus URL http://[::1]:12221
task: "blueprint_planner"
  configured period: every 1m
  currently executing: no
  last completed activation: iter 13, triggered by a dependent task completing
    started at 2025-06-26T21:25:42.178Z (0s ago) and ran for 0ms
    blueprint planning explicitly disabled by config!
    
➜  omicron git:(ajs/chicken-switch-bg-task) cargo run -p omicron-omdb nexus --nexus-internal-url='http://[::1]:12221' chicken-switches show 1
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.78s
     Running `target/debug/omdb nexus '--nexus-internal-url=http://[::1]:12221' chicken-switches show 1`
note: using Nexus URL http://[::1]:12221
Reconfigurator Chicken Switches:
    version: 1
    modified time: 2025-06-26 21:24:31.546880 UTC
    planner enabled: true

ChickenSwitchesCollector::new(datastore.clone());
let chicken_switches_watcher = chicken_switches_collector.watcher();
driver.register(TaskDefinition {
name: "chickens_switches_watcher",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: "chickens_switches_watcher",
name: "chicken_switches_watcher",

Copy link
Contributor

@jgallagher jgallagher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just some minor nits 👍

@@ -441,6 +441,8 @@ pub struct BackgroundTaskConfig {
pub webhook_deliverator: WebhookDeliveratorConfig,
/// configuration for SP ereport ingester task
pub sp_ereport_ingester: SpEreportIngesterConfig,
/// reconfigurator runtime configuration
pub chicken_switches: ChickenSwitchesConfig,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit - should these live under BlueprintTasksConfig? So in the TOML, it'd be something like

blueprint.chicken_switches.loader_period_secs = N

or if we only expect this to ever really have the period, maybe eliminate the ChickenSwitchesConfig struct and make it

blueprints.chicken_switches_loader_period_secs = N


impl Default for ChickenSwitchesConfig {
fn default() -> Self {
Self { period_secs: Duration::from_secs(5) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a default? (If yes, why is it 5 here but 30 in the config files?)

@@ -48,6 +48,7 @@ pub struct BackgroundTasks {
pub task_alert_dispatcher: Activator,
pub task_webhook_deliverator: Activator,
pub task_sp_ereport_ingester: Activator,
pub task_chicken_switches_collector: Activator,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit - maybe

Suggested change
pub task_chicken_switches_collector: Activator,
pub task_chicken_switches_loader: Activator,

I'm not sure we've been consistent with this, but I'd expect "_collector" to be a task that goes out and collects things (e.g., inventory), vs "_loader" is a task that reads stuff from the DB.

@@ -24,7 +25,7 @@ use tokio::sync::watch::{self, Receiver, Sender};
/// Background task that runs the update planner.
pub struct BlueprintPlanner {
datastore: Arc<DataStore>,
disabled: bool,
rx_chicken_switches: Receiver<Option<ReconfiguratorChickenSwitches>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why this is an Option, but does it need to be? Presumably for every possible chicken switch, we have some default value (i.e., the thing we'd choose if this is None). Could we populate the channel with a ReconfiguratorChickenSwitches with those values set to avoid having to deal with None at all in this task?

Oh, as I write that I guess we don't have a default for version. How gross would it be to fill in a version: 0 for this "made up default" set of switches?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

runtime configurability for Reconfigurator
3 participants