Skip to content

Commit 48884d4

Browse files
committed
start ereport ingestion task
1 parent 80e9922 commit 48884d4

File tree

6 files changed

+117
-1
lines changed

6 files changed

+117
-1
lines changed

Cargo.lock

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

clients/gateway-client/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ workspace = true
1111
base64.workspace = true
1212
chrono.workspace = true
1313
daft.workspace = true
14+
ereport-types.workspace = true
1415
gateway-messages.workspace = true
1516
gateway-types.workspace = true
1617
progenitor.workspace = true
@@ -21,4 +22,5 @@ serde_json.workspace = true
2122
schemars.workspace = true
2223
slog.workspace = true
2324
uuid.workspace = true
25+
omicron-uuid-kinds.workspace = true
2426
omicron-workspace-hack.workspace = true

clients/gateway-client/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ progenitor::generate_api!(
7474
SpUpdateStatus = { derives = [PartialEq, Hash, Eq] },
7575
UpdatePreparationProgress = { derives = [PartialEq, Hash, Eq] },
7676
},
77-
replace = { RotSlot = gateway_types::rot::RotSlot },
77+
replace = {
78+
RotSlot = gateway_types::rot::RotSlot,
79+
Ena = ereport_types::Ena,
80+
TypedUuidForEreporterRestartKind = omicron_uuid_kinds::EreporterRestartUuid,
81+
},
7882
);
7983

8084
// Override the impl of Ord for SpIdentifier because the default one orders the

nexus/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ crucible-pantry-client.workspace = true
3131
crucible-common.workspace = true
3232
dns-service-client.workspace = true
3333
dpd-client.workspace = true
34+
ereport-types.workspace = true
3435
mg-admin-client.workspace = true
3536
dropshot.workspace = true
3637
fatfs.workspace = true
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
//! Background tasks for ereport ingestion
6+
7+
use crate::app::background::BackgroundTask;
8+
use anyhow::Context;
9+
use futures::future::BoxFuture;
10+
use internal_dns_types::names::ServiceName;
11+
use nexus_db_queries::context::OpContext;
12+
use nexus_db_queries::db::DataStore;
13+
use omicron_common::backoff;
14+
use omicron_uuid_kinds::EreporterRestartUuid;
15+
use omicron_uuid_kinds::OmicronZoneUuid;
16+
use std::sync::Arc;
17+
use uuid::Uuid;
18+
19+
pub struct SpEreportIngester {
20+
pub datastore: Arc<DataStore>,
21+
pub resolver: internal_dns_resolver::Resolver,
22+
pub nexus_id: OmicronZoneUuid,
23+
pub rack_id: Uuid,
24+
}
25+
26+
impl BackgroundTask for SpEreportIngester {
27+
fn activate<'a>(
28+
&'a mut self,
29+
opctx: &'a OpContext,
30+
) -> BoxFuture<'a, serde_json::Value> {
31+
todo!()
32+
}
33+
}
34+
35+
impl SpEreportIngester {
36+
async fn actually_activate(
37+
&mut self,
38+
opctx: &OpContext,
39+
) -> anyhow::Result<()> {
40+
// Find MGS clients.
41+
// TODO(eliza): reuse the same client across activations...
42+
let mgs_clients = self
43+
.resolver
44+
.lookup_all_socket_v6(ServiceName::ManagementGatewayService)
45+
.await
46+
.context("looking up MGS addresses")?
47+
.into_iter()
48+
.map(|sockaddr| {
49+
let url = format!("http://{}", sockaddr);
50+
let log = opctx.log.new(o!("gateway_url" => url.clone()));
51+
gateway_client::Client::new(&url, log)
52+
})
53+
.collect::<Vec<_>>();
54+
55+
Ok(())
56+
}
57+
}
58+
59+
struct Sp {
60+
sp_type: gateway_client::types::SpType,
61+
slot: u32,
62+
}
63+
64+
struct SpState {
65+
committed_ena: ereport_types::Ena,
66+
restart_id: EreporterRestartUuid,
67+
}
68+
69+
const LIMIT: std::num::NonZeroU32 = match std::num::NonZeroU32::new(255) {
70+
None => unreachable!(),
71+
Some(l) => l,
72+
};
73+
74+
async fn mgs_request(
75+
opctx: &OpContext,
76+
clients: &[gateway_client::Client],
77+
Sp { sp_type, slot }: Sp,
78+
sp_state: Option<SpState>,
79+
) -> anyhow::Result<()> {
80+
let mut idx = 0;
81+
let restart_id = sp_state
82+
.as_ref()
83+
.map(|state| state.restart_id.clone())
84+
.unwrap_or(EreporterRestartUuid::nil());
85+
backoff::retry_notify_ext(
86+
backoff::retry_policy_internal_service(),
87+
|| async {
88+
let client = &clients[idx];
89+
let res = client
90+
.sp_ereports_ingest(
91+
sp_type,
92+
slot,
93+
sp_state.as_ref().map(|state| &state.committed_ena),
94+
LIMIT,
95+
&restart_id,
96+
sp_state.as_ref().map(|state| &state.committed_ena),
97+
)
98+
.await;
99+
100+
Ok(())
101+
},
102+
|err, count, duration| todo!(),
103+
)
104+
.await
105+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub mod decommissioned_disk_cleaner;
1515
pub mod dns_config;
1616
pub mod dns_propagation;
1717
pub mod dns_servers;
18+
pub mod ereport_ingester;
1819
pub mod external_endpoints;
1920
pub mod instance_reincarnation;
2021
pub mod instance_updater;

0 commit comments

Comments
 (0)