Skip to content

Commit d87449e

Browse files
committed
Move bundle selection types and EreportFilters to nexus-types
Move BundleDataCategory, BundleData, BundleDataSelection, SledSelection, and EreportFilters to nexus/types/src/support_bundle.rs so they can be shared between the support bundle collector and FM case types. Pure refactor, no behavior change.
1 parent af9dd12 commit d87449e

7 files changed

Lines changed: 183 additions & 159 deletions

File tree

nexus/db-queries/src/db/datastore/ereport.rs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use nexus_db_lookup::DbConnection;
2828
use nexus_db_schema::schema::ereport::dsl;
2929
use nexus_types::fm::ereport as fm;
3030
use nexus_types::fm::ereport::EreportId;
31+
use nexus_types::support_bundle::EreportFilters;
3132
use omicron_common::api::external::CreateResult;
3233
use omicron_common::api::external::DataPageParams;
3334
use omicron_common::api::external::Error;
@@ -48,44 +49,6 @@ pub struct EreporterRestartBySerial {
4849
pub ereports: u32,
4950
}
5051

51-
/// A set of filters for fetching ereports.
52-
#[derive(Clone, Debug, Default, Eq, PartialEq)]
53-
pub struct EreportFilters {
54-
/// If present, include only ereports that were collected at the specified
55-
/// timestamp or later.
56-
///
57-
/// If `end_time` is also present, this value *must* be earlier than
58-
/// `end_time`.
59-
pub start_time: Option<DateTime<Utc>>,
60-
/// If present, include only ereports that were collected at the specified
61-
/// timestamp or before.
62-
///
63-
/// If `start_time` is also present, this value *must* be later than
64-
/// `start_time`.
65-
pub end_time: Option<DateTime<Utc>>,
66-
/// If this list is non-empty, include only ereports that were reported by
67-
/// systems with the provided serial numbers.
68-
pub only_serials: Vec<String>,
69-
/// If this list is non-empty, include only ereports with the provided class
70-
/// strings.
71-
// TODO(eliza): globbing could be nice to add here eventually...
72-
pub only_classes: Vec<String>,
73-
}
74-
75-
impl EreportFilters {
76-
fn check_time_range(&self) -> Result<(), Error> {
77-
if let (Some(start), Some(end)) = (self.start_time, self.end_time) {
78-
if start > end {
79-
return Err(Error::invalid_request(
80-
"start time must be before end time",
81-
));
82-
}
83-
}
84-
85-
Ok(())
86-
}
87-
}
88-
8952
impl DataStore {
9053
/// Fetch an ereport by its restart ID and ENA.
9154
///

nexus/db-queries/src/db/datastore/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ pub use disk::LocalStorageAllocation;
141141
pub use disk::LocalStorageDisk;
142142
pub use dns::DataStoreDnsTest;
143143
pub use dns::DnsVersionUpdateBuilder;
144-
pub use ereport::EreportFilters;
145144
pub use external_ip::FloatingIpAllocation;
146145
pub use external_subnet::ExternalSubnetBeginOpResult;
147146
pub use external_subnet::ExternalSubnetCompleteOpResult;

nexus/src/app/background/tasks/support_bundle/request.rs

Lines changed: 5 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
//! Support bundle request types and data selection
66
7-
use nexus_db_queries::db::datastore::EreportFilters;
7+
use nexus_types::support_bundle::{
8+
BundleData, BundleDataCategory, BundleDataSelection, EreportFilters,
9+
SledSelection,
10+
};
11+
812
use omicron_uuid_kinds::SledUuid;
9-
use std::collections::HashMap;
10-
use std::collections::HashSet;
1113
use std::num::NonZeroU64;
1214

1315
/// We use "/var/tmp" to use Nexus' filesystem for temporary storage,
@@ -18,121 +20,6 @@ pub const TEMPDIR: &str = "/var/tmp";
1820
/// within a single streaming request.
1921
pub const CHUNK_SIZE: NonZeroU64 = NonZeroU64::new(1024 * 1024 * 1024).unwrap();
2022

21-
/// Describes the category of support bundle data.
22-
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
23-
pub enum BundleDataCategory {
24-
/// Collects reconfigurator state (some of the latest blueprints,
25-
/// information about the target blueprint).
26-
Reconfigurator,
27-
/// Collects info from sled agents, running a handful of
28-
/// diagnostic commands (e.g., zoneadm, dladm, etc).
29-
HostInfo,
30-
/// Collects sled serial numbers, cubby numbers, and UUIDs.
31-
SledCubbyInfo,
32-
/// Saves task dumps from SPs.
33-
SpDumps,
34-
/// Collects ereports.
35-
Ereports,
36-
}
37-
38-
/// Specifies what data to collect for a bundle data category.
39-
///
40-
/// Each variant corresponds to a BundleDataCategory.
41-
/// For categories without additional parameters, the variant is a unit variant.
42-
/// For categories that can be filtered or configured, the variant contains
43-
/// that configuration data.
44-
#[derive(Debug, Clone, Eq, PartialEq)]
45-
pub enum BundleData {
46-
Reconfigurator,
47-
HostInfo(HashSet<SledSelection>),
48-
SledCubbyInfo,
49-
SpDumps,
50-
Ereports(EreportFilters),
51-
}
52-
53-
impl BundleData {
54-
fn category(&self) -> BundleDataCategory {
55-
match self {
56-
Self::Reconfigurator => BundleDataCategory::Reconfigurator,
57-
Self::HostInfo(_) => BundleDataCategory::HostInfo,
58-
Self::SledCubbyInfo => BundleDataCategory::SledCubbyInfo,
59-
Self::SpDumps => BundleDataCategory::SpDumps,
60-
Self::Ereports(_) => BundleDataCategory::Ereports,
61-
}
62-
}
63-
}
64-
65-
/// A collection of bundle data specifications.
66-
///
67-
/// This wrapper ensures that categories and data always match - you can't
68-
/// insert (BundleDataCategory::Reconfigurator, BundleData::SpDumps)
69-
/// because each BundleData determines its own category.
70-
#[derive(Debug, Clone)]
71-
pub struct BundleDataSelection {
72-
data: HashMap<BundleDataCategory, BundleData>,
73-
}
74-
75-
impl BundleDataSelection {
76-
pub fn new() -> Self {
77-
Self { data: HashMap::new() }
78-
}
79-
80-
/// Inserts BundleData to be queried for a particular category within the
81-
/// bundle.
82-
///
83-
/// Each category of data can only be specified once (e.g., inserting
84-
/// BundleData::HostInfo multiple times will only use the most-recently
85-
/// inserted specification)
86-
pub fn insert(&mut self, bundle_data: BundleData) {
87-
self.data.insert(bundle_data.category(), bundle_data);
88-
}
89-
90-
pub fn contains(&self, category: BundleDataCategory) -> bool {
91-
self.data.contains_key(&category)
92-
}
93-
94-
pub fn get(&self, category: BundleDataCategory) -> Option<&BundleData> {
95-
self.data.get(&category)
96-
}
97-
}
98-
99-
impl FromIterator<BundleData> for BundleDataSelection {
100-
fn from_iter<T: IntoIterator<Item = BundleData>>(iter: T) -> Self {
101-
let mut selection = Self::new();
102-
for bundle_data in iter {
103-
selection.insert(bundle_data);
104-
}
105-
selection
106-
}
107-
}
108-
109-
impl Default for BundleDataSelection {
110-
fn default() -> Self {
111-
[
112-
BundleData::Reconfigurator,
113-
BundleData::HostInfo(HashSet::from([SledSelection::All])),
114-
BundleData::SledCubbyInfo,
115-
BundleData::SpDumps,
116-
BundleData::Ereports(EreportFilters {
117-
start_time: Some(chrono::Utc::now() - chrono::Days::new(7)),
118-
..EreportFilters::default()
119-
}),
120-
]
121-
.into_iter()
122-
.collect()
123-
}
124-
}
125-
126-
/// The set of sleds to include
127-
///
128-
/// Multiple values of this enum are joined together into a HashSet.
129-
/// Therefore "SledSelection::All" overrides specific sleds.
130-
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
131-
pub enum SledSelection {
132-
All,
133-
Specific(SledUuid),
134-
}
135-
13623
/// Specifies the data to be collected within the Support Bundle.
13724
#[derive(Clone)]
13825
pub struct BundleRequest {

nexus/src/app/background/tasks/support_bundle/steps/ereports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
77
use crate::app::background::tasks::support_bundle::collection::BundleCollection;
88
use crate::app::background::tasks::support_bundle::step::CollectionStepOutput;
9+
use nexus_types::support_bundle::EreportFilters;
910

1011
use anyhow::Context;
1112
use camino::Utf8Path;
1213
use camino::Utf8PathBuf;
1314
use nexus_db_queries::context::OpContext;
1415
use nexus_db_queries::db::DataStore;
1516
use nexus_db_queries::db::datastore;
16-
use nexus_db_queries::db::datastore::EreportFilters;
1717
use nexus_db_queries::db::pagination::Paginator;
1818
use nexus_types::fm::Ereport;
1919
use nexus_types::internal_api::background::SupportBundleEreportStatus;

nexus/src/app/background/tasks/support_bundle_collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ mod test {
441441
use super::*;
442442

443443
use crate::app::background::tasks::support_bundle::perfetto;
444-
use crate::app::background::tasks::support_bundle::request::BundleData;
445444
use crate::app::support_bundles::SupportBundleQueryType;
446445
use http_body_util::BodyExt;
447446
use illumos_utils::zpool::ZpoolHealth;
@@ -456,6 +455,7 @@ mod test {
456455
use nexus_types::internal_api::background::SupportBundleCollectionStep;
457456
use nexus_types::internal_api::background::SupportBundleEreportStatus;
458457
use nexus_types::inventory::SpType;
458+
use nexus_types::support_bundle::BundleData;
459459
use omicron_common::api::external::ByteCount;
460460
use omicron_common::api::internal::shared::DatasetKind;
461461
use omicron_common::disk::DatasetConfig;

nexus/types/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ pub mod multicast;
4141
pub mod quiesce;
4242
pub mod saga;
4343
pub mod silo;
44+
pub mod support_bundle;
4445
pub mod trust_quorum;

0 commit comments

Comments
 (0)