Skip to content

Commit

Permalink
add chicken switch
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Oct 30, 2023
1 parent 7b21243 commit eac3319
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 2 deletions.
9 changes: 9 additions & 0 deletions common/src/nexus_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,12 @@ pub struct InventoryConfig {
/// This is a very coarse mechanism to keep the system from overwhelming
/// itself with inventory data.
pub nkeep: u32,

/// disable inventory collection altogether
///
/// This is an emergency lever for support / operations. It should never be
/// necessary.
pub disable: bool,
}

/// Configuration for a nexus server
Expand Down Expand Up @@ -615,6 +621,7 @@ mod test {
external_endpoints.period_secs = 9
inventory.period_secs = 10
inventory.nkeep = 11
inventory.disable = false
[default_region_allocation_strategy]
type = "random"
seed = 0
Expand Down Expand Up @@ -703,6 +710,7 @@ mod test {
inventory: InventoryConfig {
period_secs: Duration::from_secs(10),
nkeep: 11,
disable: false,
}
},
default_region_allocation_strategy:
Expand Down Expand Up @@ -758,6 +766,7 @@ mod test {
external_endpoints.period_secs = 9
inventory.period_secs = 10
inventory.nkeep = 3
inventory.disable = false
[default_region_allocation_strategy]
type = "random"
"##,
Expand Down
2 changes: 2 additions & 0 deletions nexus/examples/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ external_endpoints.period_secs = 60
inventory.period_secs = 600
# Maximum number of past collections to keep in the database
inventory.nkeep = 5
# Disable inventory collection altogether (for emergencies)
inventory.disable = false

[default_region_allocation_strategy]
# allocate region on 3 random distinct zpools, on 3 random distinct sleds.
Expand Down
1 change: 1 addition & 0 deletions nexus/src/app/background/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl BackgroundTasks {
resolver,
&nexus_id.to_string(),
config.inventory.nkeep,
config.inventory.disable,
);
let task = driver.register(
String::from("inventory_collection"),
Expand Down
32 changes: 30 additions & 2 deletions nexus/src/app/background/inventory_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! Background task for reading inventory for the rack
use super::common::BackgroundTask;
use anyhow::ensure;
use anyhow::Context;
use futures::future::BoxFuture;
use futures::FutureExt;
Expand All @@ -21,6 +22,7 @@ pub struct InventoryCollector {
resolver: internal_dns::resolver::Resolver,
creator: String,
nkeep: u32,
disable: bool,
}

impl InventoryCollector {
Expand All @@ -29,12 +31,14 @@ impl InventoryCollector {
resolver: internal_dns::resolver::Resolver,
creator: &str,
nkeep: u32,
disable: bool,
) -> InventoryCollector {
InventoryCollector {
datastore,
resolver,
creator: creator.to_owned(),
nkeep,
disable,
}
}
}
Expand All @@ -55,6 +59,7 @@ impl BackgroundTask for InventoryCollector {
&self.resolver,
&self.creator,
self.nkeep,
self.disable,
)
.await
.context("failed to collect inventory")
Expand Down Expand Up @@ -88,7 +93,12 @@ async fn inventory_activate(
resolver: &internal_dns::resolver::Resolver,
creator: &str,
nkeep: u32,
disabled: bool,
) -> Result<Collection, anyhow::Error> {
// If we're disabled, don't do anything. (This switch is only intended for
// unforeseen production emergencies.)
ensure!(!disabled, "disabled by explicit configuration");

// Prune old collections. We do this first, here, to ensure that we never
// develop an unbounded backlog of collections. (If this process were done
// by a separate task, it would be possible for the backlog to grow
Expand Down Expand Up @@ -185,8 +195,13 @@ mod test {
// a bunch and make sure that it always creates a new collection and
// does not allow a backlog to accumulate.
let nkeep = 3;
let mut task =
InventoryCollector::new(datastore.clone(), resolver, "me", nkeep);
let mut task = InventoryCollector::new(
datastore.clone(),
resolver.clone(),
"me",
nkeep,
false,
);
let nkeep = usize::try_from(nkeep).unwrap();
for i in 0..10 {
let _ = task.activate(&opctx).await;
Expand All @@ -208,5 +223,18 @@ mod test {
assert_eq!(collections.len(), std::cmp::min(i + 2, nkeep + 1));
last_collections = collections;
}

// Create a disabled task and make sure that does nothing.
let mut task = InventoryCollector::new(
datastore.clone(),
resolver,
"disabled",
3,
true,
);
let previous = datastore.inventory_collections().await.unwrap();
let _ = task.activate(&opctx).await;
let latest = datastore.inventory_collections().await.unwrap();
assert_eq!(previous, latest);
}
}
2 changes: 2 additions & 0 deletions nexus/tests/config.test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ external_endpoints.period_secs = 60
inventory.period_secs = 600
# Maximum number of past collections to keep in the database
inventory.nkeep = 3
# Disable inventory collection altogether (for emergencies)
inventory.disable = false

[default_region_allocation_strategy]
# we only have one sled in the test environment, so we need to use the
Expand Down
2 changes: 2 additions & 0 deletions smf/nexus/multi-sled/config-partial.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ external_endpoints.period_secs = 60
inventory.period_secs = 600
# Maximum number of past collections to keep in the database
inventory.nkeep = 3
# Disable inventory collection altogether (for emergencies)
inventory.disable = false

[default_region_allocation_strategy]
# by default, allocate across 3 distinct sleds
Expand Down
2 changes: 2 additions & 0 deletions smf/nexus/single-sled/config-partial.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ external_endpoints.period_secs = 60
inventory.period_secs = 600
# Maximum number of past collections to keep in the database
inventory.nkeep = 3
# Disable inventory collection altogether (for emergencies)
inventory.disable = false

[default_region_allocation_strategy]
# by default, allocate without requirement for distinct sleds.
Expand Down

0 comments on commit eac3319

Please sign in to comment.