Watch
0
0
Fork
You've already forked hyperhive
0

remove the agent's stats page and its endpoint

This commit is contained in:
iris 2026-11-16 19:00:52 +01:00
commit 6ed714a0a7
3 changed files with 49 additions and 1744 deletions

View file

@ -1,8 +1,6 @@
//! Per-container HTTP server: the stats and screen pages (`GET /stats`,
//! `GET /screen`, `GET /static/*`), `GET /` redirecting to `/stats`, the small
//! JSON the dashboard card and those pages read (`/api/state`,
//! `/api/dashboard-state`, `/api/stats`) and the live event stream
//! `/events/stream`.
//! Per-container HTTP server: the screen page (`GET /screen`, `GET /static/*`),
//! the small JSON the dashboard card and that page read (`/api/state`,
//! `/api/dashboard-state`) and the live event stream `/events/stream`.
//!
//! Handlers are split by concern into the submodules below; this file owns the
//! shared [`AppState`], the listener + router wiring in [`serve`], and the
@ -13,7 +11,6 @@ pub(crate) use auth::force_logout;
mod proxy;
mod screen;
mod state;
mod stats;
mod stream;
use std::net::SocketAddr;
@ -23,7 +20,7 @@ use std::sync::{Arc, Mutex};
use std::time::Duration;
use anyhow::{Context, Result};
use axum::{Router, response::Redirect, routing::get};
use axum::{Router, routing::get};
use backon::{ExponentialBuilder, Retryable};
use tower_http::services::ServeDir;
@ -47,11 +44,9 @@ struct AppState {
/// The API routes, without the extra proxies and the static fallback.
fn routes() -> Router<AppState> {
Router::new()
.route("/", get(|| async { Redirect::temporary("stats") }))
.route("/api/state", get(state::api_state))
.route("/api/dashboard-state", get(state::api_dashboard_state))
.route("/events/stream", get(stream::events_stream))
.route("/api/stats", get(stats::api_stats))
.route("/screen/ws", get(screen::screen_ws))
.route("/icon", get(screen::serve_icon))
}
@ -92,11 +87,9 @@ pub async fn serve(label: String, port: u16, bus: Bus) -> Result<()> {
// Mount any `services.hyperhive.agent.extraWebProxies` under `/extra/<name>/` before the
// static fallback so declared proxies win over `ServeDir`.
let app = proxy::mount_extra_proxies(app)
// Anything else (`/`, `/stats`, `/screen`, `/static/*`)
// falls through to the merged dist. ServeDir auto-appends
// `.html` when the URL is a bare path that matches a file
// (so `/stats` → `dist/stats.html`, `/screen` → `dist/
// screen.html`). Per-agent `extraFiles` additions are
// Anything else (`/screen`, `/static/*`) falls through to the merged
// dist. ServeDir auto-appends `.html` when the URL is a bare path that
// matches a file (so `/screen` → `dist/screen.html`). Per-agent `extraFiles` additions are
// already layered into this same directory (see
// services.hyperhive.agent.frontend.mergedDist in nix).
.fallback_service(ServeDir::new(&static_dir))

View file

@ -1,4 +1,4 @@
//! `/api/state` (the agent's name, for the stats and screen pages) and
//! `/api/state` (the agent's name, for the screen page) and
//! `/api/dashboard-state` (what the hive dashboard's card reads).
use axum::extract::State;
@ -6,7 +6,7 @@ use serde::Serialize;
use super::AppState;
/// What the stats and screen pages read of the agent: its name, for the title
/// What the screen page reads of the agent: its name, for the title
/// and the screen's login, and the port of the hive dashboard for the way back.
#[derive(Serialize)]
pub(super) struct Identity {
@ -67,8 +67,8 @@ struct AgentLink {
#[derive(Serialize, Clone, Copy)]
#[serde(rename_all = "snake_case")]
enum AgentLinkKind {
/// `url` is a path on the agent's container web UI (`/stats`,
/// `/screen`). Agent page: same-origin path. Dashboard:
/// `url` is a path on the agent's container web UI
/// (`/screen`). Agent page: same-origin path. Dashboard:
/// `http://<host>:<container.port><url>`.
Container,
/// `url` is already a fully-qualified absolute URL — use as-is.
@ -137,13 +137,6 @@ fn read_own_status() -> (Option<String>, Option<i64>) {
fn agent_links(gui_enabled: bool) -> Vec<AgentLink> {
let mut links = Vec::new();
links.push(AgentLink {
url: "stats.html".to_owned(),
icon: "📊".to_owned(),
label: "stats".to_owned(),
kind: AgentLinkKind::Container,
});
if gui_enabled {
links.push(AgentLink {
url: "screen.html".to_owned(),
@ -195,7 +188,7 @@ mod tests {
keys
}
/// `GET /api/state` carries exactly what the stats and screen pages read.
/// `GET /api/state` carries exactly what the screen page reads.
#[test]
fn the_identity_serialises_exactly_its_read_fields() {
let identity = super::Identity {

View file

@ -1,40 +0,0 @@
//! The stats read endpoint.
use axum::extract::State;
use serde::Deserialize;
use super::AppState;
#[derive(Deserialize)]
pub(super) struct StatsQuery {
window: Option<String>,
}
pub(super) async fn api_stats(
State(_state): State<AppState>,
axum::extract::Query(q): axum::extract::Query<StatsQuery>,
) -> axum::Json<crate::stats::Snapshot> {
let window = crate::stats::Window::parse(q.window.as_deref().unwrap_or("24h"));
let mut snapshot = crate::stats::snapshot_default(window);
// Pass the window span so the local reminder rollup filters its counts
// to the same time range as the chart data.
let window_secs = window.span_secs();
let window_secs_u = u64::try_from(window_secs).unwrap_or(0);
snapshot.reminder_stats = fetch_reminder_stats(window_secs_u).await;
axum::Json(snapshot)
}
/// Fetch reminder activity stats from the harness-local reminder store over
/// `HIVE_AGENT_SOCKET` — was a broker RPC before reminders moved
/// in-container. Returns `None` on any transport / decode failure or
/// when the socket is unset — the stats are decorative, not authoritative.
async fn fetch_reminder_stats(window_secs: u64) -> Option<hive_sh4re::inbox::ReminderStats> {
match crate::todo_server::dial(&hive_agent_sock::Request::ReminderRollup {
since_secs: window_secs,
})
.await?
{
hive_agent_sock::Response::ReminderRollup { stats } => Some(stats),
_ => None,
}
}