Skip to content

Commit 45c032b

Browse files
authored
Store PlanningReports in database for debugging only (PR 1/2) (#9029)
#8631 introduced `PlanningReport`s for blueprints. We've wanted to store them in the database all along, but have punted on doing so because: 1. They're highly structured, making them difficult to map to SQL / diesel 2. We expect to want to change them pretty frequently at least in the near/mid term, which compounds problem 1 Chatting with @davepacheco, we came up with a compromise: * These reports are not intended for programmatic consumption, and are primarily useful as a debugging aid. (We want to report _something_ to operators, but not at this level of detail. More on this momentarily.) * Therefore, it seems okay to punt on the diesel / SQL problem by storing these as serialized JSON blobs, under the condition that we never attempt to parse them in Nexus proper, and therefore don't have to deal with versioning. * We can (and this PR does) add an `omdb` subcommand that _attempts_ to parse them; if omdb and the Nexus that produced the report are out of sync, this parsing may fail, but that's okay in that we can still at least dump the raw JSON out. This PR hedges on this a bit by storing the git commit in the JSON blob, so at least omdb can warn if it's expected that it can't parse it (and note the git commit from which the support operator would need an omdb to parse it successfully).
1 parent 4b4e4ca commit 45c032b

File tree

19 files changed

+504
-30
lines changed

19 files changed

+504
-30
lines changed

Cargo.lock

Lines changed: 50 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ url = "2.5.4"
768768
usdt = "0.5.0"
769769
uuid = { version = "1.17.0", features = ["serde", "v4"] }
770770
uzers = "0.12"
771+
vergen-gitcl = { version = "1.0.8" }
771772
walkdir = "2.5"
772773
whoami = "1.5"
773774
wicket = { path = "wicket" }

dev-tools/omdb/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ workspace = true
99

1010
[build-dependencies]
1111
omicron-rpaths.workspace = true
12+
vergen-gitcl.workspace = true
1213

1314
[dependencies]
1415
anyhow.workspace = true

dev-tools/omdb/build.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,28 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
// See omicron-rpaths for documentation.
6-
// NOTE: This file MUST be kept in sync with the other build.rs files in this
7-
// repository.
5+
use vergen_gitcl::Emitter;
6+
use vergen_gitcl::GitclBuilder;
7+
88
fn main() {
9+
// See omicron-rpaths for documentation. NOTE: This file MUST be kept in
10+
// sync with the other build.rs files in this repository.
911
omicron_rpaths::configure_default_omicron_rpaths();
12+
13+
// Define the `VERGEN_GIT_SHA` and `VERGEN_GIT_DIRTY` environment variables
14+
// (accessible via `env!()`) that note the current git commit and whether
15+
// the working tree is dirty at the time of this build.
16+
//
17+
// We use this to check our own git SHA against the git SHA of the Nexus
18+
// that generated blueprint planner debug logs.
19+
let gitcl = GitclBuilder::default()
20+
.sha(/* short= */ false)
21+
.dirty(/* include_untracked= */ false)
22+
.build()
23+
.expect("valid GitclBuilder configuration");
24+
Emitter::default()
25+
.add_instructions(&gitcl)
26+
.expect("valid instructions")
27+
.emit()
28+
.expect("emitted version information");
1029
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use crate::Omdb;
2121
use crate::check_allow_destructive::DestructiveOperationToken;
22+
use crate::db::blueprints::cmd_db_blueprints;
2223
use crate::db::ereport::cmd_db_ereport;
2324
use crate::helpers::CONNECTION_OPTIONS_HEADING;
2425
use crate::helpers::DATABASE_OPTIONS_HEADING;
@@ -173,6 +174,7 @@ use tabled::Tabled;
173174
use uuid::Uuid;
174175

175176
mod alert;
177+
mod blueprints;
176178
mod db_metadata;
177179
mod ereport;
178180
mod saga;
@@ -342,6 +344,10 @@ pub struct DbFetchOptions {
342344
/// Subcommands that query or update the database
343345
#[derive(Debug, Subcommand, Clone)]
344346
enum DbCommands {
347+
/// Print information about blueprints
348+
///
349+
/// Most blueprint information is available via `omdb nexus`, not `omdb db`.
350+
Blueprints(blueprints::BlueprintsArgs),
345351
/// Commands for database metadata
346352
DbMetadata(DbMetadataArgs),
347353
/// Commands relevant to Crucible datasets
@@ -1134,6 +1140,9 @@ impl DbArgs {
11341140
self.db_url_opts.with_datastore(omdb, log, |opctx, datastore| {
11351141
async move {
11361142
match &self.command {
1143+
DbCommands::Blueprints(args) => {
1144+
cmd_db_blueprints(&opctx, &datastore, &fetch_opts, &args).await
1145+
}
11371146
DbCommands::DbMetadata(DbMetadataArgs {
11381147
command: DbMetadataCommands::ListNexus,
11391148
}) => {

0 commit comments

Comments
 (0)