Skip to main content

Crate id_effect_console

Crate id_effect_console 

Source
Expand description

The operator console for id_effect services: live fibers, supervision trees, metrics, health and the log level, behind an id_effect_authz guard.

§The API

Console collects what the console shows and Console::router turns it into an Axum router answering JSON under API_PREFIX (/_console/api) and the dashboard page at /_console:

RouteAnswers
GET fibersevery live fiber (FiberView, from core fiber_dump, feature fiber-registry)
GET supervisorsthe registered supervision trees (SupervisorsView, from which_children)
GET metricsthe metric registry and the runtime fiber gauges (MetricView)
GET healththe HealthRegistry report (always 200)
GET log-levelthe reloadable EnvFilter and the EffectLogger minimum (LogLevelView)
PUT log-levelchanges both without a restart (LogLevelChange)
GET jobsper-queue counts and the newest jobs of a job queue (JobsView, feature jobs)
POST jobs/{id}/retrya dead or cancelled job runs again now (JobView; 404 unknown id, 409 other state)
POST jobs/{id}/cancela scheduled or failed job is cancelled (JobView; 404 unknown id, 409 other state)

The two POST routes require Content-Type: application/json (415 otherwise), so a cross-site form cannot trigger them.

§The dashboard

The same router serves GET /_console: one static page (inline CSS and vanilla JavaScript, compiled in with include_str!, no build step and nothing loaded from another origin) that polls the API and shows the health checks, the log level with a form that changes it, the supervision trees, the job queues (when the jobs feature and a queue are configured, with a retry button on dead and cancelled jobs and a cancel button on scheduled and failed ones), the live fibers and the metrics. It is behind the same guard as the API.

§Security model

There is no unguarded constructor: the only way to get the routes is Console::router, which takes an authorization Guard and puts it in front of every console route and the console router’s fallback, so a principal the guard denies learns nothing about the API (401 anonymous, 403 otherwise, Problem Details body). The authentication layer that sets the principal runs outside the guard (Router::layer on the merged app), as for any id_effect_authz route. Console answers carry Cache-Control: no-store.

ConsoleConfig is where the console listens. Bound to a loopback address it serves the local machine only; on any other address ConsoleConfig::requires_guard is true: the guard must then restrict the console to operators (a role or permission policy), while a loopback console may use a lenient one such as authenticated(). The guard is required either way. On the console’s own listener, ConsoleConfig::check_host_and_origin also answers 403 to a request for another host or from another origin (DNS rebinding, cross-site posts; see Host and Origin), by default allowing the bind address only.

use std::net::{Ipv6Addr, SocketAddr};

use id_effect_authz::{Guard, require_role};
use id_effect_console::{Console, ConsoleConfig};

let config = ConsoleConfig::new(SocketAddr::from((Ipv6Addr::LOCALHOST, 9090)));
assert!(!config.requires_guard());

let console: axum::Router = Console::new().router(Guard::new("console", require_role("operator")));

Tier platform (ADR 0010 Amendment 6): the Ledger reference app under examples/reference/ depends on it.

Structs§

Console
What the console shows, built up then turned into its guarded routes by Console::router.
ConsoleConfig
Where the console listens, and the host names it answers to.
FiberView
One live fiber, as GET /_console/api/fibers lists it (by ascending id).
JobView
One job, without its payload (which may carry personal data).
JobsView
What GET /_console/api/jobs answers.
LogLevelChange
The body of PUT /_console/api/log-level: at least one field.
LogLevelView
The log level in force, as GET /_console/api/log-level answers it.
MetricView
One metric series, as GET /_console/api/metrics lists it: the registry’s series sorted by name, kind and tags, then the runtime’s id_effect_fibers_live and id_effect_fibers_started_total.
QueueView
One queue’s counts.
SupervisorsView
What GET /_console/api/supervisors answers.
UnreachableSupervisor
A registered supervisor that did not answer.

Constants§

API_PREFIX
Where the console API is mounted: every route is /_console/api/<name>.

Type Aliases§

EnvFilterHandle
The reload handle of an EnvFilter layered directly on a Registry: what id_effect_opentelemetry’s OtelStarterGuard::env_filter returns, or what tracing_subscriber::reload::Layer::new(filter) gives an app that builds its own subscriber.