Skip to content

Commit 65b3308

Browse files
authored
add background task to prune TUF repos (#9107)
1 parent c6628ce commit 65b3308

File tree

24 files changed

+1517
-6
lines changed

24 files changed

+1517
-6
lines changed

Cargo.lock

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

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ use nexus_types::internal_api::background::SupportBundleEreportStatus;
7070
use nexus_types::internal_api::background::TufArtifactReplicationCounters;
7171
use nexus_types::internal_api::background::TufArtifactReplicationRequest;
7272
use nexus_types::internal_api::background::TufArtifactReplicationStatus;
73+
use nexus_types::internal_api::background::TufRepoPrunerStatus;
7374
use nexus_types::inventory::BaseboardId;
7475
use omicron_uuid_kinds::BlueprintUuid;
7576
use omicron_uuid_kinds::CollectionUuid;
@@ -1199,6 +1200,9 @@ fn print_task_details(bgtask: &BackgroundTask, details: &serde_json::Value) {
11991200
"tuf_artifact_replication" => {
12001201
print_task_tuf_artifact_replication(details);
12011202
}
1203+
"tuf_repo_pruner" => {
1204+
print_task_tuf_repo_pruner(details);
1205+
}
12021206
"alert_dispatcher" => {
12031207
print_task_alert_dispatcher(details);
12041208
}
@@ -2573,6 +2577,19 @@ fn print_task_tuf_artifact_replication(details: &serde_json::Value) {
25732577
}
25742578
}
25752579

2580+
fn print_task_tuf_repo_pruner(details: &serde_json::Value) {
2581+
match serde_json::from_value::<TufRepoPrunerStatus>(details.clone()) {
2582+
Err(error) => eprintln!(
2583+
"warning: failed to interpret task details: {}: {:?}",
2584+
InlineErrorChain::new(&error),
2585+
details
2586+
),
2587+
Ok(status) => {
2588+
print!("{}", status);
2589+
}
2590+
}
2591+
}
2592+
25762593
fn print_task_alert_dispatcher(details: &serde_json::Value) {
25772594
use nexus_types::internal_api::background::AlertDispatched;
25782595
use nexus_types::internal_api::background::AlertDispatcherStatus;

dev-tools/omdb/tests/env.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ task: "tuf_artifact_replication"
199199
replicate update repo artifacts across sleds
200200

201201

202+
task: "tuf_repo_pruner"
203+
determine which TUF repos' artifacts can be pruned
204+
205+
202206
task: "v2p_manager"
203207
manages opte v2p mappings for vpc networking
204208

@@ -407,6 +411,10 @@ task: "tuf_artifact_replication"
407411
replicate update repo artifacts across sleds
408412

409413

414+
task: "tuf_repo_pruner"
415+
determine which TUF repos' artifacts can be pruned
416+
417+
410418
task: "v2p_manager"
411419
manages opte v2p mappings for vpc networking
412420

@@ -602,6 +610,10 @@ task: "tuf_artifact_replication"
602610
replicate update repo artifacts across sleds
603611

604612

613+
task: "tuf_repo_pruner"
614+
determine which TUF repos' artifacts can be pruned
615+
616+
605617
task: "v2p_manager"
606618
manages opte v2p mappings for vpc networking
607619

dev-tools/omdb/tests/successes.out

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@ task: "tuf_artifact_replication"
434434
replicate update repo artifacts across sleds
435435

436436

437+
task: "tuf_repo_pruner"
438+
determine which TUF repos' artifacts can be pruned
439+
440+
437441
task: "v2p_manager"
438442
manages opte v2p mappings for vpc networking
439443

@@ -819,6 +823,18 @@ task: "tuf_artifact_replication"
819823
copy err: 0
820824
local repos: 0
821825

826+
task: "tuf_repo_pruner"
827+
configured period: every <REDACTED_DURATION>m
828+
last completed activation: <REDACTED ITERATIONS>, triggered by <TRIGGERED_BY_REDACTED>
829+
started at <REDACTED_TIMESTAMP> (<REDACTED DURATION>s ago) and ran for <REDACTED DURATION>ms
830+
configuration:
831+
nkeep_recent_releases: 3
832+
nkeep_recent_uploads: 3
833+
repo pruned: none
834+
repos kept because they're recent target releases: none
835+
repos kept because they're recent uploads: none
836+
other repos eligible for pruning: none
837+
822838
task: "v2p_manager"
823839
configured period: every <REDACTED_DURATION>s
824840
last completed activation: <REDACTED ITERATIONS>, triggered by <TRIGGERED_BY_REDACTED>
@@ -1335,6 +1351,18 @@ task: "tuf_artifact_replication"
13351351
copy err: 0
13361352
local repos: 0
13371353

1354+
task: "tuf_repo_pruner"
1355+
configured period: every <REDACTED_DURATION>m
1356+
last completed activation: <REDACTED ITERATIONS>, triggered by <TRIGGERED_BY_REDACTED>
1357+
started at <REDACTED_TIMESTAMP> (<REDACTED DURATION>s ago) and ran for <REDACTED DURATION>ms
1358+
configuration:
1359+
nkeep_recent_releases: 3
1360+
nkeep_recent_uploads: 3
1361+
repo pruned: none
1362+
repos kept because they're recent target releases: none
1363+
repos kept because they're recent uploads: none
1364+
other repos eligible for pruning: none
1365+
13381366
task: "v2p_manager"
13391367
configured period: every <REDACTED_DURATION>s
13401368
last completed activation: <REDACTED ITERATIONS>, triggered by <TRIGGERED_BY_REDACTED>

nexus-config/src/nexus_config.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ pub struct BackgroundTaskConfig {
430430
RegionSnapshotReplacementFinishConfig,
431431
/// configuration for TUF artifact replication task
432432
pub tuf_artifact_replication: TufArtifactReplicationConfig,
433+
/// configuration for TUF repo pruner task
434+
pub tuf_repo_pruner: TufRepoPrunerConfig,
433435
/// configuration for read-only region replacement start task
434436
pub read_only_region_replacement_start:
435437
ReadOnlyRegionReplacementStartConfig,
@@ -765,6 +767,26 @@ pub struct TufArtifactReplicationConfig {
765767
pub min_sled_replication: usize,
766768
}
767769

770+
#[serde_as]
771+
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
772+
pub struct TufRepoPrunerConfig {
773+
/// period (in seconds) for periodic activations of this background task
774+
#[serde_as(as = "DurationSeconds<u64>")]
775+
pub period_secs: Duration,
776+
777+
/// number of extra recent target releases to keep
778+
///
779+
/// The system always keeps two: the current release and the previous one.
780+
/// This number is in addition to that.
781+
pub nkeep_extra_target_releases: u8,
782+
783+
/// number of extra recently uploaded repos to keep
784+
///
785+
/// The system always keeps one, assuming that the operator may be about to
786+
/// update to it. This number is in addition to that.
787+
pub nkeep_extra_newly_uploaded: u8,
788+
}
789+
768790
#[serde_as]
769791
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
770792
pub struct ReadOnlyRegionReplacementStartConfig {
@@ -1119,6 +1141,9 @@ mod test {
11191141
region_snapshot_replacement_finish.period_secs = 30
11201142
tuf_artifact_replication.period_secs = 300
11211143
tuf_artifact_replication.min_sled_replication = 3
1144+
tuf_repo_pruner.period_secs = 299
1145+
tuf_repo_pruner.nkeep_extra_target_releases = 51
1146+
tuf_repo_pruner.nkeep_extra_newly_uploaded = 52
11221147
read_only_region_replacement_start.period_secs = 30
11231148
alert_dispatcher.period_secs = 42
11241149
webhook_deliverator.period_secs = 43
@@ -1342,6 +1367,11 @@ mod test {
13421367
period_secs: Duration::from_secs(300),
13431368
min_sled_replication: 3,
13441369
},
1370+
tuf_repo_pruner: TufRepoPrunerConfig {
1371+
period_secs: Duration::from_secs(299),
1372+
nkeep_extra_target_releases: 51,
1373+
nkeep_extra_newly_uploaded: 52,
1374+
},
13451375
read_only_region_replacement_start:
13461376
ReadOnlyRegionReplacementStartConfig {
13471377
period_secs: Duration::from_secs(30),
@@ -1449,6 +1479,9 @@ mod test {
14491479
region_snapshot_replacement_finish.period_secs = 30
14501480
tuf_artifact_replication.period_secs = 300
14511481
tuf_artifact_replication.min_sled_replication = 3
1482+
tuf_repo_pruner.period_secs = 299
1483+
tuf_repo_pruner.nkeep_extra_target_releases = 51
1484+
tuf_repo_pruner.nkeep_extra_newly_uploaded = 52
14521485
read_only_region_replacement_start.period_secs = 30
14531486
alert_dispatcher.period_secs = 42
14541487
webhook_deliverator.period_secs = 43

nexus/background-task-interface/src/init.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub struct BackgroundTasks {
4444
pub task_region_snapshot_replacement_step: Activator,
4545
pub task_region_snapshot_replacement_finish: Activator,
4646
pub task_tuf_artifact_replication: Activator,
47+
pub task_tuf_repo_pruner: Activator,
4748
pub task_read_only_region_replacement_start: Activator,
4849
pub task_alert_dispatcher: Activator,
4950
pub task_webhook_deliverator: Activator,

nexus/db-model/src/schema_versions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{collections::BTreeMap, sync::LazyLock};
1616
///
1717
/// This must be updated when you change the database schema. Refer to
1818
/// schema/crdb/README.adoc in the root of this repository for details.
19-
pub const SCHEMA_VERSION: Version = Version::new(194, 0, 0);
19+
pub const SCHEMA_VERSION: Version = Version::new(195, 0, 0);
2020

2121
/// List of all past database schema versions, in *reverse* order
2222
///
@@ -28,6 +28,7 @@ static KNOWN_VERSIONS: LazyLock<Vec<KnownVersion>> = LazyLock::new(|| {
2828
// | leaving the first copy as an example for the next person.
2929
// v
3030
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
31+
KnownVersion::new(195, "tuf-pruned-index"),
3132
KnownVersion::new(194, "tuf-pruned"),
3233
KnownVersion::new(193, "nexus-lockstep-port"),
3334
KnownVersion::new(192, "blueprint-source"),

0 commit comments

Comments
 (0)