feat: seed production-like backup histories

This commit is contained in:
2026-11-09 22:23:03 +07:00
parent fba4a1e628
commit 34154b2ef1

View File

@@ -31,9 +31,28 @@ struct DemoOrbit {
dry_run: bool,
status: &'static str,
snap_count: usize,
interval_hours: i64,
base_size_kb: u32,
}
impl DemoOrbit {
fn snapshot_age(&self, index: usize) -> Duration {
let since_last_success = if self.status == "failed" {
self.interval_hours * 3
} else {
self.interval_hours / 3
};
let jitter = ((index * 13 + self.slug.len() * 7) % 45) as i64;
Duration::hours(since_last_success + index as i64 * self.interval_hours)
+ Duration::minutes(jitter)
}
fn snapshot_size_kb(&self, index: usize) -> u32 {
let variation = 84 + ((index * 7 + self.slug.len() * 3) % 33) as u32;
self.base_size_kb * variation / 100
}
}
fn demo_id(kind: &str, name: &str) -> Uuid {
Uuid::new_v5(&Uuid::NAMESPACE_OID, format!("{DEMO_NS}:{kind}:{name}").as_bytes())
}
@@ -98,8 +117,8 @@ pub fn apply(data_dir: &Path, vault_pass: &str, force: bool) -> Result<SeedRepor
for i in 0..o.snap_count {
let snap_id = demo_id("snap", &format!("{}:{}", o.slug, i));
let taken_at = now - Duration::hours((i as i64 + 1) * 9 + (o.slug.len() as i64 % 5));
let payload = synthetic_payload(o.slug, o.base_size_kb + (i as u32) * 17);
let taken_at = now - o.snapshot_age(i);
let payload = synthetic_payload(o.slug, o.snapshot_size_kb(i));
let manifest = SnapshotManifest {
snapshot_id: snap_id,
orbit_id,
@@ -236,134 +255,169 @@ fn demo_orbits() -> Vec<DemoOrbit> {
DemoOrbit {
slug: "prod-api",
provider: "postgres",
config: serde_json::json!({ "connection_url": "postgres://demo/prod" }),
config: serde_json::json!({ "connection_url": "postgres://postgres.demo.invalid/prod" }),
schedule: "0 2 * * *",
decay: "year-of-monthlies",
dry_run: false,
status: "completed",
snap_count: 4,
base_size_kb: 420,
snap_count: 24,
interval_hours: 24,
base_size_kb: 2560,
},
DemoOrbit {
slug: "wiki",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/data/wiki"] }),
config: serde_json::json!({ "paths": ["/_tessera_demo/wiki"] }),
schedule: "0 3 * * *",
decay: "week-of-dailies",
dry_run: false,
status: "completed",
snap_count: 3,
base_size_kb: 88,
snap_count: 14,
interval_hours: 24,
base_size_kb: 256,
},
DemoOrbit {
slug: "gitea",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/var/gitea"] }),
config: serde_json::json!({ "paths": ["/_tessera_demo/gitea"] }),
schedule: "0 1 * * *",
decay: "month-of-weeklies",
dry_run: false,
status: "running",
snap_count: 3,
base_size_kb: 220,
snap_count: 18,
interval_hours: 24,
base_size_kb: 1024,
},
DemoOrbit {
slug: "monitoring",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/etc/prometheus", "/var/lib/grafana"] }),
config: serde_json::json!({ "paths": ["/_tessera_demo/prometheus", "/_tessera_demo/grafana"] }),
schedule: "0 */6 * * *",
decay: "week-of-dailies",
dry_run: false,
status: "completed",
snap_count: 3,
base_size_kb: 64,
snap_count: 28,
interval_hours: 6,
base_size_kb: 96,
},
DemoOrbit {
slug: "staging-db",
provider: "postgres",
config: serde_json::json!({ "connection_url": "postgres://demo/staging" }),
config: serde_json::json!({ "connection_url": "postgres://postgres.demo.invalid/staging" }),
schedule: "0 4 * * 0",
decay: "week-of-dailies",
dry_run: false,
status: "failed",
snap_count: 2,
base_size_kb: 310,
snap_count: 8,
interval_hours: 168,
base_size_kb: 640,
},
DemoOrbit {
slug: "legal-docs",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/vault/legal"] }),
config: serde_json::json!({ "paths": ["/_tessera_demo/legal"] }),
schedule: "0 0 * * 1",
decay: "year-of-monthlies",
dry_run: false,
status: "completed",
snap_count: 2,
base_size_kb: 1200,
snap_count: 12,
interval_hours: 168,
base_size_kb: 3072,
},
DemoOrbit {
slug: "matrix-synapse",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/var/matrix"] }),
config: serde_json::json!({ "paths": ["/_tessera_demo/matrix"] }),
schedule: "0 2 * * *",
decay: "month-of-weeklies",
dry_run: false,
status: "completed",
snap_count: 3,
base_size_kb: 540,
snap_count: 16,
interval_hours: 24,
base_size_kb: 768,
},
DemoOrbit {
slug: "home-assistant",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/config"] }),
config: serde_json::json!({ "paths": ["/_tessera_demo/home-assistant"] }),
schedule: "0 */12 * * *",
decay: "week-of-dailies",
dry_run: false,
status: "completed",
snap_count: 2,
base_size_kb: 45,
snap_count: 21,
interval_hours: 12,
base_size_kb: 64,
},
DemoOrbit {
slug: "deno-api",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/app/deno"] }),
config: serde_json::json!({ "paths": ["/_tessera_demo/deno"] }),
schedule: "0 5 * * *",
decay: "week-of-dailies",
dry_run: false,
status: "completed",
snap_count: 3,
base_size_kb: 96,
snap_count: 14,
interval_hours: 24,
base_size_kb: 192,
},
DemoOrbit {
slug: "mail-archive",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/mail/archive"] }),
config: serde_json::json!({ "paths": ["/_tessera_demo/mail"] }),
schedule: "0 3 * * 6",
decay: "year-of-monthlies",
dry_run: false,
status: "completed",
snap_count: 2,
base_size_kb: 890,
status: "failed",
snap_count: 12,
interval_hours: 168,
base_size_kb: 1792,
},
DemoOrbit {
slug: "rehearse-nightly",
provider: "filesystem",
config: serde_json::json!({ "paths": ["/tmp/rehearse"] }),
config: serde_json::json!({ "paths": ["/_tessera_demo/rehearse"] }),
schedule: "0 2 * * *",
decay: "week-of-dailies",
dry_run: true,
status: "rehearsed",
snap_count: 0,
interval_hours: 24,
base_size_kb: 0,
},
DemoOrbit {
slug: "observability-pg",
provider: "postgres",
config: serde_json::json!({ "connection_url": "postgres://demo/metrics" }),
config: serde_json::json!({ "connection_url": "postgres://postgres.demo.invalid/metrics" }),
schedule: "0 1 * * *",
decay: "month-of-weeklies",
dry_run: false,
status: "completed",
snap_count: 3,
base_size_kb: 180,
snap_count: 18,
interval_hours: 24,
base_size_kb: 896,
},
]
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn demo_history_has_volume_and_preserves_capture_cadence() {
let orbits = demo_orbits();
assert_eq!(orbits.iter().filter(|orbit| !orbit.dry_run).count(), 11);
assert!(orbits.iter().map(|orbit| orbit.snap_count).sum::<usize>() >= 180);
for orbit in orbits {
if orbit.dry_run {
assert_eq!(orbit.snap_count, 0);
continue;
}
assert!(orbit.snapshot_age(0) > Duration::zero());
for index in 1..orbit.snap_count {
let gap = orbit.snapshot_age(index) - orbit.snapshot_age(index - 1);
assert!((gap - Duration::hours(orbit.interval_hours)).num_minutes().abs() < 45);
}
}
}
}