Skip to content

Commit 815354e

Browse files
committed
background task
1 parent 4d9d269 commit 815354e

File tree

53 files changed

+1816
-137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1816
-137
lines changed

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ use nexus_types::internal_api::background::RegionSnapshotReplacementFinishStatus
5151
use nexus_types::internal_api::background::RegionSnapshotReplacementGarbageCollectStatus;
5252
use nexus_types::internal_api::background::RegionSnapshotReplacementStartStatus;
5353
use nexus_types::internal_api::background::RegionSnapshotReplacementStepStatus;
54+
use nexus_types::internal_api::background::TufArtifactReplicationCounters;
55+
use nexus_types::internal_api::background::TufArtifactReplicationRequest;
56+
use nexus_types::internal_api::background::TufArtifactReplicationStatus;
5457
use nexus_types::inventory::BaseboardId;
5558
use omicron_uuid_kinds::BlueprintUuid;
5659
use omicron_uuid_kinds::CollectionUuid;
@@ -943,6 +946,9 @@ fn print_task_details(bgtask: &BackgroundTask, details: &serde_json::Value) {
943946
"service_firewall_rule_propagation" => {
944947
print_task_service_firewall_rule_propagation(details);
945948
}
949+
"tuf_artifact_replication" => {
950+
print_task_tuf_artifact_replication(details);
951+
}
946952
_ => {
947953
println!(
948954
"warning: unknown background task: {:?} \
@@ -2024,6 +2030,69 @@ fn print_task_service_firewall_rule_propagation(details: &serde_json::Value) {
20242030
};
20252031
}
20262032

2033+
fn print_task_tuf_artifact_replication(details: &serde_json::Value) {
2034+
fn print_counters(counters: TufArtifactReplicationCounters) {
2035+
const ROWS: &[&str] = &[
2036+
"list ok:",
2037+
"list err:",
2038+
"put ok:",
2039+
"put err:",
2040+
"copy ok:",
2041+
"copy err:",
2042+
"delete ok:",
2043+
"delete err:",
2044+
];
2045+
const WIDTH: usize = const_max_len(ROWS);
2046+
2047+
for (label, value) in ROWS.iter().zip([
2048+
counters.list_ok,
2049+
counters.list_err,
2050+
counters.put_ok,
2051+
counters.put_err,
2052+
counters.copy_ok,
2053+
counters.copy_err,
2054+
counters.delete_ok,
2055+
counters.delete_err,
2056+
]) {
2057+
println!(" {label:<WIDTH$} {value:>3}");
2058+
}
2059+
}
2060+
2061+
match serde_json::from_value::<TufArtifactReplicationStatus>(
2062+
details.clone(),
2063+
) {
2064+
Err(error) => eprintln!(
2065+
"warning: failed to interpret task details: {:?}: {:?}",
2066+
error, details
2067+
),
2068+
Ok(status) => {
2069+
println!(" request ringbuf:");
2070+
for TufArtifactReplicationRequest {
2071+
time,
2072+
target_sled,
2073+
operation,
2074+
error,
2075+
} in status.request_debug_ringbuf.iter()
2076+
{
2077+
println!(" - target sled: {target_sled}");
2078+
println!(" operation: {operation:?}");
2079+
println!(
2080+
" at: {}",
2081+
time.to_rfc3339_opts(SecondsFormat::Secs, true)
2082+
);
2083+
if let Some(error) = error {
2084+
println!(" error: {error}")
2085+
}
2086+
}
2087+
println!(" last run:");
2088+
print_counters(status.last_run_counters);
2089+
println!(" lifetime:");
2090+
print_counters(status.lifetime_counters);
2091+
println!(" local repos: {}", status.local_repos);
2092+
}
2093+
}
2094+
}
2095+
20272096
/// Summarizes an `ActivationReason`
20282097
fn reason_str(reason: &ActivationReason) -> &'static str {
20292098
match reason {

dev-tools/omdb/tests/env.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ task: "switch_port_config_manager"
175175
manages switch port settings for rack switches
176176

177177

178+
task: "tuf_artifact_replication"
179+
replicate update repo artifacts across sleds
180+
181+
178182
task: "v2p_manager"
179183
manages opte v2p mappings for vpc networking
180184

@@ -355,6 +359,10 @@ task: "switch_port_config_manager"
355359
manages switch port settings for rack switches
356360

357361

362+
task: "tuf_artifact_replication"
363+
replicate update repo artifacts across sleds
364+
365+
358366
task: "v2p_manager"
359367
manages opte v2p mappings for vpc networking
360368

@@ -522,6 +530,10 @@ task: "switch_port_config_manager"
522530
manages switch port settings for rack switches
523531

524532

533+
task: "tuf_artifact_replication"
534+
replicate update repo artifacts across sleds
535+
536+
525537
task: "v2p_manager"
526538
manages opte v2p mappings for vpc networking
527539

dev-tools/omdb/tests/successes.out

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ task: "switch_port_config_manager"
394394
manages switch port settings for rack switches
395395

396396

397+
task: "tuf_artifact_replication"
398+
replicate update repo artifacts across sleds
399+
400+
397401
task: "v2p_manager"
398402
manages opte v2p mappings for vpc networking
399403

@@ -724,6 +728,35 @@ task: "switch_port_config_manager"
724728
started at <REDACTED_TIMESTAMP> (<REDACTED DURATION>s ago) and ran for <REDACTED DURATION>ms
725729
warning: unknown background task: "switch_port_config_manager" (don't know how to interpret details: Object {})
726730

731+
task: "tuf_artifact_replication"
732+
configured period: every <REDACTED_DURATION>h
733+
currently executing: no
734+
last completed activation: <REDACTED ITERATIONS>, triggered by a periodic timer firing
735+
started at <REDACTED_TIMESTAMP> (<REDACTED DURATION>s ago) and ran for <REDACTED DURATION>ms
736+
request ringbuf:
737+
- target sled: ..........<REDACTED_UUID>...........
738+
operation: List
739+
at: <REDACTED_TIMESTAMP>
740+
last run:
741+
list ok: 1
742+
list err: 0
743+
put ok: 0
744+
put err: 0
745+
copy ok: 0
746+
copy err: 0
747+
delete ok: 0
748+
delete err: 0
749+
lifetime:
750+
list ok: 1
751+
list err: 0
752+
put ok: 0
753+
put err: 0
754+
copy ok: 0
755+
copy err: 0
756+
delete ok: 0
757+
delete err: 0
758+
local repos: 0
759+
727760
task: "v2p_manager"
728761
configured period: every <REDACTED_DURATION>s
729762
currently executing: no
@@ -1183,6 +1216,35 @@ task: "switch_port_config_manager"
11831216
started at <REDACTED_TIMESTAMP> (<REDACTED DURATION>s ago) and ran for <REDACTED DURATION>ms
11841217
warning: unknown background task: "switch_port_config_manager" (don't know how to interpret details: Object {})
11851218

1219+
task: "tuf_artifact_replication"
1220+
configured period: every <REDACTED_DURATION>h
1221+
currently executing: no
1222+
last completed activation: <REDACTED ITERATIONS>, triggered by a periodic timer firing
1223+
started at <REDACTED_TIMESTAMP> (<REDACTED DURATION>s ago) and ran for <REDACTED DURATION>ms
1224+
request ringbuf:
1225+
- target sled: ..........<REDACTED_UUID>...........
1226+
operation: List
1227+
at: <REDACTED_TIMESTAMP>
1228+
last run:
1229+
list ok: 1
1230+
list err: 0
1231+
put ok: 0
1232+
put err: 0
1233+
copy ok: 0
1234+
copy err: 0
1235+
delete ok: 0
1236+
delete err: 0
1237+
lifetime:
1238+
list ok: 1
1239+
list err: 0
1240+
put ok: 0
1241+
put err: 0
1242+
copy ok: 0
1243+
copy err: 0
1244+
delete ok: 0
1245+
delete err: 0
1246+
local repos: 0
1247+
11861248
task: "v2p_manager"
11871249
configured period: every <REDACTED_DURATION>s
11881250
currently executing: no

dev-tools/omdb/tests/usage_errors.out

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -315,17 +315,19 @@ Options:
315315
Show sleds that match the given filter
316316

317317
Possible values:
318-
- all: All sleds in the system, regardless of policy or state
319-
- commissioned: All sleds that are currently part of the control plane cluster
320-
- decommissioned: All sleds that were previously part of the control plane cluster
321-
but have been decommissioned
322-
- discretionary: Sleds that are eligible for discretionary services
323-
- in-service: Sleds that are in service (even if they might not be eligible
318+
- all: All sleds in the system, regardless of policy or state
319+
- commissioned: All sleds that are currently part of the control plane cluster
320+
- decommissioned: All sleds that were previously part of the control plane
321+
cluster but have been decommissioned
322+
- discretionary: Sleds that are eligible for discretionary services
323+
- in-service: Sleds that are in service (even if they might not be eligible
324324
for discretionary services)
325-
- query-during-inventory: Sleds whose sled agents should be queried for inventory
326-
- reservation-create: Sleds on which reservations can be created
327-
- vpc-routing: Sleds which should be sent OPTE V2P mappings and Routing rules
328-
- vpc-firewall: Sleds which should be sent VPC firewall rules
325+
- query-during-inventory: Sleds whose sled agents should be queried for inventory
326+
- reservation-create: Sleds on which reservations can be created
327+
- vpc-routing: Sleds which should be sent OPTE V2P mappings and Routing rules
328+
- vpc-firewall: Sleds which should be sent VPC firewall rules
329+
- tuf-artifact-replication: Sleds which should have TUF repo artifacts replicated onto
330+
them
329331

330332
--log-level <LOG_LEVEL>
331333
log level filter

nexus-config/src/nexus_config.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ pub struct BackgroundTaskConfig {
417417
/// configuration for region snapshot replacement finisher task
418418
pub region_snapshot_replacement_finish:
419419
RegionSnapshotReplacementFinishConfig,
420+
/// configuration for TUF artifact replication task
421+
pub tuf_artifact_replication: TufArtifactReplicationConfig,
420422
}
421423

422424
#[serde_as]
@@ -722,6 +724,14 @@ pub struct RegionSnapshotReplacementFinishConfig {
722724
pub period_secs: Duration,
723725
}
724726

727+
#[serde_as]
728+
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
729+
pub struct TufArtifactReplicationConfig {
730+
/// period (in seconds) for periodic activations of this background task
731+
#[serde_as(as = "DurationSeconds<u64>")]
732+
pub period_secs: Duration,
733+
}
734+
725735
/// Configuration for a nexus server
726736
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
727737
pub struct PackageConfig {
@@ -978,6 +988,7 @@ mod test {
978988
region_snapshot_replacement_garbage_collection.period_secs = 30
979989
region_snapshot_replacement_step.period_secs = 30
980990
region_snapshot_replacement_finish.period_secs = 30
991+
tuf_artifact_replication.period_secs = 300
981992
[default_region_allocation_strategy]
982993
type = "random"
983994
seed = 0
@@ -1174,6 +1185,10 @@ mod test {
11741185
RegionSnapshotReplacementFinishConfig {
11751186
period_secs: Duration::from_secs(30),
11761187
},
1188+
tuf_artifact_replication:
1189+
TufArtifactReplicationConfig {
1190+
period_secs: Duration::from_secs(300)
1191+
},
11771192
},
11781193
default_region_allocation_strategy:
11791194
crate::nexus_config::RegionAllocationStrategy::Random {
@@ -1257,6 +1272,7 @@ mod test {
12571272
region_snapshot_replacement_garbage_collection.period_secs = 30
12581273
region_snapshot_replacement_step.period_secs = 30
12591274
region_snapshot_replacement_finish.period_secs = 30
1275+
tuf_artifact_replication.period_secs = 300
12601276
[default_region_allocation_strategy]
12611277
type = "random"
12621278
"##,

nexus/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ license = "MPL-2.0"
77
[lints]
88
workspace = true
99

10+
[features]
11+
# Set by omicron-package based on the target configuration.
12+
rack-topology-single-sled = []
13+
1014
[build-dependencies]
1115
omicron-rpaths.workspace = true
1216

nexus/db-model/src/schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@ table! {
907907
sled_policy -> crate::sled_policy::SledPolicyEnum,
908908
sled_state -> crate::SledStateEnum,
909909
sled_agent_gen -> Int8,
910+
repo_depot_port -> Int4,
910911
}
911912
}
912913

nexus/db-model/src/schema_versions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::collections::BTreeMap;
1717
///
1818
/// This must be updated when you change the database schema. Refer to
1919
/// schema/crdb/README.adoc in the root of this repository for details.
20-
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(120, 0, 0);
20+
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(121, 0, 0);
2121

2222
/// List of all past database schema versions, in *reverse* order
2323
///
@@ -29,6 +29,7 @@ static KNOWN_VERSIONS: Lazy<Vec<KnownVersion>> = Lazy::new(|| {
2929
// | leaving the first copy as an example for the next person.
3030
// v
3131
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
32+
KnownVersion::new(121, "tuf-artifact-replication"),
3233
KnownVersion::new(120, "rendezvous-debug-dataset"),
3334
KnownVersion::new(119, "tuf-artifact-key-uuid"),
3435
KnownVersion::new(118, "support-bundles"),

nexus/db-model/src/sled.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ pub struct Sled {
8181
/// This is specifically distinct from `rcgen`, which is incremented by
8282
/// child resources as part of `DatastoreCollectionConfig`.
8383
pub sled_agent_gen: Generation,
84+
85+
// ServiceAddress (Repo Depot API). Uses `ip`.
86+
pub repo_depot_port: SqlU16,
8487
}
8588

8689
impl Sled {
@@ -169,6 +172,7 @@ impl From<Sled> for params::SledAgentInfo {
169172
};
170173
Self {
171174
sa_address: sled.address(),
175+
repo_depot_port: sled.repo_depot_port.into(),
172176
role,
173177
baseboard: Baseboard {
174178
serial: sled.serial_number.clone(),
@@ -220,6 +224,9 @@ pub struct SledUpdate {
220224
pub ip: ipv6::Ipv6Addr,
221225
pub port: SqlU16,
222226

227+
// ServiceAddress (Repo Depot API). Uses `ip`.
228+
pub repo_depot_port: SqlU16,
229+
223230
// Generation number - owned and incremented by sled-agent.
224231
pub sled_agent_gen: Generation,
225232
}
@@ -228,6 +235,7 @@ impl SledUpdate {
228235
pub fn new(
229236
id: Uuid,
230237
addr: SocketAddrV6,
238+
repo_depot_port: u16,
231239
baseboard: SledBaseboard,
232240
hardware: SledSystemHardware,
233241
rack_id: Uuid,
@@ -247,6 +255,7 @@ impl SledUpdate {
247255
reservoir_size: hardware.reservoir_size,
248256
ip: addr.ip().into(),
249257
port: addr.port().into(),
258+
repo_depot_port: repo_depot_port.into(),
250259
sled_agent_gen,
251260
}
252261
}
@@ -282,6 +291,7 @@ impl SledUpdate {
282291
reservoir_size: self.reservoir_size,
283292
ip: self.ip,
284293
port: self.port,
294+
repo_depot_port: self.repo_depot_port,
285295
last_used_address,
286296
sled_agent_gen: self.sled_agent_gen,
287297
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ mod test {
376376
let sled = SledUpdate::new(
377377
*sled_id.as_untyped_uuid(),
378378
"[::1]:0".parse().unwrap(),
379+
0,
379380
SledBaseboard {
380381
serial_number: "test-sn".to_string(),
381382
part_number: "test-pn".to_string(),

0 commit comments

Comments
 (0)