Skip to content

Commit

Permalink
add crdb settings to blueprint display
Browse files Browse the repository at this point in the history
  • Loading branch information
iliana committed May 24, 2024
1 parent 3030fc5 commit 9fddf32
Show file tree
Hide file tree
Showing 14 changed files with 191 additions and 73 deletions.
6 changes: 6 additions & 0 deletions nexus/db-model/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use nexus_types::deployment::BlueprintTarget;
use nexus_types::deployment::BlueprintZoneConfig;
use nexus_types::deployment::BlueprintZoneDisposition;
use nexus_types::deployment::BlueprintZonesConfig;
use nexus_types::deployment::CockroachDbPreserveDowngrade;
use omicron_common::api::internal::shared::NetworkInterface;
use omicron_common::disk::DiskIdentity;
use omicron_uuid_kinds::GenericUuid;
Expand Down Expand Up @@ -74,6 +75,11 @@ impl From<Blueprint> for nexus_types::deployment::BlueprintMetadata {
internal_dns_version: *value.internal_dns_version,
external_dns_version: *value.external_dns_version,
cockroachdb_fingerprint: value.cockroachdb_fingerprint,
cockroachdb_setting_preserve_downgrade:
CockroachDbPreserveDowngrade::from_optional_string(
&value.cockroachdb_setting_preserve_downgrade,
)
.ok(),
time_created: value.time_created,
creator: value.creator,
comment: value.comment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ to: blueprint e4aeb3b3-272f-4967-be34-2d34daa46aa1
nexus 29278a22-1ba1-4117-bfdb-39fcb9ae7fd1 in service fd00:1122:3344:102::22


COCKROACHDB SETTINGS:
+ state fingerprint::::::::::::::::: (not present in collection) -> (none)
+ cluster.preserve_downgrade_option: (not present in collection) -> (do not modify)

METADATA:
+ internal DNS version: (not present in collection) -> 1
+ external DNS version: (not present in collection) -> 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ to: blueprint 4171ad05-89dd-474b-846b-b007e4346366
+ internal_ntp 2d73d30e-ca47-46a8-9c12-917d4ab824b6 in service fd00:1122:3344:104::21


COCKROACHDB SETTINGS:
state fingerprint::::::::::::::::: (none) (unchanged)
cluster.preserve_downgrade_option: (do not modify) (unchanged)

METADATA:
internal DNS version: 1 (unchanged)
external DNS version: 1 (unchanged)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ to: blueprint f432fcd5-1284-4058-8b4a-9286a3de6163
+ crucible f86e19d2-9145-41cf-be89-6aaa34a73873 in service fd00:1122:3344:104::24


COCKROACHDB SETTINGS:
state fingerprint::::::::::::::::: (none) (unchanged)
cluster.preserve_downgrade_option: (do not modify) (unchanged)

METADATA:
internal DNS version: 1 (unchanged)
external DNS version: 1 (unchanged)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ to: blueprint 1ac2d88f-27dd-4506-8585-6b2be832528e
+ nexus c8851a11-a4f7-4b21-9281-6182fd15dc8d in service fd00:1122:3344:102::2d


COCKROACHDB SETTINGS:
state fingerprint::::::::::::::::: (none) (unchanged)
cluster.preserve_downgrade_option: (do not modify) (unchanged)

METADATA:
internal DNS version: 1 (unchanged)
external DNS version: 1 (unchanged)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ WARNING: Zones exist without physical disks!



COCKROACHDB SETTINGS:
state fingerprint::::::::::::::::: (none)
cluster.preserve_downgrade_option: (do not modify)

METADATA:
created by::::::::::: test_blueprint2
created at::::::::::: 1970-01-01T00:00:00.000Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ to: blueprint 9f71f5d3-a272-4382-9154-6ea2e171a6c6
+ nexus c26b3bda-5561-44a1-a69f-22103fe209a1 in service fd00:1122:3344:101::2f


COCKROACHDB SETTINGS:
state fingerprint::::::::::::::::: (none) (unchanged)
cluster.preserve_downgrade_option: (do not modify) (unchanged)

METADATA:
internal DNS version: 1 (unchanged)
external DNS version: 1 (unchanged)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ ERRORS:
zone id: 7f4e9f9f-08f8-4d14-885d-e977c05525ad
reason: mismatched underlay address: before: fd00:1122:3344:105::21, after: fd01:1122:3344:105::21

COCKROACHDB SETTINGS:
state fingerprint::::::::::::::::: (none) (unchanged)
cluster.preserve_downgrade_option: (do not modify) (unchanged)

METADATA:
internal DNS version: 1 (unchanged)
* external DNS version: 1 -> 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ WARNING: Zones exist without physical disks!



COCKROACHDB SETTINGS:
state fingerprint::::::::::::::::: (none)
cluster.preserve_downgrade_option: (do not modify)

METADATA:
created by::::::::::: test_blueprint2
created at::::::::::: 1970-01-01T00:00:00.000Z
Expand Down
34 changes: 31 additions & 3 deletions nexus/types/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ pub struct Blueprint {
// on this.
pub cockroachdb_fingerprint: String,

/// Whether to set `cluster.preserve_downgrade_option` and what to set it
/// to.
/// Whether to set `cluster.preserve_downgrade_option` and what to set it to
pub cockroachdb_setting_preserve_downgrade: CockroachDbPreserveDowngrade,

/// when this blueprint was generated (for debugging)
Expand All @@ -186,6 +185,9 @@ impl Blueprint {
internal_dns_version: self.internal_dns_version,
external_dns_version: self.external_dns_version,
cockroachdb_fingerprint: self.cockroachdb_fingerprint.clone(),
cockroachdb_setting_preserve_downgrade: Some(
self.cockroachdb_setting_preserve_downgrade,
),
time_created: self.time_created,
creator: self.creator.clone(),
comment: self.comment.clone(),
Expand Down Expand Up @@ -359,7 +361,28 @@ pub struct BlueprintDisplay<'a> {
}

impl<'a> BlueprintDisplay<'a> {
pub(super) fn make_metadata_table(&self) -> KvListWithHeading {
fn make_cockroachdb_table(&self) -> KvListWithHeading {
let fingerprint = if self.blueprint.cockroachdb_fingerprint.is_empty() {
NONE_PARENS.to_string()
} else {
self.blueprint.cockroachdb_fingerprint.clone()
};

KvListWithHeading::new_unchanged(
COCKROACHDB_HEADING,
vec![
(COCKROACHDB_FINGERPRINT, fingerprint),
(
COCKROACHDB_PRESERVE_DOWNGRADE,
self.blueprint
.cockroachdb_setting_preserve_downgrade
.to_string(),
),
],
)
}

fn make_metadata_table(&self) -> KvListWithHeading {
let comment = if self.blueprint.comment.is_empty() {
NONE_PARENS.to_string()
} else {
Expand Down Expand Up @@ -459,6 +482,7 @@ impl<'a> fmt::Display for BlueprintDisplay<'a> {
}
}

writeln!(f, "{}", self.make_cockroachdb_table())?;
writeln!(f, "{}", self.make_metadata_table())?;

Ok(())
Expand Down Expand Up @@ -1013,6 +1037,10 @@ pub struct BlueprintMetadata {
pub external_dns_version: Generation,
/// CockroachDB state fingerprint when this blueprint was created
pub cockroachdb_fingerprint: String,
/// Whether to set `cluster.preserve_downgrade_option` and what to set it to
/// (`None` if this value was retrieved from the database and was invalid)
pub cockroachdb_setting_preserve_downgrade:
Option<CockroachDbPreserveDowngrade>,

/// when this blueprint was generated (for debugging)
pub time_created: chrono::DateTime<chrono::Utc>,
Expand Down
153 changes: 88 additions & 65 deletions nexus/types/src/deployment/blueprint_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::blueprint_display::{
BpSledSubtable, BpSledSubtableColumn, BpSledSubtableData,
BpSledSubtableRow, KvListWithHeading, KvPair,
};
use super::zone_sort_key;
use super::{zone_sort_key, CockroachDbPreserveDowngrade};
use omicron_common::api::external::Generation;
use omicron_common::disk::DiskIdentity;
use omicron_uuid_kinds::OmicronZoneUuid;
Expand Down Expand Up @@ -662,71 +662,75 @@ impl<'diff> BlueprintDiffDisplay<'diff> {
Self { diff }
}

pub fn make_metadata_diff_table(&self) -> KvListWithHeading {
let diff = self.diff;
let mut kv = vec![];
match &diff.before_meta {
DiffBeforeMetadata::Collection { .. } => {
// Collections don't have DNS versions, so this is new.
kv.push(KvPair::new(
BpDiffState::Added,
INTERNAL_DNS_VERSION,
linear_table_modified(
&NOT_PRESENT_IN_COLLECTION_PARENS,
&diff.after_meta.internal_dns_version,
),
));
kv.push(KvPair::new(
BpDiffState::Added,
EXTERNAL_DNS_VERSION,
linear_table_modified(
&NOT_PRESENT_IN_COLLECTION_PARENS,
&diff.after_meta.external_dns_version,
),
));
}
DiffBeforeMetadata::Blueprint(before) => {
if before.internal_dns_version
!= diff.after_meta.internal_dns_version
{
kv.push(KvPair::new(
BpDiffState::Modified,
INTERNAL_DNS_VERSION,
linear_table_modified(
&before.internal_dns_version,
&diff.after_meta.internal_dns_version,
),
));
} else {
kv.push(KvPair::new(
BpDiffState::Unchanged,
INTERNAL_DNS_VERSION,
linear_table_unchanged(&before.internal_dns_version),
));
};

if before.external_dns_version
!= diff.after_meta.external_dns_version
{
kv.push(KvPair::new(
BpDiffState::Modified,
EXTERNAL_DNS_VERSION,
linear_table_modified(
&before.external_dns_version,
&diff.after_meta.external_dns_version,
),
));
} else {
kv.push(KvPair::new(
BpDiffState::Unchanged,
EXTERNAL_DNS_VERSION,
linear_table_unchanged(&before.external_dns_version),
));
};
}
pub fn make_metadata_diff_tables(
&self,
) -> impl IntoIterator<Item = KvListWithHeading> {
macro_rules! diff_row {
($member:ident, $label:expr) => {
diff_row!($member, $label, |value| value)
};

($member:ident, $label:expr, $display:expr) => {
match &self.diff.before_meta {
DiffBeforeMetadata::Collection { .. } => {
// Collections have no metadata, so this is new
KvPair::new(
BpDiffState::Added,
$label,
linear_table_modified(
&NOT_PRESENT_IN_COLLECTION_PARENS,
&$display(&self.diff.after_meta.$member),
),
)
}
DiffBeforeMetadata::Blueprint(before) => {
if before.$member == self.diff.after_meta.$member {
KvPair::new(
BpDiffState::Unchanged,
$label,
linear_table_unchanged(&$display(
&self.diff.after_meta.$member,
)),
)
} else {
KvPair::new(
BpDiffState::Modified,
$label,
linear_table_modified(
&$display(&before.$member),
&$display(&self.diff.after_meta.$member),
),
)
}
}
}
};
}

KvListWithHeading::new(METADATA_HEADING, kv)
[
KvListWithHeading::new(
COCKROACHDB_HEADING,
vec![
diff_row!(
cockroachdb_fingerprint,
COCKROACHDB_FINGERPRINT,
display_none_if_empty
),
diff_row!(
cockroachdb_setting_preserve_downgrade,
COCKROACHDB_PRESERVE_DOWNGRADE,
display_optional_preserve_downgrade
),
],
),
KvListWithHeading::new(
METADATA_HEADING,
vec![
diff_row!(internal_dns_version, INTERNAL_DNS_VERSION),
diff_row!(external_dns_version, EXTERNAL_DNS_VERSION),
],
),
]
}

/// Write out physical disk and zone tables for a given `sled_id`
Expand Down Expand Up @@ -847,8 +851,27 @@ impl<'diff> fmt::Display for BlueprintDiffDisplay<'diff> {
}

// Write out metadata diff table
writeln!(f, "{}", self.make_metadata_diff_table())?;
for table in self.make_metadata_diff_tables() {
writeln!(f, "{}", table)?;
}

Ok(())
}
}

fn display_none_if_empty(value: &str) -> &str {
if value.is_empty() {
NONE_PARENS
} else {
value
}
}

fn display_optional_preserve_downgrade(
value: &Option<CockroachDbPreserveDowngrade>,
) -> String {
match value {
Some(v) => v.to_string(),
None => INVALID_VALUE_PARENS.to_string(),
}
}
5 changes: 5 additions & 0 deletions nexus/types/src/deployment/blueprint_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ pub mod constants {
pub(super) const SUB_LAST: &str = "└─";

pub const ARROW: &str = "->";
pub const COCKROACHDB_HEADING: &str = "COCKROACHDB SETTINGS";
pub const COCKROACHDB_FINGERPRINT: &str = "state fingerprint";
pub const COCKROACHDB_PRESERVE_DOWNGRADE: &str =
"cluster.preserve_downgrade_option";
pub const METADATA_HEADING: &str = "METADATA";
pub const CREATED_BY: &str = "created by";
pub const CREATED_AT: &str = "created at";
Expand All @@ -29,6 +33,7 @@ pub mod constants {
pub const NONE_PARENS: &str = "(none)";
pub const NOT_PRESENT_IN_COLLECTION_PARENS: &str =
"(not present in collection)";
pub const INVALID_VALUE_PARENS: &str = "(invalid value)";
}
use constants::*;

Expand Down
Loading

0 comments on commit 9fddf32

Please sign in to comment.