feat: seed production-like backup histories
This commit is contained in:
@@ -31,9 +31,28 @@ struct DemoOrbit {
|
|||||||
dry_run: bool,
|
dry_run: bool,
|
||||||
status: &'static str,
|
status: &'static str,
|
||||||
snap_count: usize,
|
snap_count: usize,
|
||||||
|
interval_hours: i64,
|
||||||
base_size_kb: u32,
|
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 {
|
fn demo_id(kind: &str, name: &str) -> Uuid {
|
||||||
Uuid::new_v5(&Uuid::NAMESPACE_OID, format!("{DEMO_NS}:{kind}:{name}").as_bytes())
|
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 {
|
for i in 0..o.snap_count {
|
||||||
let snap_id = demo_id("snap", &format!("{}:{}", o.slug, i));
|
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 taken_at = now - o.snapshot_age(i);
|
||||||
let payload = synthetic_payload(o.slug, o.base_size_kb + (i as u32) * 17);
|
let payload = synthetic_payload(o.slug, o.snapshot_size_kb(i));
|
||||||
let manifest = SnapshotManifest {
|
let manifest = SnapshotManifest {
|
||||||
snapshot_id: snap_id,
|
snapshot_id: snap_id,
|
||||||
orbit_id,
|
orbit_id,
|
||||||
@@ -236,134 +255,169 @@ fn demo_orbits() -> Vec<DemoOrbit> {
|
|||||||
DemoOrbit {
|
DemoOrbit {
|
||||||
slug: "prod-api",
|
slug: "prod-api",
|
||||||
provider: "postgres",
|
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 * * *",
|
schedule: "0 2 * * *",
|
||||||
decay: "year-of-monthlies",
|
decay: "year-of-monthlies",
|
||||||
dry_run: false,
|
dry_run: false,
|
||||||
status: "completed",
|
status: "completed",
|
||||||
snap_count: 4,
|
snap_count: 24,
|
||||||
base_size_kb: 420,
|
interval_hours: 24,
|
||||||
|
base_size_kb: 2560,
|
||||||
},
|
},
|
||||||
DemoOrbit {
|
DemoOrbit {
|
||||||
slug: "wiki",
|
slug: "wiki",
|
||||||
provider: "filesystem",
|
provider: "filesystem",
|
||||||
config: serde_json::json!({ "paths": ["/data/wiki"] }),
|
config: serde_json::json!({ "paths": ["/_tessera_demo/wiki"] }),
|
||||||
schedule: "0 3 * * *",
|
schedule: "0 3 * * *",
|
||||||
decay: "week-of-dailies",
|
decay: "week-of-dailies",
|
||||||
dry_run: false,
|
dry_run: false,
|
||||||
status: "completed",
|
status: "completed",
|
||||||
snap_count: 3,
|
snap_count: 14,
|
||||||
base_size_kb: 88,
|
interval_hours: 24,
|
||||||
|
base_size_kb: 256,
|
||||||
},
|
},
|
||||||
DemoOrbit {
|
DemoOrbit {
|
||||||
slug: "gitea",
|
slug: "gitea",
|
||||||
provider: "filesystem",
|
provider: "filesystem",
|
||||||
config: serde_json::json!({ "paths": ["/var/gitea"] }),
|
config: serde_json::json!({ "paths": ["/_tessera_demo/gitea"] }),
|
||||||
schedule: "0 1 * * *",
|
schedule: "0 1 * * *",
|
||||||
decay: "month-of-weeklies",
|
decay: "month-of-weeklies",
|
||||||
dry_run: false,
|
dry_run: false,
|
||||||
status: "running",
|
status: "running",
|
||||||
snap_count: 3,
|
snap_count: 18,
|
||||||
base_size_kb: 220,
|
interval_hours: 24,
|
||||||
|
base_size_kb: 1024,
|
||||||
},
|
},
|
||||||
DemoOrbit {
|
DemoOrbit {
|
||||||
slug: "monitoring",
|
slug: "monitoring",
|
||||||
provider: "filesystem",
|
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 * * *",
|
schedule: "0 */6 * * *",
|
||||||
decay: "week-of-dailies",
|
decay: "week-of-dailies",
|
||||||
dry_run: false,
|
dry_run: false,
|
||||||
status: "completed",
|
status: "completed",
|
||||||
snap_count: 3,
|
snap_count: 28,
|
||||||
base_size_kb: 64,
|
interval_hours: 6,
|
||||||
|
base_size_kb: 96,
|
||||||
},
|
},
|
||||||
DemoOrbit {
|
DemoOrbit {
|
||||||
slug: "staging-db",
|
slug: "staging-db",
|
||||||
provider: "postgres",
|
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",
|
schedule: "0 4 * * 0",
|
||||||
decay: "week-of-dailies",
|
decay: "week-of-dailies",
|
||||||
dry_run: false,
|
dry_run: false,
|
||||||
status: "failed",
|
status: "failed",
|
||||||
snap_count: 2,
|
snap_count: 8,
|
||||||
base_size_kb: 310,
|
interval_hours: 168,
|
||||||
|
base_size_kb: 640,
|
||||||
},
|
},
|
||||||
DemoOrbit {
|
DemoOrbit {
|
||||||
slug: "legal-docs",
|
slug: "legal-docs",
|
||||||
provider: "filesystem",
|
provider: "filesystem",
|
||||||
config: serde_json::json!({ "paths": ["/vault/legal"] }),
|
config: serde_json::json!({ "paths": ["/_tessera_demo/legal"] }),
|
||||||
schedule: "0 0 * * 1",
|
schedule: "0 0 * * 1",
|
||||||
decay: "year-of-monthlies",
|
decay: "year-of-monthlies",
|
||||||
dry_run: false,
|
dry_run: false,
|
||||||
status: "completed",
|
status: "completed",
|
||||||
snap_count: 2,
|
snap_count: 12,
|
||||||
base_size_kb: 1200,
|
interval_hours: 168,
|
||||||
|
base_size_kb: 3072,
|
||||||
},
|
},
|
||||||
DemoOrbit {
|
DemoOrbit {
|
||||||
slug: "matrix-synapse",
|
slug: "matrix-synapse",
|
||||||
provider: "filesystem",
|
provider: "filesystem",
|
||||||
config: serde_json::json!({ "paths": ["/var/matrix"] }),
|
config: serde_json::json!({ "paths": ["/_tessera_demo/matrix"] }),
|
||||||
schedule: "0 2 * * *",
|
schedule: "0 2 * * *",
|
||||||
decay: "month-of-weeklies",
|
decay: "month-of-weeklies",
|
||||||
dry_run: false,
|
dry_run: false,
|
||||||
status: "completed",
|
status: "completed",
|
||||||
snap_count: 3,
|
snap_count: 16,
|
||||||
base_size_kb: 540,
|
interval_hours: 24,
|
||||||
|
base_size_kb: 768,
|
||||||
},
|
},
|
||||||
DemoOrbit {
|
DemoOrbit {
|
||||||
slug: "home-assistant",
|
slug: "home-assistant",
|
||||||
provider: "filesystem",
|
provider: "filesystem",
|
||||||
config: serde_json::json!({ "paths": ["/config"] }),
|
config: serde_json::json!({ "paths": ["/_tessera_demo/home-assistant"] }),
|
||||||
schedule: "0 */12 * * *",
|
schedule: "0 */12 * * *",
|
||||||
decay: "week-of-dailies",
|
decay: "week-of-dailies",
|
||||||
dry_run: false,
|
dry_run: false,
|
||||||
status: "completed",
|
status: "completed",
|
||||||
snap_count: 2,
|
snap_count: 21,
|
||||||
base_size_kb: 45,
|
interval_hours: 12,
|
||||||
|
base_size_kb: 64,
|
||||||
},
|
},
|
||||||
DemoOrbit {
|
DemoOrbit {
|
||||||
slug: "deno-api",
|
slug: "deno-api",
|
||||||
provider: "filesystem",
|
provider: "filesystem",
|
||||||
config: serde_json::json!({ "paths": ["/app/deno"] }),
|
config: serde_json::json!({ "paths": ["/_tessera_demo/deno"] }),
|
||||||
schedule: "0 5 * * *",
|
schedule: "0 5 * * *",
|
||||||
decay: "week-of-dailies",
|
decay: "week-of-dailies",
|
||||||
dry_run: false,
|
dry_run: false,
|
||||||
status: "completed",
|
status: "completed",
|
||||||
snap_count: 3,
|
snap_count: 14,
|
||||||
base_size_kb: 96,
|
interval_hours: 24,
|
||||||
|
base_size_kb: 192,
|
||||||
},
|
},
|
||||||
DemoOrbit {
|
DemoOrbit {
|
||||||
slug: "mail-archive",
|
slug: "mail-archive",
|
||||||
provider: "filesystem",
|
provider: "filesystem",
|
||||||
config: serde_json::json!({ "paths": ["/mail/archive"] }),
|
config: serde_json::json!({ "paths": ["/_tessera_demo/mail"] }),
|
||||||
schedule: "0 3 * * 6",
|
schedule: "0 3 * * 6",
|
||||||
decay: "year-of-monthlies",
|
decay: "year-of-monthlies",
|
||||||
dry_run: false,
|
dry_run: false,
|
||||||
status: "completed",
|
status: "failed",
|
||||||
snap_count: 2,
|
snap_count: 12,
|
||||||
base_size_kb: 890,
|
interval_hours: 168,
|
||||||
|
base_size_kb: 1792,
|
||||||
},
|
},
|
||||||
DemoOrbit {
|
DemoOrbit {
|
||||||
slug: "rehearse-nightly",
|
slug: "rehearse-nightly",
|
||||||
provider: "filesystem",
|
provider: "filesystem",
|
||||||
config: serde_json::json!({ "paths": ["/tmp/rehearse"] }),
|
config: serde_json::json!({ "paths": ["/_tessera_demo/rehearse"] }),
|
||||||
schedule: "0 2 * * *",
|
schedule: "0 2 * * *",
|
||||||
decay: "week-of-dailies",
|
decay: "week-of-dailies",
|
||||||
dry_run: true,
|
dry_run: true,
|
||||||
status: "rehearsed",
|
status: "rehearsed",
|
||||||
snap_count: 0,
|
snap_count: 0,
|
||||||
|
interval_hours: 24,
|
||||||
base_size_kb: 0,
|
base_size_kb: 0,
|
||||||
},
|
},
|
||||||
DemoOrbit {
|
DemoOrbit {
|
||||||
slug: "observability-pg",
|
slug: "observability-pg",
|
||||||
provider: "postgres",
|
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 * * *",
|
schedule: "0 1 * * *",
|
||||||
decay: "month-of-weeklies",
|
decay: "month-of-weeklies",
|
||||||
dry_run: false,
|
dry_run: false,
|
||||||
status: "completed",
|
status: "completed",
|
||||||
snap_count: 3,
|
snap_count: 18,
|
||||||
base_size_kb: 180,
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user