Skip to content

Commit 38daa6e

Browse files
authored
Add reconfigurator chicken-switch-history to omdb (#8465)
1 parent 44f83c9 commit 38daa6e

File tree

2 files changed

+83
-5
lines changed

2 files changed

+83
-5
lines changed

dev-tools/omdb/src/bin/omdb/reconfigurator.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,24 @@ use diesel::ExpressionMethods;
1616
use diesel::QueryDsl;
1717
use diesel::SelectableHelper;
1818
use nexus_db_model::BpTarget;
19+
use nexus_db_model::SqlU32;
1920
use nexus_db_queries::authz;
2021
use nexus_db_queries::context::OpContext;
2122
use nexus_db_queries::db::DataStore;
2223
use nexus_db_queries::db::datastore::SQL_BATCH_SIZE;
2324
use nexus_db_queries::db::pagination::Paginator;
2425
use nexus_types::deployment::Blueprint;
2526
use nexus_types::deployment::BlueprintMetadata;
27+
use nexus_types::deployment::ReconfiguratorChickenSwitches;
2628
use nexus_types::deployment::UnstableReconfiguratorState;
2729
use omicron_common::api::external::Error;
2830
use omicron_common::api::external::LookupType;
2931
use omicron_uuid_kinds::BlueprintUuid;
3032
use omicron_uuid_kinds::GenericUuid;
3133
use slog::Logger;
3234
use std::collections::BTreeMap;
35+
use std::num::NonZeroU32;
36+
use tabled::Tabled;
3337

3438
/// Arguments to the "omdb reconfigurator" subcommand
3539
#[derive(Debug, Args)]
@@ -53,6 +57,8 @@ enum ReconfiguratorCommands {
5357
Archive(ExportArgs),
5458
/// Show recent history of blueprints
5559
History(HistoryArgs),
60+
/// Show the recent history of chicken switch settings
61+
ChickenSwitchesHistory(ChickenSwitchesHistoryArgs),
5662
}
5763

5864
#[derive(Debug, Args, Clone)]
@@ -61,6 +67,13 @@ struct ExportArgs {
6167
output_file: Utf8PathBuf,
6268
}
6369

70+
#[derive(Debug, Args, Clone)]
71+
struct ChickenSwitchesHistoryArgs {
72+
/// how far back in the history to show (number of targets)
73+
#[clap(long, default_value_t = 128)]
74+
limit: u32,
75+
}
76+
6477
#[derive(Debug, Args, Clone)]
6578
struct HistoryArgs {
6679
/// how far back in the history to show (number of targets)
@@ -111,6 +124,12 @@ impl ReconfiguratorArgs {
111124
)
112125
.await
113126
}
127+
ReconfiguratorCommands::ChickenSwitchesHistory(args) => {
128+
cmd_reconfigurator_chicken_switches_history(
129+
&opctx, &datastore, args,
130+
)
131+
.await
132+
}
114133
},
115134
)
116135
.await
@@ -352,6 +371,64 @@ async fn cmd_reconfigurator_history(
352371

353372
Ok(())
354373
}
374+
/// Show recent history of chicken switches
375+
async fn cmd_reconfigurator_chicken_switches_history(
376+
opctx: &OpContext,
377+
datastore: &DataStore,
378+
history_args: &ChickenSwitchesHistoryArgs,
379+
) -> anyhow::Result<()> {
380+
let mut history = vec![];
381+
let limit = history_args.limit;
382+
let batch_size = NonZeroU32::min(limit.try_into().unwrap(), SQL_BATCH_SIZE);
383+
let mut paginator = Paginator::<SqlU32>::new(
384+
batch_size,
385+
dropshot::PaginationOrder::Descending,
386+
);
387+
while let Some(p) = paginator.next() {
388+
if history.len() >= limit as usize {
389+
break;
390+
}
391+
let batch = datastore
392+
.reconfigurator_chicken_switches_list(opctx, &p.current_pagparams())
393+
.await
394+
.context("batch of chicken switches")?;
395+
paginator = p.found_batch(&batch, &|b| SqlU32::new(b.version));
396+
history.extend(batch.into_iter());
397+
}
398+
399+
#[derive(Tabled)]
400+
#[tabled(rename_all = "SCREAMING_SNAKE_CASE")]
401+
struct SwitchesRow {
402+
version: String,
403+
planner_enabled: String,
404+
time_modified: String,
405+
}
406+
407+
let rows: Vec<_> = history
408+
.into_iter()
409+
.map(|s| {
410+
let ReconfiguratorChickenSwitches {
411+
version,
412+
planner_enabled,
413+
time_modified,
414+
} = s;
415+
SwitchesRow {
416+
version: version.to_string(),
417+
planner_enabled: planner_enabled.to_string(),
418+
time_modified: time_modified.to_string(),
419+
}
420+
})
421+
.collect();
422+
423+
let table = tabled::Table::new(rows)
424+
.with(tabled::settings::Style::empty())
425+
.with(tabled::settings::Padding::new(0, 1, 0, 0))
426+
.to_string();
427+
428+
println!("{}", table);
429+
430+
Ok(())
431+
}
355432

356433
async fn blueprint_load(
357434
opctx: &OpContext,

dev-tools/omdb/tests/usage_errors.out

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,11 +1176,12 @@ Interact with the Reconfigurator system
11761176
Usage: omdb reconfigurator [OPTIONS] <COMMAND>
11771177

11781178
Commands:
1179-
export Save the current Reconfigurator state to a file
1180-
archive Save the current Reconfigurator state to a file and remove historical artifacts from the
1181-
live system (e.g., non-target blueprints)
1182-
history Show recent history of blueprints
1183-
help Print this message or the help of the given subcommand(s)
1179+
export Save the current Reconfigurator state to a file
1180+
archive Save the current Reconfigurator state to a file and remove historical
1181+
artifacts from the live system (e.g., non-target blueprints)
1182+
history Show recent history of blueprints
1183+
chicken-switches-history Show the recent history of chicken switch settings
1184+
help Print this message or the help of the given subcommand(s)
11841185

11851186
Options:
11861187
--log-level <LOG_LEVEL> log level filter [env: LOG_LEVEL=] [default: warn]

0 commit comments

Comments
 (0)