chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
0
0
HUD_LOGS_DB names the file the kept lines go in
crates/hud/src/main.rs+19−11
| @@ -76,7 +76,8 @@ Configuration, from the environment: | ||
HUD_DATA_DIR where sign-in's key, sessions and registered clients | ||
(under oauth/), the workspace's canvases (under | ||
canvas/) and, with HUD_LOGS, the lines logged | ||
(logs.db) are kept, files mode 0600 (HUD_CACHE_DIR) | ||
(logs.db, unless HUD_LOGS_DB) are kept, files mode 0600 | ||
(HUD_CACHE_DIR) | ||
HUD_OAUTH on or off: sign-in, the write and canvas tools, the | ||
workspace, and queries through the account's PDS (on | ||
when HUD_PUBLIC_URL is https, which on requires) | ||
| @@ -157,11 +158,13 @@ Configuration, from the environment: | ||
(Prometheus) and PUT /log (a RUST_LOG directive, to | ||
change what is logged until a restart), as | ||
127.0.0.1:9464 (unset: off) | ||
HUD_LOGS on or off: keep every line logged in | ||
HUD_DATA_DIR/logs.db too, for HUD_OPERATOR_DIDS to read | ||
with place.hud.getLogs and admin_logs; hud index keeps | ||
its own there too, so with the same HUD_DATA_DIR they | ||
read both (off) | ||
HUD_LOGS on or off: keep every line logged in HUD_LOGS_DB too, | ||
for HUD_OPERATOR_DIDS to read with place.hud.getLogs | ||
and admin_logs; hud index keeps its own there too, so | ||
given the same file they read both (off) | ||
HUD_LOGS_DB the SQLite file those lines are kept in, as | ||
/logs/logs.db: in a directory of its own, it can be | ||
shared with hud index alone (HUD_DATA_DIR/logs.db) | ||
HUD_LOGS_KEEP how many lines at info and below are kept there; every | ||
line goes after 30 days (500000) | ||
HUD_OPERATOR_DIDS the DIDs of the accounts that run this server, by | ||
| @@ -197,7 +200,8 @@ Configuration, from the environment: | ||
separated by commas or spaces (none) | ||
| ||
hud index, beside HUD_BIND, HUD_DATA_DIR, HUD_RELAY, HUD_PLC_URL, | ||
HUD_ALLOW_PRIVATE, RUST_LOG, HUD_SLOW_MS, HUD_LOGS and HUD_LOGS_KEEP above: | ||
HUD_ALLOW_PRIVATE, RUST_LOG, HUD_SLOW_MS, HUD_LOGS, HUD_LOGS_DB and | ||
HUD_LOGS_KEEP above: | ||
HUD_INDEX_PORT listen port (8790) | ||
HUD_INDEX_URL the origin the index is reached at, which names its | ||
did:web (http://localhost:<port>) | ||
| @@ -607,11 +611,14 @@ fn config() -> Result<Config, String> { | ||
}; | ||
let chat = chat(bind, port)?; | ||
let app_blocks = hud_core::frames::blocks(&var("HUD_APP_BLOCKS")?.unwrap_or_default())?; | ||
let data_dir = var("HUD_DATA_DIR")?.map_or_else(|| cache_dir.clone(), PathBuf::from); | ||
let logs_db = var("HUD_LOGS_DB")?.map(PathBuf::from); | ||
let logs = logs.then(|| logs_db.unwrap_or_else(|| data_dir.join("logs.db"))); | ||
Ok(Config { | ||
port, | ||
bind, | ||
public_origin, | ||
data_dir: var("HUD_DATA_DIR")?.map_or_else(|| cache_dir.clone(), PathBuf::from), | ||
data_dir, | ||
cache_dir, | ||
blob_cache_bytes, | ||
cache_memory_bytes, | ||
| @@ -669,14 +676,15 @@ async fn serve_metrics( | ||
Ok(()) | ||
} | ||
| ||
/// With `HUD_LOGS`, each line logged from now on kept in `logs.db` too, | ||
/// With `HUD_LOGS`, each line logged from now on kept in its file too, | ||
/// written a second at a time. | ||
fn keep_logs(hud: &Hud) { | ||
let Some(logs) = hud.logs.clone() else { return }; | ||
let (Some(logs), Some(path)) = (hud.logs.clone(), &hud.config.logs) else { | ||
return; | ||
}; | ||
let kept = logs.clone(); | ||
hud_core::telemetry::keep_lines(move |line| kept.keep(line)); | ||
tokio::spawn(hud_core::logs::flushing(logs, hud_core::logs::FLUSH)); | ||
let path = hud.config.data_dir.join("logs.db"); | ||
tracing::info!(path = %path.display(), "keeping the lines logged"); | ||
} | ||
| ||
crates/hud/tests/cli.rs+8−4
| @@ -1178,12 +1178,14 @@ fn schema_prints_the_published_schemas() { | ||
} | ||
} | ||
| ||
/// `hud index` serves the index; with `HUD_LOGS` its lines are kept in | ||
/// `logs.db` as `hud serve`'s are, each naming it, and with | ||
/// `HUD_INDEX_METRICS` its metrics answer on loopback, its own with them. | ||
/// `hud index` serves the index; with `HUD_LOGS` its lines are kept as | ||
/// `hud serve`'s are, in the file `HUD_LOGS_DB` names, in a directory of | ||
/// its own, each naming it; and with `HUD_INDEX_METRICS` its metrics answer | ||
/// on loopback, its own with them. | ||
#[test] | ||
fn serves_the_index_and_stops_on_sigterm() { | ||
let dir = temp_dir("index"); | ||
let kept_in = dir.join("logs/kept.db"); | ||
let port = free_port().to_string(); | ||
let metrics = free_port(); | ||
let at = format!("127.0.0.1:{metrics}"); | ||
| @@ -1214,6 +1216,7 @@ fn serves_the_index_and_stops_on_sigterm() { | ||
("HUD_DATA_DIR", dir.to_str().unwrap()), | ||
("HUD_RELAY", "http://127.0.0.1:9"), | ||
("HUD_LOGS", "on"), | ||
("HUD_LOGS_DB", kept_in.to_str().unwrap()), | ||
("RUST_LOG", "info"), | ||
], | ||
"serving the index at", | ||
| @@ -1243,10 +1246,11 @@ fn serves_the_index_and_stops_on_sigterm() { | ||
let (status, log) = server.stop("TERM"); | ||
assert!(status.success(), "{log:#?}"); | ||
assert!(dir.join("index.db").exists()); | ||
assert!(!dir.join("logs.db").exists()); | ||
let line: Value = serde_json::from_str(&log[0]).unwrap(); | ||
assert_eq!(line["service.name"], "hud-index"); | ||
// Kept, each naming the index, up to its stopping. | ||
let db = rusqlite::Connection::open(dir.join("logs.db")).unwrap(); | ||
let db = rusqlite::Connection::open(&kept_in).unwrap(); | ||
let kept = |message: &str| -> Vec<Value> { | ||
let mut stmt = db | ||
.prepare("SELECT line FROM line WHERE message = ?1") | ||
crates/hud-core/src/canvas/canonical.rs+1−1
| @@ -153,7 +153,7 @@ mod tests { | ||
sign_up_pds: crate::config::SIGN_UP_PDS.into(), | ||
client: Default::default(), | ||
operators: Vec::new(), | ||
logs: false, | ||
logs: None, | ||
logs_keep: crate::logs::KEEP, | ||
index: None, | ||
app_blocks: Vec::new(), | ||
crates/hud-core/src/canvas/space.rs+1−1
| @@ -1335,7 +1335,7 @@ mod tests { | ||
sign_up_pds: crate::config::SIGN_UP_PDS.into(), | ||
client: Default::default(), | ||
operators: Vec::new(), | ||
logs: false, | ||
logs: None, | ||
logs_keep: crate::logs::KEEP, | ||
index: None, | ||
app_blocks: Vec::new(), | ||
crates/hud-core/src/canvas/tools.rs+1−1
| @@ -502,7 +502,7 @@ mod tests { | ||
sign_up_pds: crate::config::SIGN_UP_PDS.into(), | ||
client: Default::default(), | ||
operators: Vec::new(), | ||
logs: false, | ||
logs: None, | ||
logs_keep: crate::logs::KEEP, | ||
index: None, | ||
app_blocks: Vec::new(), | ||
crates/hud-core/src/frames/instance/tests.rs+1−1
| @@ -60,7 +60,7 @@ fn hud_over(w: &World, spaces: bool) -> Arc<Hud> { | ||
sign_up_pds: crate::config::SIGN_UP_PDS.into(), | ||
client: Default::default(), | ||
operators: Vec::new(), | ||
logs: false, | ||
logs: None, | ||
logs_keep: crate::logs::KEEP, | ||
index: None, | ||
app_blocks: Vec::new(), | ||
crates/hud-core/src/oauth/tests.rs+1−1
| @@ -70,7 +70,7 @@ fn config(plc: &str) -> crate::Config { | ||
sign_up_pds: crate::config::SIGN_UP_PDS.into(), | ||
client: Default::default(), | ||
operators: Vec::new(), | ||
logs: false, | ||
logs: None, | ||
logs_keep: crate::logs::KEEP, | ||
index: None, | ||
app_blocks: Vec::new(), | ||
crates/hud-core/src/config.rs+4−3
| @@ -211,9 +211,10 @@ pub struct Config { | ||
/// The accounts that run this server, by DID (`HUD_OPERATOR_DIDS`): | ||
/// they alone read its kept lines (`logs`). | ||
pub operators: Vec<String>, | ||
/// Whether the server keeps each line it logs, to read back, in | ||
/// `<data_dir>/logs.db` (`HUD_LOGS`). | ||
pub logs: bool, | ||
/// The file the server keeps each line it logs in, to read back: by | ||
/// default `<data_dir>/logs.db` (`HUD_LOGS`, `HUD_LOGS_DB`). None, it | ||
/// keeps none. | ||
pub logs: Option<PathBuf>, | ||
/// How many lines at info and below it keeps (`HUD_LOGS_KEEP`, by | ||
/// default `logs::KEEP`). | ||
pub logs_keep: u64, | ||
crates/hud-core/src/identity.rs+2−2
| @@ -483,7 +483,7 @@ mod tests { | ||
sign_up_pds: crate::config::SIGN_UP_PDS.into(), | ||
client: Default::default(), | ||
operators: Vec::new(), | ||
logs: false, | ||
logs: None, | ||
logs_keep: crate::logs::KEEP, | ||
index: None, | ||
app_blocks: Vec::new(), | ||
| @@ -633,7 +633,7 @@ mod tests { | ||
sign_up_pds: crate::config::SIGN_UP_PDS.into(), | ||
client: Default::default(), | ||
operators: Vec::new(), | ||
logs: false, | ||
logs: None, | ||
logs_keep: crate::logs::KEEP, | ||
index: None, | ||
app_blocks: Vec::new(), | ||
crates/hud-core/src/join.rs+1−1
| @@ -1175,7 +1175,7 @@ mod tests { | ||
sign_up_pds: crate::config::SIGN_UP_PDS.into(), | ||
client: Default::default(), | ||
operators: Vec::new(), | ||
logs: false, | ||
logs: None, | ||
logs_keep: crate::logs::KEEP, | ||
index: None, | ||
app_blocks: Vec::new(), | ||