12c1af0261
crates/horizon-telemetry-server, its own workspace like the launcher's (the game's workspace never builds a web server): - POST /v1/batch (zstd, decoded and checked by horizon-telemetry), DELETE /v1/installs/<id>, GET /v1/aggregate (cached 10 min, CORS for the website), GET /healthz. - SQLite: machine descriptions stored once, one row of columns per session with 80-byte summary blobs, zstd bodies for crash/bug/benchmark, daily totals rebuilt when a day changes and kept after raw rows expire (180 days). About 190 bytes per session on disk. - Per-address token bucket (addresses in memory only), per-install daily cap, groups under 5 install-days hidden from the totals. - Tests: refusals, rate limit, daily cap, deletion (rows and totals), retention, storage size, and end to end with the launcher's uploader. - Dockerfile and a path-filtered CI workflow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
41 lines
1.5 KiB
Rust
41 lines
1.5 KiB
Rust
//! `horizon-telemetry-server`: serves on `PORT` (default 8080), keeps its data in
|
|
//! `HORIZON_TELEMETRY_DB` (default `telemetry.sqlite3`), and does its upkeep every ten minutes.
|
|
use std::net::SocketAddr;
|
|
use std::time::Duration;
|
|
|
|
use horizon_telemetry_server::{App, Config, router, store::Store};
|
|
|
|
#[tokio::main(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn main() {
|
|
let path = std::env::var("HORIZON_TELEMETRY_DB").unwrap_or_else(|_| "telemetry.sqlite3".into());
|
|
let port: u16 = std::env::var("PORT")
|
|
.ok()
|
|
.and_then(|p| p.parse().ok())
|
|
.unwrap_or(8080);
|
|
let store = Store::open(&path).unwrap_or_else(|e| panic!("{path}: {e}"));
|
|
let app = App::new(store, Config::from_env());
|
|
let upkeep = app.clone();
|
|
tokio::spawn(async move {
|
|
let mut every = tokio::time::interval(Duration::from_secs(600));
|
|
loop {
|
|
every.tick().await;
|
|
if let Err(e) = upkeep.maintain() {
|
|
eprintln!("horizon-telemetry-server: upkeep failed: {e}");
|
|
}
|
|
}
|
|
});
|
|
let listener = tokio::net::TcpListener::bind(SocketAddr::from(([0, 0, 0, 0], port)))
|
|
.await
|
|
.unwrap_or_else(|e| panic!("port {port}: {e}"));
|
|
eprintln!("horizon-telemetry-server: listening on {port}, data in {path}");
|
|
axum::serve(
|
|
listener,
|
|
router(app).into_make_service_with_connect_info::<SocketAddr>(),
|
|
)
|
|
.with_graceful_shutdown(async {
|
|
let _ = tokio::signal::ctrl_c().await;
|
|
})
|
|
.await
|
|
.unwrap_or_else(|e| panic!("{e}"));
|
|
}
|