Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions nexus/db-model/src/fm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ mod case;
pub use case::*;
mod diagnosis_engine;
pub use diagnosis_engine::*;
mod sb_req_ereports;
pub use sb_req_ereports::*;
mod sb_req_host_info;
pub use sb_req_host_info::*;
mod sb_req_reconfigurator;
pub use sb_req_reconfigurator::*;
mod sb_req_sled_cubby_info;
pub use sb_req_sled_cubby_info::*;
mod sb_req_sp_dumps;
pub use sb_req_sp_dumps::*;
mod support_bundle_request;
pub use support_bundle_request::*;

#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
#[diesel(table_name = fm_sitrep)]
Expand Down
3 changes: 3 additions & 0 deletions nexus/db-model/src/fm/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use super::AlertRequest;
use super::DiagnosisEngine;
use super::SupportBundleRequest;
use crate::DbTypedUuid;
use crate::ereport;
use nexus_db_schema::schema::{fm_case, fm_ereport_in_case};
Expand Down Expand Up @@ -58,6 +59,7 @@ impl CaseMetadata {
de,
comment,
alerts_requested: _,
support_bundles_requested: _,
ereports: _,
} = case;
Self {
Expand Down Expand Up @@ -138,4 +140,5 @@ pub struct Case {
pub metadata: CaseMetadata,
pub ereports: Vec<CaseEreport>,
pub alerts_requested: Vec<AlertRequest>,
pub support_bundles_requested: Vec<SupportBundleRequest>,
}
49 changes: 49 additions & 0 deletions nexus/db-model/src/fm/sb_req_ereports.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! DB model for the `fm_sb_req_ereports` per-variant table.

use crate::DbTypedUuid;
use chrono::{DateTime, Utc};
use nexus_db_schema::schema::fm_sb_req_ereports;
use nexus_types::fm::ereport::EreportFilters;
use omicron_uuid_kinds::{SitrepKind, SupportBundleKind};

#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
#[diesel(table_name = fm_sb_req_ereports)]
pub struct SbReqEreports {
pub sitrep_id: DbTypedUuid<SitrepKind>,
pub request_id: DbTypedUuid<SupportBundleKind>,
pub start_time: Option<DateTime<Utc>>,
pub end_time: Option<DateTime<Utc>>,
pub only_serials: Vec<String>,
pub only_classes: Vec<String>,
}

impl SbReqEreports {
pub fn new(
sitrep_id: impl Into<DbTypedUuid<SitrepKind>>,
request_id: impl Into<DbTypedUuid<SupportBundleKind>>,
filters: &EreportFilters,
) -> Self {
SbReqEreports {
sitrep_id: sitrep_id.into(),
request_id: request_id.into(),
start_time: filters.start_time,
end_time: filters.end_time,
only_serials: filters.only_serials.clone(),
only_classes: filters.only_classes.clone(),
}
}

/// Reconstruct the `EreportFilters` from the DB row.
pub fn into_ereport_filters(self) -> EreportFilters {
EreportFilters {
start_time: self.start_time,
end_time: self.end_time,
only_serials: self.only_serials,
only_classes: self.only_classes,
}
}
}
59 changes: 59 additions & 0 deletions nexus/db-model/src/fm/sb_req_host_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! DB model for the `fm_sb_req_host_info` per-variant table.

use crate::DbTypedUuid;
use nexus_db_schema::schema::fm_sb_req_host_info;
use nexus_types::support_bundle::SledSelection;
use omicron_uuid_kinds::{
GenericUuid, SitrepKind, SledUuid, SupportBundleKind,
};
use std::collections::HashSet;

#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
#[diesel(table_name = fm_sb_req_host_info)]
pub struct SbReqHostInfo {
pub sitrep_id: DbTypedUuid<SitrepKind>,
pub request_id: DbTypedUuid<SupportBundleKind>,
pub all_sleds: bool,
pub sled_ids: Vec<uuid::Uuid>,
}

impl SbReqHostInfo {
pub fn new(
sitrep_id: impl Into<DbTypedUuid<SitrepKind>>,
request_id: impl Into<DbTypedUuid<SupportBundleKind>>,
sleds: &HashSet<SledSelection>,
) -> Self {
let all_sleds = sleds.contains(&SledSelection::All);
let sled_ids: Vec<uuid::Uuid> = sleds
.iter()
.filter_map(|s| match s {
SledSelection::Specific(id) => Some(id.into_untyped_uuid()),
SledSelection::All => None,
})
.collect();
SbReqHostInfo {
sitrep_id: sitrep_id.into(),
request_id: request_id.into(),
all_sleds,
sled_ids,
}
}

/// Reconstruct the `HashSet<SledSelection>` from the DB row.
pub fn into_sled_selections(self) -> HashSet<SledSelection> {
let mut set = HashSet::new();
if self.all_sleds {
set.insert(SledSelection::All);
}
for id in self.sled_ids {
set.insert(SledSelection::Specific(SledUuid::from_untyped_uuid(
id,
)));
}
set
}
}
16 changes: 16 additions & 0 deletions nexus/db-model/src/fm/sb_req_reconfigurator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! DB model for the `fm_sb_req_reconfigurator` per-variant table.

use crate::DbTypedUuid;
use nexus_db_schema::schema::fm_sb_req_reconfigurator;
use omicron_uuid_kinds::{SitrepKind, SupportBundleKind};

#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
#[diesel(table_name = fm_sb_req_reconfigurator)]
pub struct SbReqReconfigurator {
pub sitrep_id: DbTypedUuid<SitrepKind>,
pub request_id: DbTypedUuid<SupportBundleKind>,
}
16 changes: 16 additions & 0 deletions nexus/db-model/src/fm/sb_req_sled_cubby_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! DB model for the `fm_sb_req_sled_cubby_info` per-variant table.

use crate::DbTypedUuid;
use nexus_db_schema::schema::fm_sb_req_sled_cubby_info;
use omicron_uuid_kinds::{SitrepKind, SupportBundleKind};

#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
#[diesel(table_name = fm_sb_req_sled_cubby_info)]
pub struct SbReqSledCubbyInfo {
pub sitrep_id: DbTypedUuid<SitrepKind>,
pub request_id: DbTypedUuid<SupportBundleKind>,
}
16 changes: 16 additions & 0 deletions nexus/db-model/src/fm/sb_req_sp_dumps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! DB model for the `fm_sb_req_sp_dumps` per-variant table.

use crate::DbTypedUuid;
use nexus_db_schema::schema::fm_sb_req_sp_dumps;
use omicron_uuid_kinds::{SitrepKind, SupportBundleKind};

#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
#[diesel(table_name = fm_sb_req_sp_dumps)]
pub struct SbReqSpDumps {
pub sitrep_id: DbTypedUuid<SitrepKind>,
pub request_id: DbTypedUuid<SupportBundleKind>,
}
51 changes: 51 additions & 0 deletions nexus/db-model/src/fm/support_bundle_request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Fault management support bundle requests.

use crate::DbTypedUuid;
use nexus_db_schema::schema::fm_support_bundle_request;
use nexus_types::fm;
use omicron_uuid_kinds::{CaseKind, SitrepKind, SupportBundleKind};

#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
#[diesel(table_name = fm_support_bundle_request)]
pub struct SupportBundleRequest {
pub id: DbTypedUuid<SupportBundleKind>,
pub sitrep_id: DbTypedUuid<SitrepKind>,
pub requested_sitrep_id: DbTypedUuid<SitrepKind>,
pub case_id: DbTypedUuid<CaseKind>,
}

impl SupportBundleRequest {
pub fn from_sitrep(
sitrep_id: impl Into<DbTypedUuid<SitrepKind>>,
case_id: impl Into<DbTypedUuid<CaseKind>>,
req: fm::case::SupportBundleRequest,
) -> Self {
let fm::case::SupportBundleRequest {
id,
requested_sitrep_id,
data_selection: _,
} = req;
SupportBundleRequest {
id: id.into(),
sitrep_id: sitrep_id.into(),
requested_sitrep_id: requested_sitrep_id.into(),
case_id: case_id.into(),
}
}
}

impl From<SupportBundleRequest> for fm::case::SupportBundleRequest {
fn from(req: SupportBundleRequest) -> Self {
fm::case::SupportBundleRequest {
id: req.id.into(),
requested_sitrep_id: req.requested_sitrep_id.into(),
// data_selection is reconstructed from per-variant tables
// by the sitrep read path, not stored on this row.
data_selection: None,
}
}
}
3 changes: 2 additions & 1 deletion nexus/db-model/src/schema_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{collections::BTreeMap, sync::LazyLock};
///
/// This must be updated when you change the database schema. Refer to
/// schema/crdb/README.adoc in the root of this repository for details.
pub const SCHEMA_VERSION: Version = Version::new(240, 0, 0);
pub const SCHEMA_VERSION: Version = Version::new(241, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
Expand All @@ -28,6 +28,7 @@ static KNOWN_VERSIONS: LazyLock<Vec<KnownVersion>> = LazyLock::new(|| {
// | leaving the first copy as an example for the next person.
// v
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
KnownVersion::new(241, "fm-support-bundle-request"),
KnownVersion::new(240, "multicast-drop-mvlan"),
KnownVersion::new(239, "fm-alert-request"),
KnownVersion::new(238, "fewer-nullable-columns"),
Expand Down
27 changes: 27 additions & 0 deletions nexus/db-model/src/support_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use nexus_db_schema::schema::support_bundle;

use chrono::{DateTime, Utc};
use nexus_types::external_api::support_bundle as support_bundle_types;
use omicron_uuid_kinds::CaseKind;
use omicron_uuid_kinds::CaseUuid;
use omicron_uuid_kinds::DatasetKind;
use omicron_uuid_kinds::DatasetUuid;
use omicron_uuid_kinds::OmicronZoneKind;
Expand Down Expand Up @@ -95,6 +97,7 @@ pub struct SupportBundle {
pub dataset_id: DbTypedUuid<DatasetKind>,
pub assigned_nexus: Option<DbTypedUuid<OmicronZoneKind>>,
pub user_comment: Option<String>,
pub fm_case_id: Option<DbTypedUuid<CaseKind>>,
}

impl SupportBundle {
Expand All @@ -115,6 +118,30 @@ impl SupportBundle {
dataset_id: dataset_id.into(),
assigned_nexus: Some(nexus_id.into()),
user_comment,
fm_case_id: None,
}
}

/// Create a new support bundle requested by the FM subsystem.
pub fn new_for_fm(
id: SupportBundleUuid,
reason_for_creation: String,
zpool_id: ZpoolUuid,
dataset_id: DatasetUuid,
nexus_id: OmicronZoneUuid,
fm_case_id: CaseUuid,
) -> Self {
Self {
id: id.into(),
time_created: Utc::now(),
reason_for_creation,
reason_for_failure: None,
state: SupportBundleState::Collecting,
zpool_id: zpool_id.into(),
dataset_id: dataset_id.into(),
assigned_nexus: Some(nexus_id.into()),
user_comment: None,
fm_case_id: Some(fm_case_id.into()),
}
}

Expand Down
4 changes: 4 additions & 0 deletions nexus/db-queries/src/db/datastore/fm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ impl DataStore {
comment,
ereports,
alerts_requested,
support_bundles_requested: iddqd::IdOrdMap::new(),
}
}));
}
Expand Down Expand Up @@ -1552,6 +1553,7 @@ mod tests {
de,
ereports,
alerts_requested,
support_bundles_requested: _,
} = case;
let case_id = id;
let Some(expected) = this.cases.get(&case_id) else {
Expand Down Expand Up @@ -1770,6 +1772,7 @@ mod tests {
de: fm::DiagnosisEngineKind::PowerShelf,
ereports,
alerts_requested,
support_bundles_requested: iddqd::IdOrdMap::new(),
comment: "my cool case".to_string(),
}
};
Expand Down Expand Up @@ -1802,6 +1805,7 @@ mod tests {
de: fm::DiagnosisEngineKind::PowerShelf,
ereports,
alerts_requested,
support_bundles_requested: iddqd::IdOrdMap::new(),
comment: "break in case of emergency".to_string(),
}
};
Expand Down
Loading
Loading