Docs / Contributing

Building and developing

How to build yasp from source, run the same checks CI runs, and find where to make common changes. For how the parts fit together, read how-it-works.md first. Before you open a pull request, read CONTRIBUTING.md.

# Toolchain

rust-toolchain.toml pins the Rust release (currently 1.98.0) with rustfmt and clippy. With rustup installed, the first cargo command in the checkout installs it. CI reads the same file, so build with it to get the same warnings CI gets.

The Terraform provider in integrations/ is Go; its version comes from its go.mod.

# Building

cargo build --release -p yasp          # the server: target/release/yasp
cargo build --release -p yasp-probe    # the remote probe: target/release/yasp-probe

The release profile uses thin LTO, one codegen unit and stripped symbols, so it takes a while. The release binaries of yasp-probe use the release-probe profile instead, which also optimizes for size and aborts on panic:

cargo build --profile release-probe -p yasp-probe   # target/release-probe/yasp-probe

Templates (askama), stylesheets, scripts, fonts and translations are compiled into the binary. There's nothing else to install next to it.

# SAML

SAML sign-in is an opt-in feature, because it links the C libraries libxmlsec1 and OpenSSL. On Debian or Ubuntu, install what CI and the Dockerfile install, then build with the feature:

sudo apt-get install -y libxmlsec1-dev libxml2-dev libclang-dev pkg-config
cargo build --release -p yasp --features saml

The machine that runs it needs libxmlsec1, libxmlsec1-openssl and libxml2. A SAML build is dynamically linked, so there is no static SAML binary. See saml.md.

# Static musl binaries

The release binaries are static musl builds made from deploy/docker/Dockerfile. Each architecture is built on its own native runner (x86_64 and aarch64), so nothing is cross-compiled. To make the same binaries locally:

docker build -f deploy/docker/Dockerfile --target binaries -o dist .

This writes dist/yasp and dist/yasp-probe for the architecture Docker builds for. To do it without Docker on Linux, install musl-tools and mirror the Dockerfile:

T="$(uname -m)-unknown-linux-musl"
rustup target add "$T"
cargo build --locked --release --target "$T" -p yasp
cargo build --locked --profile release-probe --target "$T" -p yasp-probe

# Docker images

deploy/docker/Dockerfile has these targets:

TargetWhat it builds
yaspThe static server on distroless/static-debian12:nonroot, listening on 0.0.0.0:8080, SQLite in /data
yasp-probeThe static probe on the same base, data in /data
yasp-samlThe server with SAML, dynamically linked, on debian:bookworm-slim
binariesJust the two static binaries, for -o
docker build -f deploy/docker/Dockerfile --target yasp       -t yasp .
docker build -f deploy/docker/Dockerfile --target yasp-probe -t yasp-probe .
docker build -f deploy/docker/Dockerfile --target yasp-saml  -t yasp:saml .

# Releases

.github/workflows/release.yml runs on a v* tag. It checks that the tag matches the version in Cargo.toml, builds the binaries, yasp, yasp-probe and yasp-saml targets for linux/amd64 and linux/arm64, merges them into multi-arch images on GHCR, signs them with cosign, and attaches the binaries, CycloneDX SBOMs, a signed SHA256SUMS and build provenance to a GitHub release. A tag with a - (like v1.2.3-rc.1) is a pre-release and doesn't move latest. See verifying-releases.md.

# Running it locally

cargo run -p yasp -- keys generate     # an encryption key for yasp.toml
cargo run -p yasp -- serve             # reads ./yasp.toml if present
cargo run -p yasp -- demo-seed         # sample monitors, components and history

To sign in to the dashboard without a real identity provider, run the development OIDC provider in another terminal:

cargo xtask dev-idp 8090

It signs in whoever fills in its form, with no password, and binds to 127.0.0.1. The [oidc] settings to use with it are at the top of xtask/src/dev_idp.rs. It's the only xtask command; cargo xtask help lists it.

# Tests

# SQLite

cargo test

Each database test gets a fresh SQLite file in the temp directory.

# Postgres

The tests in crates/yasp-db read YASP_TEST_DB. Unset (or sqlite), they use SQLite. Set to a Postgres URL, each test creates its own schema in that database:

docker run -d --name yasp-pg -e POSTGRES_USER=yasp -e POSTGRES_PASSWORD=yasp \
  -p 127.0.0.1:55432:5432 postgres:17-alpine
YASP_TEST_DB=postgres://yasp:yasp@127.0.0.1:55432/yasp cargo test

The other crates' tests (yasp-web, yasp) use SQLite either way. Persistence changes belong in yasp-db, where both backends are tested. CI runs the whole suite against SQLite, Postgres 15 and Postgres 17.

# Schema snapshots

crates/yasp-db/tests/schema.rs applies every migration to an empty database and compares the result with crates/yasp-db/tests/snapshots/schema.sqlite.txt and schema.postgres.txt. After an intended schema change (a new migration), refresh both, once per backend:

YASP_UPDATE_SNAPSHOTS=1 cargo test -p yasp-db --test schema
YASP_UPDATE_SNAPSHOTS=1 YASP_TEST_DB=postgres://… cargo test -p yasp-db --test schema

A diff in a snapshot for an already released migration means that migration changed. Don't do that: add a new one.

# Other test suites

  • crates/yasp-engine/tests/scenarios/*.scn: engine scenarios in a small text format, documented at the top of the file. Add a scenario when you change damping or quorum. tests/properties.rs has property tests.
  • crates/yasp-checks/tests: checks against local servers, with certificate fixtures.
  • crates/yasp/tests/probe_e2e.rs: a real server, probe agent and HTTP target, in-process.
  • SAML: cargo test -p yasp-web --features saml --test saml --test auth (needs the SAML libraries).

# What CI runs

.github/workflows/ci.yml, on every push to main and every pull request, with RUSTFLAGS=-D warnings:

JobCommands
fmtcargo fmt --all --check
clippycargo clippy --workspace --all-targets --locked -- -D warnings
samlinstalls libxmlsec1-dev libxml2-dev libclang-dev pkg-config, then cargo clippy -p yasp-web -p yasp --features yasp/saml,yasp-web/saml --all-targets --locked -- -D warnings and cargo test -p yasp-web --features saml --test saml --test auth --locked
test (sqlite, postgres-15, postgres-17)cargo nextest run --workspace --locked --profile ci, then cargo test --workspace --locked --doc
denycargo deny --locked check with cargo-deny 0.22.2
probe-depsfails if cargo tree -p yasp-probe -e normal contains yasp-db, yasp-web, yasp-notify, sea-orm, sqlx, askama or lettre
terraform-providergofmt -l . must print nothing, go vet ./..., go test ./...

The nextest ci profile is in .config/nextest.toml. Plain cargo test runs the same tests. deny.toml holds the licence allowlist and the advisory exceptions, each with a reason.

# Terraform provider

integrations/terraform-provider-yasp is a Go module built on the Terraform plugin framework. It manages monitors and components through the REST API.

cd integrations/terraform-provider-yasp
go build -o terraform-provider-yasp .
go test ./...
# against a running server (creates and deletes a monitor and a component):
YASP_URL=http://localhost:8080 YASP_TOKEN=yasp_api_… go test -run Live ./internal/provider/

Its README explains how to try a local build with dev_overrides.

# Project layout

PathWhat
crates/yaspServer binary: CLI (main.rs), config, serve, and the leader's background tasks
crates/yasp-webHTTP: public.rs (status pages), admin/ (dashboard), api/ (REST, OpenAPI, Statuspage API), auth/, probe_api.rs, templates/, locales/, assets/
crates/yasp-enginePure state engine, with scenario and property tests
crates/yasp-dbentity.rs, migrations/, repo/ (one module per table group), schema snapshots
crates/yasp-notifyFan-out, delivery worker, retries, and the email, webhook, push and chat transports
crates/yasp-checksOne module per check type, plus policy.rs
crates/yasp-probeProbe binary and library
crates/yasp-proto, yasp-model, yasp-cryptoWire protocol, domain types, encryption
xtaskdev-idp
integrations/terraform-provider-yaspTerraform/OpenTofu provider (Go)
deploy/Dockerfile, Compose, systemd units, the demo deploy script
docs/Operator guides, screenshots and design spikes

# Where to start

# A monitor type

  1. crates/yasp-model/src/check.rs: add a variant to CheckSpec with its settings struct, and crates/yasp-model/src/monitor.rs: a MonitorKind.
  2. crates/yasp-checks/src/: a module with an attempt function, wired into attempt_once in lib.rs. Connect through the Policy you're given, so the network policy applies.
  3. crates/yasp-proto/src/messages.rs: a Capability for it, and its mapping in Capability::for_kind. Add it to CAPABILITIES in yasp-checks (or to capabilities() if it depends on the host). Older probes don't advertise it, so they're never assigned the new check.
  4. The dashboard form: crates/yasp-web/src/admin/monitors.rs and templates/admin/monitor_fields.html. Check the REST API (api/v1.rs) and its OpenAPI description too.
  5. Tests in crates/yasp-checks/tests/checks.rs, and a row in the table in probes.md.

The compiler points to most of the match arms you need to extend.

# A notification channel

  1. crates/yasp-db/src/repo/channels.rs: a variant of ChannelConfig. Anything secret (a token or key) goes in the channel's encrypted secret, not in the config.
  2. crates/yasp-notify/src/worker.rs: send it in the channel match. Chat and paging formats live in chat.rs. Return a transient failure for errors worth retrying and a permanent one otherwise; the retry schedule is in retry.rs.
  3. The dashboard: crates/yasp-web/src/admin/notifications.rs and templates/admin/channel_form.html.

# A string on a public page

Public pages and the subscription pages are translated. The English text is the key: use "…"|t (or |tf, |tn) in templates/public, or i18n::t("…") in code. Then add the same key with a translation to every file in crates/yasp-web/locales/ (de.txt, es.txt, fr.txt, ja.txt, pt-BR.txt). The format is described at the top of crates/yasp-web/src/i18n.rs. The test every_language_translates_every_key fails when a catalog misses a key or a placeholder.

# A database change

Add a new migration in crates/yasp-db/src/migrations/, register it in mod.rs there, refresh the schema snapshots on both backends, and run the suite with and without YASP_TEST_DB. Never edit a released migration.

# Before you push

cargo fmt --all
cargo clippy --workspace --all-targets -- -D warnings
cargo test
YASP_TEST_DB=postgres://… cargo test

Add a line to CHANGELOG.md under Unreleased, and sign off your commits (git commit -s).