Docs / Start here

How it works

This page describes yasp's moving parts and how a check result turns into a status page, an incident and a notification. It's for operators who want to know what they're running, and for contributors who want to find their way around the code.

# The pieces

                 remote probes (yasp-probe)
                 long-poll assignments, POST results
                            |
                            v
  browsers ---->  +------------------------------------------+
  API clients     |  yasp serve (every instance)             |
  heartbeats      |  yasp-web: pages, dashboard, APIs,       |
  alert hooks     |  probe API, heartbeats, alert hooks      |
                  |                                          |
                  |  leader only:                            |
                  |   built-in probe   engine   notifier     |
                  |   timers, retention, ACME, static copy   |
                  +------------------------------------------+
                            |            |            |
                            v            v            v
                  +------------------------------------------+
                  |  database (SQLite, or Postgres for HA)   |
                  |  check_results -> state -> events ->     |
                  |  deliveries                              |
                  +------------------------------------------+
                                         |
                                         v
                       email, push, Slack, Teams, webhooks, pagers

Everything goes through the database. Instances don't talk to each other, and the probes only talk to whichever instance their requests reach.

# Crates

The workspace is crates/* plus xtask.

CrateJob
yaspThe server binary: CLI, config, wiring, and the background tasks (leader lease, engine, notifier, built-in probe, static copy, ACME, self-monitor heartbeat)
yasp-webEverything HTTP: public status pages, the dashboard under /admin, sign-in, the REST and Statuspage-compatible APIs, SCIM, the probe API, heartbeats and alert webhooks
yasp-engineThe state engine: damping, multi-probe agreement, component status, banner and uptime maths. Pure: no IO, no tokio, no clock reads; time is passed in
yasp-dbSeaORM entities, migrations and repositories, one code path for SQLite and Postgres
yasp-notifyTurns events into deliveries and sends them: email, Web Push, signed webhooks, chat and paging channels
yasp-checksThe check executors (HTTP, TCP, DNS, ping, TLS, databases, mail, processes, domains, other status pages) and the outbound network policy
yasp-probeThe probe: scheduler, center client, result queue and main loop. A library too, so the server embeds it as the built-in probe
yasp-protoThe probe protocol: paths, headers, request and response bodies, clock offset estimation
yasp-modelShared domain types: ids, statuses, check specs, schedules, thresholds. No IO
yasp-cryptoThe keyring, encryption at rest, password hashing, random tokens and constant-time comparison

xtask holds repository tooling; today that's dev-idp, a development-only OpenID Connect provider. See building.md.

# The life of a check

# Scheduling

A monitor runs on one or more probes. Every install has a built-in probe, This server, which is the yasp-probe scheduler running inside yasp serve. It runs only on the leader, so checks never run twice, and it uses the same assignment and ingest code as the probe API, without HTTP and without a clock offset.

The scheduler (crates/yasp-probe/src/scheduler.rs) runs each assigned monitor on its own timer:

  • The first run waits a stable per-monitor jitter, at most a minute, so many checks or many restarting probes don't all fire at once.
  • Runs are spaced from the previous run's start, so timing doesn't drift.
  • After a down result the next run comes after at most 20 seconds, which shortens the time to detect an outage.
  • A new assignment set is reconciled: new monitors start, removed ones stop, changed ones restart, and unchanged ones keep their timing.

One run is up to 1 + retries attempts (crates/yasp-checks/src/lib.rs). The first success ends it. The outcome is:

  • up, or degraded if the successful attempt was slower than the monitor's threshold;
  • down if every attempt failed;
  • inconclusive if the failure is on the probe's side: a local network error, or the canaries failing too (below).

# Target down or probe network down

Before a probe reports down, it tries its canaries: TCP targets the center sends with every assignment set. By default these are the center's own host and port, and 1.1.1.1:443. If the canaries fail too, the probe's own network is the problem, and the outcome becomes inconclusive instead of down. The engine ignores inconclusive results: they neither count toward a state change nor reset one.

# The probe protocol

Remote probes speak protocol version 1 over HTTPS and JSON, defined in crates/yasp-proto and served by crates/yasp-web/src/probe_api.rs under /probe/v1. The probe only makes outbound requests.

  • Enrollment. POST /probe/v1/enroll trades a one-time yasp_enr_… token (valid 24 hours) for a long-lived credential yasp_prb_<probe-id>_<secret>. The probe stores it in credential.json in its data directory (mode 0600). The center keeps only SHA-256 hashes of tokens and credentials, and compares them in constant time.
  • Assignments. GET /probe/v1/assignments?rev=N returns the probe's whole work set: every monitor to run, the network policy, the canaries, and any one-off tests from Test now. It's always the full set, not a diff, so applying it twice is harmless. If rev matches the current revision, the center holds the request for up to 25 seconds and answers 304 if nothing changed. Changing a monitor or the probe's assignments bumps the revision, so probes pick up edits within about a second.
  • Results. POST /probe/v1/results takes batches of up to 500 results. Each has a per-probe sequence number that keeps increasing across restarts; the center skips duplicates and answers with the highest stored sequence, and the probe drops everything up to it. The probe uploads every 5 seconds, or at once when a monitor's outcome changes. While the center is unreachable it keeps checking and queues results in memory, with a cap. If it has to drop the oldest, it reports the gap.
  • Capabilities. The probe sends what it can run (http, tcp, icmp, process, …) at enrollment and in a header on every request. The center only assigns checks a probe can run, so a probe without a ping socket never gets ping checks.
  • Clock. Every response carries yasp-server-time. The probe estimates its clock offset and sends it back; the center corrects result timestamps with it. A result that arrives more than 2 × interval + 60 s after it started is stored as late: it shows in history but never drives state, so a probe replaying its queue after an outage can't raise old alerts.
  • Versions. A probe whose protocol version the center doesn't support gets HTTP 426 with the supported range. It keeps queueing and retries every 5 minutes, so upgrading either side fixes it. A revoked probe gets 401 and exits.

Heartbeats (/hb/{token}) and alert webhooks (/hooks/alerts/{token}) don't use probes. Each ping or alert change becomes a row in the same check_results table, and the engine treats it like any other result. A missed heartbeat period is recorded by the engine.

# From results to monitor state

The engine (crates/yasp-engine, driven by crates/yasp/src/engine_task.rs) runs on the leader once a second. It reads new rows from check_results past a stored cursor, so it doesn't matter which instance stored a result, and nothing is lost across a restart or failover. Each step commits probe tracks, monitor transitions, component statuses, uptime intervals, outbox events and the cursor in one transaction.

# Flap damping

Each (monitor, probe) pair has its own damped state (damping.rs), driven by streaks of consecutive outcomes:

FromToCondition
anydowndown_after consecutive down (default 2)
downup or degradedup_after consecutive non-down (default 2)
updegradeddegraded_after consecutive degraded (default 3)
degradedupup_after consecutive up
unknownup or degradedthe first such outcome

Heartbeat monitors default to 1 for all three: one missed period is already a strong signal.

# Multi-probe agreement

The monitor's state combines its probes' views (monitor.rs). A probe counts as reporting when it's online (seen in the last 90 seconds), its last result is fresh (newer than 2 × interval + timeout + 30 s), and its state isn't unknown. The quorum rule says how many reporting probes must agree:

QuorumRequired
Majority (default)more than half of the reporting probes
Anyone
Allevery reporting probe
At least kk; with fewer than k reporting, the monitor keeps its previous state, marked stale

If enough probes say down, the monitor is down; if enough say degraded or down, it's degraded; otherwise it's up. With no reporting probes, or when it's disabled or paused, it's unknown.

After the engine starts, monitors without new data aren't evaluated for two minutes, which gives probes time to report.

# Alert events

A monitor transition writes an operator event to the outbox: monitor.down, monitor.recovered, or monitor.degraded (sent only if the monitor has degraded alerts on). Transitions to or from unknown raise nothing, so a restart or a new monitor doesn't page anyone.

# From monitor state to component status

A component's public status is decided in this order, first match wins (component.rs):

  1. an active manual override;
  2. the worst status set by unresolved, published incidents;
  3. an in-progress maintenance window: under maintenance;
  4. its monitors.

For step 4, each linked monitor maps to a status: up is operational, degraded is degraded performance, and down is whatever the link's down as says: major outage (the default) or partial outage. The component then combines them: worst, best, or redundant (all down is a major outage, some down a partial outage). Unknown monitors are left out; if every monitor is unknown, the component keeps its last status. A component with no monitors is operational.

Step 4 is always computed, so the dashboard can show what the monitors say next to a manual or incident status.

# Automatic incidents

When a component's monitors start reporting a partial or major outage, and the component isn't under maintenance or set by hand, the engine can open an incident, as a draft or published, depending on the component's setting:

  • Outages that start within 10 minutes of an open automatic incident join it.
  • A component failing again within 30 minutes of an automatic resolve reopens that incident.
  • Once every affected component has been operational for 2 minutes, the incident resolves itself. An untouched draft is deleted instead.
  • An incident someone has edited is left alone.

Every automatic action is written to the audit log.

# Notifications

Notifications go through two tables (crates/yasp-notify):

  1. Events (the outbox). Monitor transitions, incident and maintenance updates, and subscription confirmations append events. The engine writes its events in the same transaction as the state change.
  2. Deliveries. On the leader, fan-out turns each new event into one delivery per target, so it can be re-run after a crash without duplicates. Then workers claim due deliveries, send them, and record the result.

Who gets what:

  • Alert channels (email, webhook, Slack, Teams, Discord, Telegram, ntfy, PagerDuty, Opsgenie, on-call rotation) get monitor events for the monitors they're attached to. Alerts are muted while a component the monitor feeds is in a maintenance window. monitor.escalated goes to the escalation step's channels when nobody acknowledged in time.
  • Subscribers get incident and maintenance updates for the pages that show them, either the whole page or the components they picked. Components limited to an audience never reach subscribers. Raw monitor changes don't reach subscribers.

Hold before send. Subscriber deliveries are scheduled the page's hold time (30 seconds by default, at most 120) after the event. Until then, an editor can cancel them from the incident's page; the update itself stays posted.

Retries. A transient failure is retried after 30 s × 2^(attempt − 1), ±20 % jitter, honouring Retry-After up to an hour. After 8 attempts or 24 hours the delivery is marked dead. A permanent failure (most 4xx answers, an SMTP 5xx, an address the network policy refuses) is marked failed and not retried. A claim lasts 60 seconds; if a worker dies mid-send, another takes it over. Delivery is at-least-once, so a crash mid-send can repeat a message.

Webhooks are signed: Yasp-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256> over <t>.<body>.

# Rendering the status page

Status pages are rendered on the server with askama templates (crates/yasp-web/templates/public) and are complete without JavaScript. The uptime bars link to a page per day, so they work on touch screens and without scripts. The dashboard's forms work without JavaScript too: they POST and redirect.

Pages read what the engine stored; they don't evaluate monitors. Monitor names, targets and error messages never appear on public pages.

Public pages answer with a strong ETag (a hash of the HTML) and Cache-Control: public, max-age=15, stale-while-revalidate=60, and with 304 when the browser already has the current version. Times on the page are rendered to the minute, so an unchanged page is byte-identical within a minute and the ETag holds. Private pages are sent as private, no-store without an ETag. Static assets are versioned and cached for a year.

Visible text on public pages comes from the translation catalogs in crates/yasp-web/locales, with English as the fallback.

# Static copy

A page can have a copy in S3-compatible storage that stays readable while yasp is down (crates/yasp/src/static_copy.rs). The leader renders the copy by requesting yasp's own public routes, so it's exactly what visitors see: the page, history, incident pages, feeds, the Statuspage JSON API, badges, and their assets. It republishes a page at most once a minute unless a publish is requested, and uploads only files whose content changed since the last upload. Links that need a live server, such as subscribing or signing in, point back to yasp.

# Storage

yasp uses SeaORM with one code path for SQLite and Postgres, chosen from the database URL. To stay portable, timestamps are unix milliseconds, primary keys are UUIDv7 (high-volume append tables use autoincrement integers), and enums are stored as text and validated in Rust. Backend-specific SQL is limited to small, tested match backend blocks.

SQLite runs in WAL mode with a 5-second busy timeout. It's for a single instance; use Postgres to run more than one.

Migrations run at startup, all pending ones in one transaction under a lock (an advisory lock on Postgres, BEGIN IMMEDIATE on SQLite), so two instances starting together apply them once, and a failed upgrade changes nothing. yasp refuses to start against a database with migrations it doesn't know (a newer version's schema). Migrations are forward-only: there are no down-migrations, and a released migration is never edited.

# Encryption at rest

Secrets in the database (SMTP passwords, webhook and channel secrets, sensitive check headers, private keys) are encrypted with the keyring from encryption.keys (crates/yasp-crypto):

  • Each key is 32 bytes. The first is the primary and encrypts new data; older keys stay listed to decrypt what they encrypted.
  • Every use gets its own subkey, derived with HKDF-SHA256 from a purpose (secrets, tokens, sessions, key check), so a key used for MACs is never also an encryption key.
  • Encryption is XChaCha20-Poly1305 with random nonces. The associated data binds the purpose, the key id and the row the secret belongs to, so a ciphertext copied to another row doesn't decrypt.
  • An encrypted known value is stored in the database. At startup yasp checks it and refuses to run with a wrong or missing key, instead of failing later on every secret.

Backups don't include the key. Keep it separately.

# Leader and standbys

Every instance serves HTTP. One instance at a time holds the leader lease, a row in the database, and only the leader runs the background work: the engine, notifications, the built-in probe, timers, retention, ACME and the static copy. The lease lasts 30 seconds and is renewed every 10. See high-availability.md for failover, upgrades and backups.

# Security model

  • Dashboard sessions. Sign-in is OpenID Connect (Authorization Code with PKCE), SAML 2.0 (a build feature) or one-time email links. The session cookie holds 32 random bytes; the database stores only their hash. Cookies are HttpOnly, SameSite=Lax, and over HTTPS Secure with the __Host- prefix. Sessions end after 12 hours idle or 7 days.
  • CSRF. Every unsafe request under /admin needs same-origin evidence (Sec-Fetch-Site: same-origin, or a matching Origin) and the session's CSRF token, in the x-csrf-token header or a _csrf form field.
  • Content Security Policy. Responses default to script-src 'self' with frame-ancestors 'none', base-uri 'none' and form-action 'self', plus nosniff, a strict referrer policy and Cross-Origin-Opener-Policy: same-origin. There are no inline scripts.
  • Probe network policy. By default checks can't reach loopback, private, link-local (cloud metadata), CGNAT, unique-local, multicast, documentation or unspecified addresses. The policy filters every resolved address, IP literal and redirect hop at connect time, so neither DNS rebinding nor a redirect gets around it. Admins allow networks or hosts per probe; see probes.md. The server applies the same policy to outgoing webhooks and static-copy uploads, with its own allowlist (server.outbound_allow).
  • Probe credentials. Stored as hashes, compared in constant time, revocable at once. Sensitive check values reach probes over TLS, and probes keep them in memory only.
  • Secrets never appear in clear text in logs, API responses or config exports.