The only tool you need to know what is happening and how to fix it.
Go alertingexception-trackerissue-trackinglogsmetricsmonitoringobservability-platformopen-telemetryotelsession-replaytelemetrytraces
feat: monitoring (#286)
narrow-adventure7b00c4418d23
diff --git a/.github/workflows/release-traceway.yml b/.github/workflows/release-traceway.ymlindex 362a958f..b4d0c39c 100644--- a/.github/workflows/release-traceway.yml+++ b/.github/workflows/release-traceway.yml@@ -161,6 +161,29 @@ jobs:--title "Backend v${{ inputs.version }}" \--notes "$NOTES"+ - name: Set up Go for runner binaries+ uses: actions/setup-go@v5+ with:+ go-version-file: backend/go.mod++ # traceway-runner executes browser synthetic checks on user+ # infrastructure (SYNTHETICS_BROWSER_MODE=remote); distributed as plain+ # binaries, no docker image. CGO-free on the default (untagged) build.+ - name: Build and upload traceway-runner binaries+ env:+ GH_TOKEN: ${{ github.token }}+ CGO_ENABLED: 0+ run: |+ cd backend+ mkdir -p dist+ for target in "linux amd64" "linux arm64" "darwin amd64" "darwin arm64" "windows amd64"; do+ set -- $target+ ext=""+ if [ "$1" = "windows" ]; then ext=".exe"; fi+ GOOS=$1 GOARCH=$2 go build -ldflags="-s -w" -o "dist/traceway-runner_$1_$2${ext}" ./cmd/traceway-runner+ done+ gh release upload "backend/v${{ inputs.version }}" dist/traceway-runner_*+- name: Trigger website + docs deploysenv:GH_TOKEN: ${{ github.token }}@@ -245,6 +268,23 @@ jobs:cache-from: type=ghacache-to: type=gha,mode=max+ # amd64 only like the DuckDB image it extends (same CGO constraint), plus+ # Node + @playwright/test + headless Chromium for embedded browser+ # synthetic checks.+ - name: Build and push Browser image+ id: docker_build_browser+ uses: docker/build-push-action@v5+ with:+ context: .+ file: ./Dockerfile.browser+ platforms: linux/amd64+ push: true+ tags: |+ ghcr.io/${{ github.repository_owner }}/traceway:v${{ inputs.version }}-browser+ ghcr.io/${{ github.repository_owner }}/traceway:browser+ cache-from: type=gha+ cache-to: type=gha,mode=max+- name: Install Cosignuses: sigstore/cosign-installer@v3with:@@ -274,6 +314,12 @@ jobs:run: |cosign sign --yes ghcr.io/${{ github.repository_owner }}/traceway@${{ steps.docker_build_duckdb.outputs.digest }}+ - name: Sign Browser image+ env:+ COSIGN_EXPERIMENTAL: 1+ run: |+ cosign sign --yes ghcr.io/${{ github.repository_owner }}/traceway@${{ steps.docker_build_browser.outputs.digest }}+- name: Summaryrun: |echo "### Docker Images (signed with Cosign)" >> "$GITHUB_STEP_SUMMARY"@@ -290,6 +336,9 @@ jobs:echo "**DuckDB Image** (embedded SQLite main DB + DuckDB columnar telemetry, no dependencies):" >> "$GITHUB_STEP_SUMMARY"echo "\`ghcr.io/${{ github.repository_owner }}/traceway:v${{ inputs.version }}-duckdb\`" >> "$GITHUB_STEP_SUMMARY"echo "" >> "$GITHUB_STEP_SUMMARY"- echo "All images tagged with version, plus \`latest\`, \`minimal\`, \`sqlite\`, and \`duckdb\` respectively." >> "$GITHUB_STEP_SUMMARY"+ echo "**Browser Image** (DuckDB image + Playwright/Chromium for embedded browser synthetic checks):" >> "$GITHUB_STEP_SUMMARY"+ echo "\`ghcr.io/${{ github.repository_owner }}/traceway:v${{ inputs.version }}-browser\`" >> "$GITHUB_STEP_SUMMARY"+ echo "" >> "$GITHUB_STEP_SUMMARY"+ echo "All images tagged with version, plus \`latest\`, \`minimal\`, \`sqlite\`, \`duckdb\`, and \`browser\` respectively." >> "$GITHUB_STEP_SUMMARY"echo "" >> "$GITHUB_STEP_SUMMARY"echo "See [DOCKER_SIGNATURES.md](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/DOCKER_SIGNATURES.md) to verify image signatures." >> "$GITHUB_STEP_SUMMARY"diff --git a/CLAUDE.md b/CLAUDE.mdindex 694d219d..cd289b28 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -100,7 +100,7 @@ api.POST("/login", middleware.Transactional, authController.Login)// In controller - retrieve transaction from Gin contextfunc (c *AuthController) Register(ctx *gin.Context) {- tx := middleware.GetTx(ctx) // Get transaction from context+ tx := db.GetTx(ctx) // Get transaction from context (db package, not middleware)// Use tx for all repository callsuser, err := transactional.UserRepository.FindByEmail(tx, email)@@ -117,7 +117,7 @@ func (c *AuthController) Register(ctx *gin.Context) {- Commits on status codes: 200, 201, 303- Rolls back on all other status codes or panics-**Preference:** For CRUD controller methods, always prefer using `middleware.Transactional` in the route + `middleware.GetTx(ctx)` in the controller over `pgdb.ExecuteTransaction`. The middleware approach keeps controllers flat, avoids nested closures, and follows the established pattern.+**Preference:** For CRUD controller methods, always prefer using `middleware.Transactional` in the route + `db.GetTx(ctx)` in the controller over `pgdb.ExecuteTransaction`. The middleware approach keeps controllers flat, avoids nested closures, and follows the established pattern. (The tx getter lives in the `db` package: `db.GetTx(ctx)`, not `middleware.GetTx`.)#### Repository PatternRepositories accept `*sql.Tx` to participate in transactions:@@ -266,6 +266,17 @@ NOTIFICATION_POLL_SECONDS=60 # polled rule evaluation interval; minimumONCALL_POLL_SECONDS=30 # on-call escalation worker interval; minimum 5, invalid values fall back to 30. Kept separate from NOTIFICATION_POLL_SECONDS so raising rule-evaluation intervals never delays paging. A buffered Wake() channel makes freshly opened pages notify L1 near-instantly regardless of this interval.OUTBOX_POLL_SECONDS=15 # notification outbox drain interval; minimum 5, invalid values fall back to 15. The outbox (backend/app/outbox, notification_outbox table in the main DB) is the persist-then-send layer for ALL notifications: rule dispatch and the escalator only enqueue (with an adapter-config snapshot) inside their transactions; the drain worker sends with retries (backoff 1m/5m/15m/60m, 5 attempts, then terminal failed + CaptureException). Crash-safe at-least-once: stale 'sending' rows are reclaimed after 5 min, cancelled rows can never resurrect (guarded status transitions), ack/resolve cancels queued page deliveries via outbox.CancelByKey. Cooldown and event-rule dedup record at enqueue commit (the durable promise), and fired_notifications is written at the terminal outcome. /api/health/deep exposes an `outbox` block; `traceway.outbox.*` metrics are emitted when monitoring is on; terminal rows are pruned daily (sent/cancelled 7d, failed 30d).+# Synthetics (synthetic uptime monitoring: backend/app/synthetics, /synthetics frontend route)+SYNTHETICS_POLL_SECONDS=15 # scheduler tick for due checks; minimum 5, invalid values fall back to 15. The scheduler enqueues due checks into the check_runs queue (main DB, outbox-style guarded claims, advisory lock 824737004) and records expired queued runs as `missed` in telemetry — a probe is never executed late. In-process executors claim http/tcp runs always, browser runs only when mode=embedded.+SYNTHETICS_BROWSER_MODE=off # off | embedded | remote. Browser checks are real @playwright/test specs executed by spawning Node against a harness dir (no npm/npx at runtime; allowlisted env so user scripts never see server secrets). `embedded` requires the :browser image (Dockerfile.browser, DuckDB base + Node + Chromium) and fails fast at startup otherwise; `remote` queues browser runs for traceway-runner binaries that long-poll /api/runners/poll authenticating with SYNTHETICS_RUNNER_SECRET. Hard-blocked in cloud mode (startup panic + 422 at check creation).+SYNTHETICS_RUNNER_SECRET= # shared bearer credential for the operator's runner fleet; required for remote mode (fail-fast at startup). Runners are deployment infrastructure, NOT tenant entities: no dashboard CRUD, no per-runner tokens. A runner self-registers a liveness row in synthetic_runners under its X-Traceway-Runner-Name on first poll (upsert throttled to 1/min via an in-memory cache; claim identity is "runner:<name>"). Rotation = change the secret + restart runners. Runner-side env: TRACEWAY_URL, TRACEWAY_RUNNER_SECRET, TRACEWAY_RUNNER_NAME (default hostname), RUNNER_WORKERS (default 2, max 16), and optional TRACEWAY_RUNNER_MONITORING (<project_token>@<url>/api/report) which self-instruments the runner with the Traceway Go SDK: default server metrics, a "browser_run" task trace per executed run (tags check_id/run_id/status, server_name = runner name), and CaptureException on infra failures (start/report errors, per-job panics recovered without killing the worker).+HEALTH_DEEP_TOKEN= # operator bearer secret gating GET /api/health/deep (its payload is instance-wide: cross-tenant queue depth, runner fleet, storage engine stats). Unset = endpoint disabled with a 401 pointing here.+SYNTHETICS_HTTP_CONCURRENCY=8 # concurrent in-process http/tcp probes+SYNTHETICS_BROWSER_CONCURRENCY=2 # concurrent Chromium instances in embedded mode (~300-500MB each)+SYNTHETICS_ALLOW_PRIVATE_TARGETS=true # "false" rejects checks that resolve to private/LAN addresses, validated at save AND at dial time for both http and tcp probes (netguard.GuardedDialContext dials the vetted IP, DNS-rebinding safe). Forced false in cloud mode regardless of env (tenants must never probe the platform's network). Default allow elsewhere: probing LAN services is a core self-hosted use case. When the guard is off, http probes honor HTTP(S)_PROXY; when on, the proxy is ignored so the guard vets the real target. Check creation also runs controllers.CheckLimitHook (nil = unlimited; cloud caps monitors per org plan).+SYNTHETICS_PLAYWRIGHT_DIR=/opt/traceway-playwright # Playwright harness dir (node_modules with pinned @playwright/test; docker/playwright/package.json pins the version)+SYNTHETICS_SCREENSHOT_RETENTION_DAYS=30 # browser failure artifacts under STORAGE_PATH/synthetics/ (.png screenshots AND .log Playwright output tails — failed browser runs store both, referenced by screenshot_key/output_key on check_results, served via GET /api/synthetics/screenshot|output?key= with project prefix checks); local storage only, 0 disables the cleanup worker+# Retention (see "Data Retention" section below)SQLITE_RETENTION_DAYS=30 # 0 to disable; only applies in SQLite modeDUCKDB_RETENTION_DAYS=30 # telemetry TTL on the DuckDB backend; when set it wins over SQLITE_RETENTION_DAYS there, when unset SQLITE_RETENTION_DAYS applies as fallback; 0 to disable@@ -493,6 +504,9 @@ const handleClick = createRowClickHandler('/issues/abc123', 'preset', 'from', 't/tasks Background tasks list/tasks/[task] Single task details/dashboards Dashboards page (tabs of org dashboards; /metrics redirects here)+/monitors Monitors (synthetic checks): single sidebar item, TabsRow tabs Monitors | Status Pages (?tab=, Status Pages admin-only); status pages tab has branding (description, logo upload, custom domain); old /monitors/status-pages redirects to the tab, /monitors/runners to /monitors (runners have no UI — operator infra)+/monitors/[checkId] Monitor detail (latency chart, uptime bars, runs w/ result filter, incidents)+/status/[slug] Public status page (light standalone design, no auth, raw fetch, listed in isPublicPath)/connection SDK integration guide```@@ -552,6 +566,8 @@ backend/| Admin org management | `UseAppAuth, RequireAdminAccess, Transactional` || Public (auth/invitations) | `Transactional` only || Client SDK ingestion | `CORSReport, UseClientAuth, UseGzip` |+| Synthetic runner API | `UseRunnerAuth` only (shared SYNTHETICS_RUNNER_SECRET bearer + self-registration by X-Traceway-Runner-Name; no Transactional — poll holds the request up to 25s) |+| Public status page | `RateLimitPerIP` only |### API Endpoints@@ -754,6 +770,29 @@ Org-scoped entities in the main DB. Teams (`teams`/`team_members`) own projects| GET/PUT | `/api/user-notification-rules` | App | Per-user notification-rule chains `{high: [{contactMethodId, delayMinutes}], low: [...]}` (PagerDuty-style: the page's urgency picks the chain; steps are enqueued at claim time as scheduled outbox deliveries and cancelled on ack; no chain = all enabled+verified methods immediately). Escalation policies carry `urgency: auto\|high\|low` in their definition (auto: critical -> high); pages store the resolved urgency || GET/POST | `/api/ack/:token` | None (rate-limited) | Tokenized no-login acknowledge: per-delivery `twk_` tokens (SHA-256-hashed on page_notifications), GET = read-only summary (scanner-safe), POST = idempotent ack recorded as `acknowledged_via='link'` attributed to the delivery's recipient; 404 after resolve. Frontend page: `/ack/[token]` |+**Monitors** (user-facing name for synthetic uptime checks; engine in `backend/app/synthetics`, frontend under `/monitors`, see the SYNTHETICS_* env block)++Checks (`synthetic_checks`, main DB) are http/tcp/browser probes with per-check interval, timeout, and a consecutive-failure threshold (flap damping). Runs flow through the `check_runs` queue (outbox-style guarded claims, terminal rows deleted, expired queued runs recorded as `missed`); results are telemetry (`check_results`, all three backends, pruned by the SQLite retention worker / 90d CH TTL). State transitions open/resolve `check_incidents` and feed the event-driven notification rule type `check_down` (recovery auto-resolves the page a rule-scoped dedup key opened via `oncall.AutoResolveByDedupKey`; recovery never dispatches to escalation channels). The notify hook runs post-commit with no ambient tx (SQLite single-connection). Remember: `notification_rule.repository.go` (both copies) lists event rule types explicitly, and `check_down` is one of them.++| Method | Endpoint | Auth | Purpose |+|--------|----------|------|---------|+| GET/POST | `/api/synthetics/checks` | App / App+Write | List / create checks (422 validation incl. browser-mode + cloud gates) |+| GET/PUT/DELETE | `/api/synthetics/checks/:id` | App / +Write / +Write | Detail+incidents / update (type immutable; pausing drops queued runs) / delete (auto-resolves the check's open pages) |+| POST | `/api/synthetics/checks/:id/run` | App+Write | Run now (422 if a run is already queued; OnCommit wake) |+| POST | `/api/synthetics/overview` | App | Checks + per-range aggregates (uptime, avg latency) |+| POST | `/api/synthetics/checks/:id/results` | App | Paginated run history (telemetry read, no Transactional; optional `status` filter up/down/missed + fromDate/toDate) |+| POST | `/api/synthetics/checks/:id/series` | App | Bucketed uptime/latency series (telemetry read) |+| GET | `/api/synthetics/screenshot?key=` | App | Streams a failure screenshot; key prefix-checked against the project |+| GET | `/api/synthetics/output?key=` | App | Streams a failed browser run's stored Playwright output (.log keys only, same prefix check); "logs" link in the run history UI |+| GET | `/api/synthetics/open-count` | App | Down-check count for the sidebar badge |+| POST | `/api/runners/poll` | Runner (shared secret) | Instance-wide long-poll claim of browser runs (25s hold on the wake channel, NO Transactional, excluded from tracewaygin self-monitoring); self-registers the runner's liveness row |+| POST | `/api/runners/results/:runId` | Runner (shared secret) | Report an outcome (MaxBytesReader 6MB incl. screenshotBase64; idempotent: lost/missing claim = 200 no-op; claims keyed "runner:<name>") |+| GET/POST/PUT/DELETE | `/api/organizations/:organizationId/status-pages(/:id)` | Member / Admin | Status page CRUD (slug `[a-z0-9-]{3,60}` unique, checkIds validated against the org; branding fields `description`, `customDomain` unique hostname) |+| POST | `/api/organizations/:organizationId/status-pages/:id/logo` | Admin | Upload a PNG/JPEG logo (raw body, 1MB cap, sniffed content type; SVG rejected as scriptable) stored via storage.Store under `statuspages/<id>/logo` |+| GET | `/api/status/:slug/logo` | None (rate-limited) | Streams a public page's logo |+| GET | `/api/status-domains/resolve` | None (rate-limited) | Maps the request Host header to a public status page slug — backs CNAMEd vanity domains (TLS terminates at the operator's proxy); the SPA calls it for anonymous visits to `/` |+| GET | `/api/status/:slug` | None (rate-limited) | Public status payload: per-check status + 90 daily uptime buckets + incidents; cached ~30s per slug; private/unknown slugs are both 404; latency values stripped. Frontend page: `/status/[slug]` (in `isPublicPath`) |+**Logs**| Method | Endpoint | Auth | Purpose ||--------|----------|------|---------|@@ -813,6 +852,11 @@ func (c *ReportController) Report(ctx *gin.Context) {| `project_dashboards` | Which projects show a dashboard, and tab order || `dashboard_templates` | Marketplace templates (key, category, definition), seeded by migrations || `starred_dashboard_widgets` | Homepage layout per project (dashboard id + widget id, position, col_span, size) |+| `synthetic_checks` | Synthetic check config + current state (status, consecutive_failures, next_run_at) |+| `check_runs` | Synthetic run queue (queued/claimed only; terminal rows deleted, telemetry is the record) |+| `check_incidents` | Down/up incident spans per check (feeds status pages) |+| `synthetic_runners` | Liveness registry for self-registered runner fleet (unique name, version, first/last_seen_at; no credentials, no org scoping) |+| `status_pages` | Public uptime pages (org-scoped slug + selected check ids + branding: description, logo_key, unique custom_domain) || `widget_groups` / `widget_group_widgets` / `starred_widgets` | Legacy pre-dashboards tables, retained read-only for rollback until a follow-up drop |#### ClickHouse vs PostgreSQL Decision Guide@@ -833,10 +877,11 @@ In SQLite mode (`DB_TYPE=sqlite`), the backend uses **two separate SQLite databa- `users`, `organizations`, `organization_users`, `projects`, `invitations`- `source_maps`, `metric_registry`, `dashboards`, `project_dashboards`, `dashboard_templates`, `starred_dashboard_widgets` (plus the legacy `widget_groups`/`widget_group_widgets`/`starred_widgets`)- `notification_channels`, `notification_rules`+- `synthetic_checks`, `check_runs`, `check_incidents`, `synthetic_runners`, `status_pages`**Telemetry DB tables** (`db.TelemetryDB` — non-transactional, uses lit with `db.TelemetryDB` directly):- `endpoints`, `tasks`, `exception_stack_traces`, `spans`, `metric_points`-- `session_recordings`, `archived_exceptions`, `slow_endpoints`, `fired_notifications`+- `session_recordings`, `archived_exceptions`, `slow_endpoints`, `fired_notifications`, `check_results`**How to access each database in repository code:**@@ -871,7 +916,7 @@ Built with `-tags telemetry_duckdb` (`CGO_ENABLED=1` required), this is an alter- **Driver:** `github.com/duckdb/duckdb-go/v2` (the official driver; marcboeker/go-duckdb is deprecated). Bundles prebuilt static libs for glibc only — **not musl/Alpine**, so the image uses Debian (`Dockerfile.duckdb`).- **Opened in** `backend/app/db/db_telemetry_duckdb.go`: telemetry path is the SQLite path with `.db` swapped for `_telemetry.duckdb`. By default DuckDB auto-tunes to the host; `DUCKDB_MEMORY_LIMIT`/`DUCKDB_THREADS`/`DUCKDB_CHECKPOINT_THRESHOLD` (passed through as DSN config options) let operators cap memory/threads so a memory-capped container doesn't read the host's RAM and OOM-kill the backend, and raise the WAL checkpoint threshold (default 16MB) so sustained Appender ingest isn't stalled by frequent checkpoints. `preserve_insertion_order=false` is always set — telemetry reads all have explicit ORDER BY, and dropping the guarantee lets DuckDB parallelize bulk loads and large scans with less memory. The read pool is bounded (`SetMaxOpenConns(duckDBMaxReadConns)`) since each DuckDB connection can use all threads + its own query memory; Appender writes use their own `DuckDBConnector.Connect()` connections and bypass that cap. Exposes `db.DuckDBConnector` (needed for the Appender).- **Writes use the Appender API**, not `INSERT` (`duckdb.NewAppenderFromConn(conn, "", table)` → `AppendRow(...)` → `Close()` flushes). Upserts still go through `ExecContext` with `ON CONFLICT`. The Appender rejects typed `*string` for nullable VARCHAR — use `nullableString()` in `backend/app/repositories/telemetry/duckdb/helpers.go` (returns untyped `nil` or the dereferenced value).-- **Write-path observability:** a row the Appender rejects is dropped rather than failing the whole frame (the SQLite backend 500s instead), so a poison row cannot wedge the SDK's retry loop. Every drop increments a per-table counter (`db.RecordTelemetryRowDropped`) and fires a rate-limited (1/min per table) `traceway.CaptureException`; Appender flush/connect failures still propagate to the request (500, SDK retries) and increment an insert-failure counter. `GET /api/health/deep` (App auth, all telemetry backends) exposes `telemetryBackend`, `droppedRows` per table, `droppedRowsTotal`, `insertFailures`, `ingestRejected` (requests turned away by the ingest admission gate), and on DuckDB an `engine` object (db/WAL file bytes, `duckdb_memory()` usage, read-pool in-use/wait stats) alongside its existing ClickHouse fields; it 503s only when the configured telemetry backend is ClickHouse and CH is unreachable (the embedded backends answer 200 with `chReachable:false`). The benchmark loadgen polls it before/after every ramp step and fails any step whose drop delta is nonzero; read-probe fills record cumulative `droppedRows` per fill level. When `MONITORING_TRACEWAY_URL` is set, `monitoring.StartTelemetryDBReporter` also emits `traceway.duckdb.*` metrics every 10s: `rows_dropped.delta`, `insert_failures.delta`, `db_size_mb`, `wal_size_mb`, `memory_used_mb`, `read_pool.in_use`, `read_pool.wait_count.delta`, `read_pool.wait_ms.delta`. The hourly retention worker issues a `CHECKPOINT` after its deletes so retention actually reclaims disk (DuckDB otherwise defers reclamation to the WAL checkpoint threshold).+- **Write-path observability:** a row the Appender rejects is dropped rather than failing the whole frame (the SQLite backend 500s instead), so a poison row cannot wedge the SDK's retry loop. Every drop increments a per-table counter (`db.RecordTelemetryRowDropped`) and fires a rate-limited (1/min per table) `traceway.CaptureException`; Appender flush/connect failures still propagate to the request (500, SDK retries) and increment an insert-failure counter. `GET /api/health/deep` (operator endpoint: requires the HEALTH_DEEP_TOKEN bearer secret, unset disables it; all telemetry backends) exposes `telemetryBackend`, `droppedRows` per table, `droppedRowsTotal`, `insertFailures`, `ingestRejected` (requests turned away by the ingest admission gate), and on DuckDB an `engine` object (db/WAL file bytes, `duckdb_memory()` usage, read-pool in-use/wait stats) alongside its existing ClickHouse fields; it 503s only when the configured telemetry backend is ClickHouse and CH is unreachable (the embedded backends answer 200 with `chReachable:false`). The benchmark loadgen polls it before/after every ramp step and fails any step whose drop delta is nonzero; read-probe fills record cumulative `droppedRows` per fill level. When `MONITORING_TRACEWAY_URL` is set, `monitoring.StartTelemetryDBReporter` also emits `traceway.duckdb.*` metrics every 10s: `rows_dropped.delta`, `insert_failures.delta`, `db_size_mb`, `wal_size_mb`, `memory_used_mb`, `read_pool.in_use`, `read_pool.wait_count.delta`, `read_pool.wait_ms.delta`. The hourly retention worker issues a `CHECKPOINT` after its deletes so retention actually reclaims disk (DuckDB otherwise defers reclamation to the WAL checkpoint threshold).- **`lit` placeholders:** `db.Driver` stays `lit.SQLite`, which emits `?` — DuckDB accepts these, so no separate driver was needed for reads.- **Migrations:** `backend/app/migrations/duckdb_telemetry/` (mirrors `sqlite_telemetry/` table-for-table; integer columns are `BIGINT`, JSON is `VARCHAR`, no secondary indexes since it's columnar).- **Dialect gotchas vs SQLite** (the read queries differ): native `quantile_cont(col, p)` for P50/P95/P99 instead of fetch-and-sort; `strftime('%s',col)`→`epoch(col)`; time bucketing via `time_bucket(to_seconds(N), col, TIMESTAMP '1970-01-01')` — the explicit epoch origin is required because DuckDB anchors sub-day buckets at 2000-01-03 by default, which would misalign chart buckets against the SQLite backend's epoch-floored buckets for any interval that doesn't evenly divide a day; `json_extract`→`json_extract_string`; `json_each`→`LATERAL unnest(json_keys(x))`; strict GROUP BY needs `ANY_VALUE`/`arg_max`; `SUM` returns HUGEINT (CAST to BIGINT); `CAST(.. AS REAL)`→`CAST(.. AS DOUBLE)`.@@ -894,6 +939,7 @@ Retention is handled in several different ways depending on the deployment.| `profiling_samples` (the bulk) | **30 days** | `0068_add_ttl_profiling_samples.up.sql` || `profiles` (slim metadata) | **30 days** | `0069_add_ttl_profiles.up.sql` || `profiling_stacks` (dedup table) | **30 days** | `0070_add_ttl_profiling_stacks.up.sql` |+| `check_results` (synthetic check probes) | **90 days** | `0083_add_ttl_check_results.up.sql` || All other CH tables (`transactions`, `exception_stack_traces`, `tasks`, `spans`, `sessions`, `ai_traces`, `session_recordings`, `fired_notifications`, `archived_exceptions`, `slow_endpoints`, `endpoints`, etc.) | **No TTL — retained indefinitely** | — |The three profiling tables share a 30-day TTL keyed on each table's time column (`start_time` / `recorded_at` / `last_seen`). `profiling_stacks` is a `ReplacingMergeTree(last_seen)` dedup table, so `last_seen` is bumped on every re-ingest that references a stack — a stack only ages out once it has gone unreferenced for the full window, which is exactly when its samples have also expired, so no sample is ever left pointing at a dropped stack.@@ -916,9 +962,12 @@ Tables it prunes (and the column used):| Telemetry | `profiling_samples` | `start_time` || Telemetry | `profiles` | `recorded_at` || Telemetry | `profiling_stacks` | `last_seen` |+| Telemetry | `check_results` | `recorded_at` |`archived_exceptions` (per-hash flags) and `slow_endpoints` (per-endpoint config) are intentionally skipped — they are not time-series data. `profiling_stacks` *is* pruned (unlike those two) because it holds no user intent — it is a regenerable dedup table whose `last_seen` tracks the most recent referencing sample, so deleting expired stacks is safe.+**2c. Synthetics failure screenshots — `retention.Start` worker** (`backend/app/retention/synthetics.go`). Browser-check failure screenshots written to local disk under `<STORAGE_PATH>/synthetics/` are aged out hourly by mtime, mirroring the session-recording split: the `check_results` rows referencing them are pruned separately (item 2 / CH TTL) and deliberately not coupled. `SYNTHETICS_SCREENSHOT_RETENTION_DAYS` (default 30, `0` disables); no-op unless `STORAGE_TYPE=local`.+**2b. Log row cap — `retention.Start` worker** (`backend/app/retention/log_cap.go`). SQLite mode only (SQLite or DuckDB telemetry), off by default. When `LOG_RECORDS_MAX_ROWS` is set to a positive N, a worker runs once at startup and then every minute and deletes `log_records` rows strictly older than the Nth-newest row's `timestamp` (single portable DELETE with an `ORDER BY timestamp DESC LIMIT 1 OFFSET N-1` subquery; NULL boundary = no-op under the cap, boundary ties are kept). **The cap is best-effort, not a hard limit**: nothing throttles ingest, so between passes the table can exceed N, and sustained ingest above N rows/minute keeps it above the cap permanently — document it to users as a cleanup task with a 1-minute window, sized with headroom for peak log volume. Bounds log disk usage independently of `SQLITE_RETENTION_DAYS`; disk reclamation still happens via the hourly retention pass / DuckDB WAL checkpointing.**3. On-disk session recordings — `retention.Start` worker** (`backend/app/retention/recordings.go`). Session recordings written to local disk (`STORAGE_TYPE=local`) accumulate under `<STORAGE_PATH>/recordings/`. A second worker walks that directory once at startup and then every hour and removes files whose `mtime` is older than the TTL, then prunes any directories left empty. The worker is a no-op when `STORAGE_TYPE=s3`.diff --git a/Dockerfile.browser b/Dockerfile.browsernew file mode 100644index 00000000..97a7a34e--- /dev/null+++ b/Dockerfile.browser@@ -0,0 +1,111 @@+# ==============================================================================+# Traceway Browser (Synthetics) Docker Image+# The DuckDB image plus Node + @playwright/test + headless Chromium, so+# browser synthetic checks run in-process (SYNTHETICS_BROWSER_MODE=embedded).+#+# Built on Debian like Dockerfile.duckdb: DuckDB links prebuilt glibc static+# libraries via CGO, and Playwright's Chromium build also requires glibc.+# Runs as root with --no-sandbox launch args (set by the backend's generated+# Playwright config), the standard trade-off for containerized Chromium.+#+# To bump Playwright, change the pinned @playwright/test version in+# docker/playwright/package.json; the browser build is downloaded to match.+# ==============================================================================++# ==============================================================================+# Stage 1: Build Frontend+# ==============================================================================+FROM --platform=$BUILDPLATFORM node:22-alpine AS frontend-builder++WORKDIR /app/frontend++COPY frontend/package.json frontend/package-lock.json ./++RUN npm ci++COPY frontend/ ./++ENV CLOUD_MODE=false+RUN npm run build++# ==============================================================================+# Stage 2: Build Backend with embedded frontend (telemetry_duckdb tag = DuckDB telemetry)+# Built natively (no cross-compile) because CGO cross-compilation against the+# prebuilt DuckDB libraries is impractical.+# ==============================================================================+FROM golang:1.26-bookworm AS backend-builder++WORKDIR /app/backend++RUN apt-get update && apt-get install -y --no-install-recommends git build-essential && rm -rf /var/lib/apt/lists/*++COPY backend/ ./+COPY cli/ /app/cli/++COPY --from=frontend-builder /app/frontend/build ./static/frontend/++RUN go mod edit -dropreplace=go.tracewayapp.com -dropreplace=go.tracewayapp.com/tracewaygin+RUN go mod tidy+RUN go mod download++RUN CGO_ENABLED=1 go build -tags telemetry_duckdb -ldflags="-s -w" -o /traceway ./cmd/traceway++# ==============================================================================+# Stage 3: Playwright harness (pinned @playwright/test + Chromium download).+# npm only exists here; the runtime invokes node against the CLI directly.+# ==============================================================================+FROM node:22-bookworm-slim AS playwright-builder++WORKDIR /opt/traceway-playwright++COPY docker/playwright/package.json ./++RUN npm install --omit=dev++ENV PLAYWRIGHT_BROWSERS_PATH=/opt/ms-playwright+# --only-shell installs just the chromium headless shell (~90MB), which is+# what headless test runs use since Playwright 1.49, skipping the full+# Chromium build (~170MB). Scripts forcing headed mode or channel:'chromium'+# would need the full install; a monitoring image does not.+RUN npx playwright install chromium --only-shell++# ==============================================================================+# Stage 4: Runtime image (Debian slim for glibc + libstdc++ + Chromium deps)+# ==============================================================================+FROM debian:bookworm-slim++RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates tzdata wget libstdc++6 && rm -rf /var/lib/apt/lists/*++# Node runtime + the Playwright harness + the downloaded Chromium build.+COPY --from=playwright-builder /usr/local/bin/node /usr/local/bin/node+COPY --from=playwright-builder /opt/traceway-playwright /opt/traceway-playwright+COPY --from=playwright-builder /opt/ms-playwright /opt/ms-playwright++# Chromium's system library dependencies, resolved by Playwright itself so the+# list tracks the pinned version instead of being hardcoded here.+RUN apt-get update && node /opt/traceway-playwright/node_modules/@playwright/test/cli.js install-deps chromium && rm -rf /var/lib/apt/lists/*++COPY --from=backend-builder /traceway /usr/local/bin/traceway++RUN mkdir -p /data && chmod 755 /data++WORKDIR /app++# DB_TYPE=sqlite selects the embedded codepath; in a telemetry_duckdb build that pairs a+# SQLite main DB (SQLITE_PATH) with a DuckDB telemetry DB derived alongside it+# (<path>_telemetry.duckdb). Both, plus local blob storage, live under /data.+ENV GIN_MODE=release \+ DB_TYPE=sqlite \+ SQLITE_PATH=/data/traceway.db \+ STORAGE_TYPE=local \+ STORAGE_PATH=/data/storage \+ PLAYWRIGHT_BROWSERS_PATH=/opt/ms-playwright \+ SYNTHETICS_BROWSER_MODE=embedded \+ SYNTHETICS_PLAYWRIGHT_DIR=/opt/traceway-playwright++EXPOSE 80 8082++HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \+ CMD wget -qO- http://localhost/health || exit 1++ENTRYPOINT ["/usr/local/bin/traceway"]diff --git a/backend/app/config/config.go b/backend/app/config/config.goindex b8b2d2f2..9f8e33c8 100644--- a/backend/app/config/config.go+++ b/backend/app/config/config.go@@ -57,6 +57,17 @@ type Cfg struct {OncallPollSeconds stringOutboxPollSeconds string+ SyntheticsPollSeconds string+ SyntheticsBrowserMode string+ SyntheticsHTTPConcurrency string+ SyntheticsBrowserConcurrency string+ SyntheticsAllowPrivateTargets string+ SyntheticsPlaywrightDir string+ SyntheticsScreenshotRetentionDays string+ SyntheticsRunnerSecret string++ HealthDeepToken string+AllowPrivateNotificationTargets stringTwilioAccountSID string@@ -175,6 +186,17 @@ func LoadFromEnv() *Cfg {OncallPollSeconds: os.Getenv("ONCALL_POLL_SECONDS"),OutboxPollSeconds: os.Getenv("OUTBOX_POLL_SECONDS"),+ SyntheticsPollSeconds: os.Getenv("SYNTHETICS_POLL_SECONDS"),+ SyntheticsBrowserMode: os.Getenv("SYNTHETICS_BROWSER_MODE"),+ SyntheticsHTTPConcurrency: os.Getenv("SYNTHETICS_HTTP_CONCURRENCY"),+ SyntheticsBrowserConcurrency: os.Getenv("SYNTHETICS_BROWSER_CONCURRENCY"),+ SyntheticsAllowPrivateTargets: os.Getenv("SYNTHETICS_ALLOW_PRIVATE_TARGETS"),+ SyntheticsPlaywrightDir: os.Getenv("SYNTHETICS_PLAYWRIGHT_DIR"),+ SyntheticsScreenshotRetentionDays: os.Getenv("SYNTHETICS_SCREENSHOT_RETENTION_DAYS"),+ SyntheticsRunnerSecret: os.Getenv("SYNTHETICS_RUNNER_SECRET"),++ HealthDeepToken: os.Getenv("HEALTH_DEEP_TOKEN"),+AllowPrivateNotificationTargets: os.Getenv("ALLOW_PRIVATE_NOTIFICATION_TARGETS"),TwilioAccountSID: os.Getenv("TWILIO_ACCOUNT_SID"),diff --git a/backend/app/controllers/health_deep.go b/backend/app/controllers/health_deep.goindex 658a6574..dc5d42ed 100644--- a/backend/app/controllers/health_deep.go+++ b/backend/app/controllers/health_deep.go@@ -7,6 +7,7 @@ import ("github.com/gin-gonic/gin""github.com/tracewayapp/traceway/backend/app/db""github.com/tracewayapp/traceway/backend/app/outbox"+ "github.com/tracewayapp/traceway/backend/app/synthetics"traceway "go.tracewayapp.com")@@ -41,6 +42,7 @@ type HealthDeepResponse struct {IngestRejected uint64 `json:"ingestRejected"`Engine *db.TelemetryEngineStats `json:"engine,omitempty"`Outbox *outbox.HealthStats `json:"outbox,omitempty"`+ Synthetics *synthetics.HealthStats `json:"synthetics,omitempty"`}// 503 means the configured telemetry backend is down. On the embedded@@ -64,6 +66,11 @@ func (h healthDeepController) Get(c *gin.Context) {} else {traceway.CaptureException(fmt.Errorf("failed to load outbox health: %w", err))}+ if syntheticsStats, err := synthetics.HealthSnapshot(); err == nil {+ resp.Synthetics = syntheticsStats+ } else {+ traceway.CaptureException(fmt.Errorf("failed to load synthetics health: %w", err))+ }if resp.TelemetryBackend == "clickhouse" && !resp.CHReachable {c.JSON(http.StatusServiceUnavailable, resp)diff --git a/backend/app/controllers/limits.go b/backend/app/controllers/limits.goindex 09969ad7..e11f5785 100644--- a/backend/app/controllers/limits.go+++ b/backend/app/controllers/limits.go@@ -11,3 +11,7 @@ func (e *LimitExceededError) Error() string { return e.Message }var ProjectLimitHook func(tx *sql.Tx, orgId int) errorvar MemberLimitHook func(tx *sql.Tx, orgId int) error++// CheckLimitHook caps synthetic checks per organization (cloud plans). Nil+// means unlimited; a LimitExceededError surfaces as a 422 in the dialog.+var CheckLimitHook func(tx *sql.Tx, orgId int) errordiff --git a/backend/app/controllers/notification_rule.controller.go b/backend/app/controllers/notification_rule.controller.goindex b96b4c48..6d355460 100644--- a/backend/app/controllers/notification_rule.controller.go+++ b/backend/app/controllers/notification_rule.controller.go@@ -38,6 +38,7 @@ var validRuleTypes = map[string]bool{"ai_trace_cost": true,"ai_conversation_cost": true,"ai_flagged_content": true,+ "check_down": true,}func (ctrl *notificationRuleController) List(ctx *gin.Context) {diff --git a/backend/app/controllers/routes.go b/backend/app/controllers/routes.goindex cb0109f4..065ac934 100644--- a/backend/app/controllers/routes.go+++ b/backend/app/controllers/routes.go@@ -55,7 +55,7 @@ func RegisterControllers(router *gin.RouterGroup) {router.PUT("/projects", middleware.UseAppAuth, middleware.RequireProjectAccess, middleware.RequireWriteAccess, ProjectController.UpdateProject)router.DELETE("/projects", middleware.UseAppAuth, middleware.RequireProjectAccess, middleware.RequireWriteAccess, ProjectController.DeleteProject)- router.GET("/health/deep", middleware.UseAppAuth, HealthDeepController.Get)+ router.GET("/health/deep", middleware.UseHealthDeepToken, HealthDeepController.Get)router.POST("/stats", middleware.UseAppAuth, middleware.RequireProjectAccess, MetricRecordController.FindHomepageStats)router.GET("/dashboard", middleware.UseAppAuth, middleware.RequireProjectAccess, DashboardController.GetDashboard)@@ -219,6 +219,39 @@ func RegisterControllers(router *gin.RouterGroup) {router.POST("/notification-history", middleware.UseAppAuth, middleware.RequireProjectAccess, NotificationHistoryController.List)+ router.GET("/synthetics/checks", middleware.UseAppAuth, middleware.RequireProjectAccess, middleware.Transactional, SyntheticCheckController.List)+ router.POST("/synthetics/overview", middleware.UseAppAuth, middleware.RequireProjectAccess, middleware.Transactional, SyntheticCheckController.Overview)+ router.POST("/synthetics/checks", middleware.UseAppAuth, middleware.RequireProjectAccess, middleware.RequireWriteAccess, middleware.Transactional, SyntheticCheckController.Create)+ router.GET("/synthetics/checks/:id", middleware.UseAppAuth, middleware.RequireProjectAccess, middleware.Transactional, SyntheticCheckController.Get)+ router.PUT("/synthetics/checks/:id", middleware.UseAppAuth, middleware.RequireProjectAccess, middleware.RequireWriteAccess, middleware.Transactional, SyntheticCheckController.Update)+ router.DELETE("/synthetics/checks/:id", middleware.UseAppAuth, middleware.RequireProjectAccess, middleware.RequireWriteAccess, middleware.Transactional, SyntheticCheckController.Delete)+ router.POST("/synthetics/checks/:id/run", middleware.UseAppAuth, middleware.RequireProjectAccess, middleware.RequireWriteAccess, middleware.Transactional, SyntheticCheckController.RunNow)+ router.POST("/synthetics/checks/:id/results", middleware.UseAppAuth, middleware.RequireProjectAccess, SyntheticCheckController.Results)+ router.GET("/synthetics/screenshot", middleware.UseAppAuth, middleware.RequireProjectAccess, SyntheticCheckController.Screenshot)+ router.GET("/synthetics/output", middleware.UseAppAuth, middleware.RequireProjectAccess, SyntheticCheckController.Output)+ router.POST("/synthetics/checks/:id/series", middleware.UseAppAuth, middleware.RequireProjectAccess, SyntheticCheckController.Series)+ router.GET("/synthetics/open-count", middleware.UseAppAuth, middleware.RequireProjectAccess, middleware.Transactional, SyntheticCheckController.OpenCount)++ // No Transactional on either runner route: Poll holds the request for up+ // to 25s (a held transaction would starve the single-connection SQLite+ // main DB) and Result finalizes through ProcessOutcome, which manages its+ // own transactions.+ router.POST("/runners/poll", middleware.UseRunnerAuth, SyntheticRunnerController.Poll)+ router.POST("/runners/results/:runId", middleware.UseRunnerAuth, SyntheticRunnerController.Result)++ router.GET("/organizations/:organizationId/status-pages", middleware.UseAppAuth, middleware.RequireOrganizationAccess, middleware.Transactional, StatusPageController.List)+ router.POST("/organizations/:organizationId/status-pages", middleware.UseAppAuth, middleware.RequireAdminAccess, middleware.Transactional, StatusPageController.Create)+ router.PUT("/organizations/:organizationId/status-pages/:id", middleware.UseAppAuth, middleware.RequireAdminAccess, middleware.Transactional, StatusPageController.Update)+ router.DELETE("/organizations/:organizationId/status-pages/:id", middleware.UseAppAuth, middleware.RequireAdminAccess, middleware.Transactional, StatusPageController.Delete)+ router.POST("/organizations/:organizationId/status-pages/:id/logo", middleware.UseAppAuth, middleware.RequireAdminAccess, middleware.Transactional, StatusPageController.UploadLogo)+ // Anonymous, rate-limited, cached ~30s per slug; no Transactional (it+ // reads main DB + telemetry through its own short transactions).+ router.GET("/status/:slug", middleware.RateLimitPerIP(30, time.Minute), StatusPageController.Public)+ router.GET("/status/:slug/logo", middleware.RateLimitPerIP(60, time.Minute), StatusPageController.PublicLogo)+ // Maps a CNAMEd vanity host to its status page slug (called by the SPA+ // when an anonymous visitor lands on / of an unrecognized host).+ router.GET("/status-domains/resolve", middleware.RateLimitPerIP(60, time.Minute), StatusPageController.ResolveHost)+router.GET("/organizations/:organizationId/teams", middleware.UseAppAuth, middleware.RequireOrganizationAccess, middleware.Transactional, TeamController.List)router.POST("/organizations/:organizationId/teams", middleware.UseAppAuth, middleware.RequireAdminAccess, middleware.Transactional, TeamController.Create)router.PUT("/organizations/:organizationId/teams/:teamId", middleware.UseAppAuth, middleware.RequireAdminAccess, middleware.Transactional, TeamController.Update)diff --git a/backend/app/controllers/status_page.controller.go b/backend/app/controllers/status_page.controller.gonew file mode 100644index 00000000..0ab083f9--- /dev/null+++ b/backend/app/controllers/status_page.controller.go@@ -0,0 +1,546 @@+package controllers++import (+ "database/sql"+ "encoding/json"+ "fmt"+ "io"+ "net"+ "net/http"+ "regexp"+ "strconv"+ "strings"+ "sync"+ "time"++ "github.com/gin-gonic/gin"+ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"+ "github.com/tracewayapp/traceway/backend/app/repositories/telemetry"+ "github.com/tracewayapp/traceway/backend/app/repositories/transactional"+ "github.com/tracewayapp/traceway/backend/app/storage"++ traceway "go.tracewayapp.com"+)++type statusPageController struct{}++func organizationIdFromPath(ctx *gin.Context) (int, bool) {+ id, err := strconv.Atoi(ctx.Param("organizationId"))+ if err != nil || id < 1 {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid organization id"})+ return 0, false+ }+ return id, true+}++var statusPageSlugPattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-]{1,58}[a-z0-9]$`)++const (+ statusPageUptimeDays = 90+ statusPageCacheTTL = 30 * time.Second+ statusPageMaxChecks = 50+ statusPageIncidentCap = 20+)++type statusPageRequest struct {+ Name string `json:"name"`+ Slug string `json:"slug"`+ IsPublic bool `json:"isPublic"`+ CheckIds []int `json:"checkIds"`+ Description string `json:"description"`+ CustomDomain string `json:"customDomain"`+}++var customDomainPattern = regexp.MustCompile(`^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)+$`)++func validateStatusPageRequest(tx *sql.Tx, organizationId int, req *statusPageRequest) (string, error) {+ req.Name = strings.TrimSpace(req.Name)+ req.Slug = strings.ToLower(strings.TrimSpace(req.Slug))+ if req.Name == "" {+ return "Name is required.", nil+ }+ if len(req.Name) > 200 {+ return "Name must be 200 characters or fewer.", nil+ }+ if !statusPageSlugPattern.MatchString(req.Slug) {+ return "Slug must be 3-60 characters of lowercase letters, digits, and hyphens.", nil+ }+ if len(req.CheckIds) == 0 {+ return "Select at least one check.", nil+ }+ if len(req.CheckIds) > statusPageMaxChecks {+ return "A status page can show at most 50 checks.", nil+ }+ req.Description = strings.TrimSpace(req.Description)+ if len(req.Description) > 500 {+ return "Description must be 500 characters or fewer.", nil+ }+ req.CustomDomain = strings.ToLower(strings.TrimSpace(req.CustomDomain))+ if req.CustomDomain != "" && !customDomainPattern.MatchString(req.CustomDomain) {+ return "Custom domain must be a bare hostname like status.example.com (no scheme or path).", nil+ }+ for _, checkId := range req.CheckIds {+ check, err := transactional.SyntheticCheckRepository.FindByIdInOrganization(tx, checkId, organizationId)+ if err != nil {+ return "", err+ }+ if check == nil {+ return "One of the selected checks does not belong to this organization.", nil+ }+ }+ return "", nil+}++func (ctrl *statusPageController) List(ctx *gin.Context) {+ organizationId, ok := organizationIdFromPath(ctx)+ if !ok {+ return+ }+ tx := db.GetTx(ctx)+ pages, err := transactional.StatusPageRepository.ListByOrganization(tx, organizationId)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to list status pages: %w", err))+ return+ }+ if pages == nil {+ pages = []*models.StatusPage{}+ }+ ctx.JSON(http.StatusOK, gin.H{"statusPages": pages})+}++func (ctrl *statusPageController) Create(ctx *gin.Context) {+ organizationId, ok := organizationIdFromPath(ctx)+ if !ok {+ return+ }+ var req statusPageRequest+ if err := ctx.ShouldBindJSON(&req); err != nil {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})+ return+ }+ tx := db.GetTx(ctx)+ if message, err := validateStatusPageRequest(tx, organizationId, &req); err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to validate status page: %w", err))+ return+ } else if message != "" {+ ctx.JSON(http.StatusUnprocessableEntity, gin.H{"error": message})+ return+ }+ if existing, err := transactional.StatusPageRepository.FindBySlug(tx, req.Slug); err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to check slug uniqueness: %w", err))+ return+ } else if existing != nil {+ ctx.JSON(http.StatusUnprocessableEntity, gin.H{"error": "This slug is already taken."})+ return+ }+ if req.CustomDomain != "" {+ if existing, err := transactional.StatusPageRepository.FindByCustomDomain(tx, req.CustomDomain); err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to check domain uniqueness: %w", err))+ return+ } else if existing != nil {+ ctx.JSON(http.StatusUnprocessableEntity, gin.H{"error": "This custom domain is already used by another status page."})+ return+ }+ }++ checkIdsJSON, _ := json.Marshal(req.CheckIds)+ now := time.Now().UTC()+ page := &models.StatusPage{+ OrganizationId: organizationId,+ Slug: req.Slug,+ Name: req.Name,+ IsPublic: req.IsPublic,+ CheckIds: models.JSONText(checkIdsJSON),+ Description: req.Description,+ CustomDomain: req.CustomDomain,+ CreatedAt: now,+ UpdatedAt: now,+ }+ id, err := transactional.StatusPageRepository.Create(tx, page)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to create status page: %w", err))+ return+ }+ page.Id = id+ ctx.JSON(http.StatusCreated, page)+}++func (ctrl *statusPageController) Update(ctx *gin.Context) {+ organizationId, ok := organizationIdFromPath(ctx)+ if !ok {+ return+ }+ id, err := strconv.Atoi(ctx.Param("id"))+ if err != nil || id < 1 {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid status page id"})+ return+ }+ var req statusPageRequest+ if err := ctx.ShouldBindJSON(&req); err != nil {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})+ return+ }+ tx := db.GetTx(ctx)+ page, err := transactional.StatusPageRepository.FindByIdForOrganization(tx, id, organizationId)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to load status page: %w", err))+ return+ }+ if page == nil {+ ctx.JSON(http.StatusNotFound, gin.H{"error": "Status page not found"})+ return+ }+ if message, err := validateStatusPageRequest(tx, organizationId, &req); err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to validate status page: %w", err))+ return+ } else if message != "" {+ ctx.JSON(http.StatusUnprocessableEntity, gin.H{"error": message})+ return+ }+ if req.Slug != page.Slug {+ if existing, err := transactional.StatusPageRepository.FindBySlug(tx, req.Slug); err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to check slug uniqueness: %w", err))+ return+ } else if existing != nil {+ ctx.JSON(http.StatusUnprocessableEntity, gin.H{"error": "This slug is already taken."})+ return+ }+ }+ if req.CustomDomain != "" && req.CustomDomain != page.CustomDomain {+ if existing, err := transactional.StatusPageRepository.FindByCustomDomain(tx, req.CustomDomain); err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to check domain uniqueness: %w", err))+ return+ } else if existing != nil && existing.Id != page.Id {+ ctx.JSON(http.StatusUnprocessableEntity, gin.H{"error": "This custom domain is already used by another status page."})+ return+ }+ }++ checkIdsJSON, _ := json.Marshal(req.CheckIds)+ previousSlug := page.Slug+ page.Name = req.Name+ page.Slug = req.Slug+ page.IsPublic = req.IsPublic+ page.CheckIds = models.JSONText(checkIdsJSON)+ page.Description = req.Description+ page.CustomDomain = req.CustomDomain+ page.UpdatedAt = time.Now().UTC()+ if err := transactional.StatusPageRepository.Update(tx, page); err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to update status page: %w", err))+ return+ }+ // A rename must drop the old slug's cached view too, or the retired URL+ // keeps serving for the rest of its TTL.+ invalidateStatusPageCache(previousSlug)+ invalidateStatusPageCache(page.Slug)+ ctx.JSON(http.StatusOK, page)+}++func (ctrl *statusPageController) Delete(ctx *gin.Context) {+ organizationId, ok := organizationIdFromPath(ctx)+ if !ok {+ return+ }+ id, err := strconv.Atoi(ctx.Param("id"))+ if err != nil || id < 1 {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid status page id"})+ return+ }+ tx := db.GetTx(ctx)+ page, err := transactional.StatusPageRepository.FindByIdForOrganization(tx, id, organizationId)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to load status page: %w", err))+ return+ }+ if page == nil {+ ctx.JSON(http.StatusNotFound, gin.H{"error": "Status page not found"})+ return+ }+ if err := transactional.StatusPageRepository.Delete(tx, id, organizationId); err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to delete status page: %w", err))+ return+ }+ invalidateStatusPageCache(page.Slug)+ ctx.JSON(http.StatusOK, gin.H{"deleted": true})+}++// Public payload shapes.++type statusPageCheckView struct {+ Name string `json:"name"`+ CheckType string `json:"checkType"`+ Status string `json:"status"`+ UptimePct *float64 `json:"uptimePct"`+ Days []*models.CheckSeriesPoint `json:"days"`+ Incidents []statusPageIncidentView `json:"incidents"`+}++type statusPageIncidentView struct {+ StartedAt time.Time `json:"startedAt"`+ ResolvedAt *time.Time `json:"resolvedAt"`+}++type statusPageView struct {+ Name string `json:"name"`+ Description string `json:"description"`+ HasLogo bool `json:"hasLogo"`+ Checks []statusPageCheckView `json:"checks"`+ GeneratedAt time.Time `json:"generatedAt"`+}++// The public endpoint is anonymous and its 90-day aggregation is far heavier+// than a point lookup, so responses are cached briefly per slug. Only found+// pages are cached: a miss is a single indexed lookup, and negative entries+// would let unknown-slug spam grow the map without bound.+var statusPageCache = struct {+ mu sync.Mutex+ entries map[string]statusPageCacheEntry+}{entries: map[string]statusPageCacheEntry{}}++type statusPageCacheEntry struct {+ view *statusPageView+ expiresAt time.Time+}++func invalidateStatusPageCache(slug string) {+ statusPageCache.mu.Lock()+ delete(statusPageCache.entries, slug)+ statusPageCache.mu.Unlock()+}++// Public serves GET /api/status/:slug with no authentication. Unknown and+// private slugs are both 404.+func (ctrl *statusPageController) Public(ctx *gin.Context) {+ slug := strings.ToLower(ctx.Param("slug"))+ if !statusPageSlugPattern.MatchString(slug) {+ ctx.JSON(http.StatusNotFound, gin.H{"error": "Status page not found"})+ return+ }++ now := time.Now().UTC()+ statusPageCache.mu.Lock()+ cached, ok := statusPageCache.entries[slug]+ statusPageCache.mu.Unlock()+ if ok && now.Before(cached.expiresAt) {+ ctx.JSON(http.StatusOK, cached.view)+ return+ }++ view, err := buildStatusPageView(ctx, slug, now)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to build status page: %w", err))+ return+ }+ if view == nil {+ ctx.JSON(http.StatusNotFound, gin.H{"error": "Status page not found"})+ return+ }+ statusPageCache.mu.Lock()+ for key, entry := range statusPageCache.entries {+ if now.After(entry.expiresAt) {+ delete(statusPageCache.entries, key)+ }+ }+ statusPageCache.entries[slug] = statusPageCacheEntry{view: view, expiresAt: now.Add(statusPageCacheTTL)}+ statusPageCache.mu.Unlock()++ ctx.JSON(http.StatusOK, view)+}++func buildStatusPageView(ctx *gin.Context, slug string, now time.Time) (*statusPageView, error) {+ type pageWithChecks struct {+ page *models.StatusPage+ checks []*models.SyntheticCheck+ }+ loaded, err := db.ExecuteTransaction(func(tx *sql.Tx) (pageWithChecks, error) {+ page, err := transactional.StatusPageRepository.FindPublicBySlug(tx, slug)+ if err != nil || page == nil {+ return pageWithChecks{}, err+ }+ var checkIds []int+ if err := json.Unmarshal(page.CheckIds, &checkIds); err != nil {+ return pageWithChecks{page: page}, nil+ }+ var checks []*models.SyntheticCheck+ for _, checkId := range checkIds {+ // Tolerates ids pointing at deleted checks.+ check, err := transactional.SyntheticCheckRepository.FindByIdInOrganization(tx, checkId, page.OrganizationId)+ if err != nil {+ return pageWithChecks{}, err+ }+ if check != nil {+ checks = append(checks, check)+ }+ }+ return pageWithChecks{page: page, checks: checks}, nil+ })+ if err != nil || loaded.page == nil {+ return nil, err+ }++ from := now.AddDate(0, 0, -statusPageUptimeDays)+ view := &statusPageView{+ Name: loaded.page.Name,+ Description: loaded.page.Description,+ HasLogo: loaded.page.LogoKey != "",+ Checks: []statusPageCheckView{},+ GeneratedAt: now,+ }+ for _, check := range loaded.checks {+ days, err := telemetry.CheckResultRepository.SeriesByCheck(ctx, check.ProjectId, check.Id, from, now, 1440)+ if err != nil {+ return nil, err+ }+ if days == nil {+ days = []*models.CheckSeriesPoint{}+ }+ var up, measured int64+ for _, day := range days {+ up += day.Up+ measured += day.Total - day.Missed+ }+ var uptimePct *float64+ if measured > 0 {+ pct := float64(up) / float64(measured) * 100+ uptimePct = &pct+ }+ // Latency values are internal detail; the public payload only carries+ // availability counts.+ for _, day := range days {+ day.AvgLatencyMs = 0+ day.MaxLatencyMs = 0+ }++ incidents, err := db.ExecuteTransaction(func(tx *sql.Tx) ([]*models.CheckIncident, error) {+ return transactional.CheckIncidentRepository.FindByCheckSince(tx, check.Id, from)+ })+ if err != nil {+ return nil, err+ }+ incidentViews := make([]statusPageIncidentView, 0, len(incidents))+ for i, incident := range incidents {+ if i >= statusPageIncidentCap {+ break+ }+ incidentViews = append(incidentViews, statusPageIncidentView{StartedAt: incident.StartedAt, ResolvedAt: incident.ResolvedAt})+ }++ status := check.CurrentStatus+ if !check.Enabled {+ status = models.CheckStatusUnknown+ }+ view.Checks = append(view.Checks, statusPageCheckView{+ Name: check.Name,+ CheckType: check.CheckType,+ Status: status,+ UptimePct: uptimePct,+ Days: days,+ Incidents: incidentViews,+ })+ }+ return view, nil+}++var StatusPageController = statusPageController{}++const statusPageLogoMaxBytes = 1 << 20++// UploadLogo stores a PNG/JPEG logo for the status page. SVG is deliberately+// rejected: it can carry scripts and this file is served to anonymous+// visitors.+func (ctrl *statusPageController) UploadLogo(ctx *gin.Context) {+ organizationId, ok := organizationIdFromPath(ctx)+ if !ok {+ return+ }+ id, err := strconv.Atoi(ctx.Param("id"))+ if err != nil || id < 1 {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid status page id"})+ return+ }+ tx := db.GetTx(ctx)+ page, err := transactional.StatusPageRepository.FindByIdForOrganization(tx, id, organizationId)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to load status page: %w", err))+ return+ }+ if page == nil {+ ctx.JSON(http.StatusNotFound, gin.H{"error": "Status page not found"})+ return+ }++ data, err := io.ReadAll(http.MaxBytesReader(ctx.Writer, ctx.Request.Body, statusPageLogoMaxBytes))+ if err != nil {+ ctx.JSON(http.StatusUnprocessableEntity, gin.H{"error": "The logo must be 1MB or smaller."})+ return+ }+ contentType := http.DetectContentType(data)+ if contentType != "image/png" && contentType != "image/jpeg" {+ ctx.JSON(http.StatusUnprocessableEntity, gin.H{"error": "The logo must be a PNG or JPEG image."})+ return+ }+ key := fmt.Sprintf("statuspages/%d/logo", page.Id)+ if err := storage.Store.Write(ctx, key, data); err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to store status page logo: %w", err))+ return+ }+ page.LogoKey = key+ page.UpdatedAt = time.Now().UTC()+ if err := transactional.StatusPageRepository.Update(tx, page); err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to save status page logo key: %w", err))+ return+ }+ invalidateStatusPageCache(page.Slug)+ ctx.JSON(http.StatusOK, page)+}++// PublicLogo streams the logo of a public status page.+func (ctrl *statusPageController) PublicLogo(ctx *gin.Context) {+ slug := strings.ToLower(ctx.Param("slug"))+ page, err := db.ExecuteTransaction(func(tx *sql.Tx) (*models.StatusPage, error) {+ return transactional.StatusPageRepository.FindPublicBySlug(tx, slug)+ })+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to load status page: %w", err))+ return+ }+ if page == nil || page.LogoKey == "" {+ ctx.JSON(http.StatusNotFound, gin.H{"error": "Not found"})+ return+ }+ data, err := storage.Store.Read(ctx, page.LogoKey)+ if err != nil {+ ctx.JSON(http.StatusNotFound, gin.H{"error": "Not found"})+ return+ }+ ctx.Header("Cache-Control", "public, max-age=300")+ ctx.Data(http.StatusOK, http.DetectContentType(data), data)+}++// ResolveHost maps the request's Host header to a public status page slug,+// so a CNAMEd vanity domain (status.example.com -> this instance) can land+// on its status page. TLS for the vanity host terminates at the operator's+// proxy; this endpoint only does the host-to-slug mapping.+func (ctrl *statusPageController) ResolveHost(ctx *gin.Context) {+ host := strings.ToLower(ctx.Request.Host)+ if h, _, err := net.SplitHostPort(host); err == nil {+ host = h+ }+ if host == "" || !customDomainPattern.MatchString(host) {+ ctx.JSON(http.StatusNotFound, gin.H{"error": "Not found"})+ return+ }+ page, err := db.ExecuteTransaction(func(tx *sql.Tx) (*models.StatusPage, error) {+ return transactional.StatusPageRepository.FindPublicByCustomDomain(tx, host)+ })+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to resolve status host: %w", err))+ return+ }+ if page == nil {+ ctx.JSON(http.StatusNotFound, gin.H{"error": "Not found"})+ return+ }+ ctx.JSON(http.StatusOK, gin.H{"slug": page.Slug})+}diff --git a/backend/app/controllers/synthetic_check.controller.go b/backend/app/controllers/synthetic_check.controller.gonew file mode 100644index 00000000..b073bce4--- /dev/null+++ b/backend/app/controllers/synthetic_check.controller.go@@ -0,0 +1,641 @@+package controllers++import (+ "encoding/json"+ "errors"+ "fmt"+ "net/http"+ "net/url"+ "regexp"+ "strconv"+ "strings"+ "time"++ "github.com/gin-gonic/gin"+ "github.com/tracewayapp/traceway/backend/app/config"+ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/middleware"+ "github.com/tracewayapp/traceway/backend/app/models"+ "github.com/tracewayapp/traceway/backend/app/netguard"+ "github.com/tracewayapp/traceway/backend/app/oncall"+ "github.com/tracewayapp/traceway/backend/app/repositories/telemetry"+ "github.com/tracewayapp/traceway/backend/app/repositories/transactional"+ "github.com/tracewayapp/traceway/backend/app/storage"+ "github.com/tracewayapp/traceway/backend/app/synthetics"++ "github.com/google/uuid"+ traceway "go.tracewayapp.com"+)++type syntheticCheckController struct{}++var validCheckTypes = map[string]bool{+ models.CheckTypeHttp: true, models.CheckTypeTcp: true, models.CheckTypeBrowser: true,+}++var validHttpMethods = map[string]bool{+ "GET": true, "HEAD": true, "POST": true, "PUT": true, "PATCH": true, "DELETE": true, "OPTIONS": true,+}++const maxBrowserScriptBytes = 100 << 10++const browserModeOffMessage = "Browser checks require SYNTHETICS_BROWSER_MODE=embedded (the :browser image) or a connected remote runner (SYNTHETICS_BROWSER_MODE=remote)."++type checkRequest struct {+ Name string `json:"name"`+ CheckType string `json:"checkType"`+ Enabled *bool `json:"enabled"`+ IntervalSeconds int `json:"intervalSeconds"`+ TimeoutSeconds int `json:"timeoutSeconds"`+ FailureThreshold int `json:"failureThreshold"`+ Config json.RawMessage `json:"config"`+}++// validateCheckRequest returns a 422 message, or an empty string when valid.+func validateCheckRequest(req *checkRequest) string {+ req.Name = strings.TrimSpace(req.Name)+ if req.Name == "" {+ return "Name is required."+ }+ if len(req.Name) > 200 {+ return "Name must be 200 characters or fewer."+ }+ if !validCheckTypes[req.CheckType] {+ return "Check type must be one of: http, tcp, browser."+ }+ if req.IntervalSeconds < synthetics.MinIntervalSeconds || req.IntervalSeconds > 86400 {+ return "Interval must be between 30 seconds and 24 hours."+ }+ if req.TimeoutSeconds < 1 || req.TimeoutSeconds > synthetics.MaxTimeoutSeconds {+ return "Timeout must be between 1 and 120 seconds."+ }+ if req.FailureThreshold < 1 || req.FailureThreshold > 10 {+ return "Failure threshold must be between 1 and 10."+ }+ if len(req.Config) == 0 {+ return "Check configuration is required."+ }++ switch req.CheckType {+ case models.CheckTypeHttp:+ var cfg models.HttpCheckConfig+ if err := json.Unmarshal(req.Config, &cfg); err != nil {+ return "The check configuration is not valid JSON."+ }+ return validateHttpCheckConfig(&cfg)+ case models.CheckTypeTcp:+ var cfg models.TcpCheckConfig+ if err := json.Unmarshal(req.Config, &cfg); err != nil {+ return "The check configuration is not valid JSON."+ }+ if strings.TrimSpace(cfg.Host) == "" {+ return "Host is required."+ }+ if cfg.Port < 1 || cfg.Port > 65535 {+ return "Port must be between 1 and 65535."+ }+ case models.CheckTypeBrowser:+ if config.Config.CloudMode == "true" {+ return "Browser checks are not available in cloud mode."+ }+ var cfg models.BrowserCheckConfig+ if err := json.Unmarshal(req.Config, &cfg); err != nil {+ return "The check configuration is not valid JSON."+ }+ if strings.TrimSpace(cfg.Script) == "" {+ return "A Playwright test script is required."+ }+ if len(cfg.Script) > maxBrowserScriptBytes {+ return "The test script must be 100KB or smaller."+ }+ }+ return ""+}++func validateHttpCheckConfig(cfg *models.HttpCheckConfig) string {+ cfg.URL = strings.TrimSpace(cfg.URL)+ if cfg.URL == "" {+ return "URL is required."+ }+ parsed, err := url.Parse(cfg.URL)+ if err != nil || (parsed.Scheme != "http" && parsed.Scheme != "https") || parsed.Host == "" {+ return "The URL must be a valid http:// or https:// address."+ }+ if cfg.Method != "" && !validHttpMethods[strings.ToUpper(cfg.Method)] {+ return "Method must be one of: GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS."+ }+ if cfg.Assertions.BodyRegex != "" {+ if _, err := regexp.Compile(cfg.Assertions.BodyRegex); err != nil {+ return "The body regex is not a valid regular expression."+ }+ }+ for _, code := range cfg.Assertions.StatusCodes {+ if code < 100 || code > 599 {+ return "Expected status codes must be between 100 and 599."+ }+ }+ // Friendly save-time rejection; the runner re-validates at dial time.+ if !synthetics.AllowPrivateTargets() {+ if err := netguard.ValidateURL(cfg.URL, false); err != nil {+ return err.Error()+ }+ }+ return ""+}++func (ctrl *syntheticCheckController) List(ctx *gin.Context) {+ projectId, err := middleware.GetProjectId(ctx)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("RequireProjectAccess middleware must be applied: %w", err))+ return+ }++ tx := db.GetTx(ctx)+ checks, err := transactional.SyntheticCheckRepository.FindByProject(tx, projectId)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to list synthetic checks: %w", err))+ return+ }+ if checks == nil {+ checks = []*models.SyntheticCheck{}+ }+ ctx.JSON(http.StatusOK, gin.H{"checks": checks})+}++type checkOverviewRequest struct {+ FromDate string `json:"fromDate"`+ ToDate string `json:"toDate"`+}++type checkOverviewItem struct {+ *models.SyntheticCheck+ Aggregates *models.CheckAggregates `json:"aggregates"`+}++func (ctrl *syntheticCheckController) Overview(ctx *gin.Context) {+ projectId, err := middleware.GetProjectId(ctx)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("RequireProjectAccess middleware must be applied: %w", err))+ return+ }+ var req checkOverviewRequest+ if err := ctx.ShouldBindJSON(&req); err != nil {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})+ return+ }+ from, to, ok := parseCheckRange(ctx, req.FromDate, req.ToDate)+ if !ok {+ return+ }++ tx := db.GetTx(ctx)+ checks, err := transactional.SyntheticCheckRepository.FindByProject(tx, projectId)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to list synthetic checks: %w", err))+ return+ }+ aggregates, err := telemetry.CheckResultRepository.AggregatesByProject(ctx, projectId, from, to)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to aggregate check results: %w", err))+ return+ }++ items := make([]checkOverviewItem, 0, len(checks))+ for _, check := range checks {+ items = append(items, checkOverviewItem{SyntheticCheck: check, Aggregates: aggregates[check.Id]})+ }+ ctx.JSON(http.StatusOK, gin.H{"checks": items})+}++func (ctrl *syntheticCheckController) Create(ctx *gin.Context) {+ projectId, err := middleware.GetProjectId(ctx)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("RequireProjectAccess middleware must be applied: %w", err))+ return+ }+ var req checkRequest+ if err := ctx.ShouldBindJSON(&req); err != nil {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})+ return+ }+ if message := validateCheckRequest(&req); message != "" {+ ctx.JSON(http.StatusUnprocessableEntity, gin.H{"error": message})+ return+ }+ // Gated on create only: an existing browser check must stay editable and+ // pausable after an operator turns the mode off.+ if req.CheckType == models.CheckTypeBrowser && synthetics.BrowserMode() == synthetics.BrowserModeOff {+ ctx.JSON(http.StatusUnprocessableEntity, gin.H{"error": browserModeOffMessage})+ return+ }++ now := time.Now().UTC()+ enabled := true+ if req.Enabled != nil {+ enabled = *req.Enabled+ }+ check := &models.SyntheticCheck{+ ProjectId: projectId,+ Name: req.Name,+ CheckType: req.CheckType,+ Enabled: enabled,+ IntervalSeconds: req.IntervalSeconds,+ TimeoutSeconds: req.TimeoutSeconds,+ Config: models.JSONText(req.Config),+ FailureThreshold: req.FailureThreshold,+ CurrentStatus: models.CheckStatusUnknown,+ NextRunAt: now,+ CreatedAt: now,+ UpdatedAt: now,+ }++ tx := db.GetTx(ctx)+ if CheckLimitHook != nil {+ project, err := transactional.ProjectRepository.FindById(tx, projectId)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to load project for check limit: %w", err))+ return+ }+ if project != nil && project.OrganizationId != nil {+ if err := CheckLimitHook(tx, *project.OrganizationId); err != nil {+ var limitErr *LimitExceededError+ if errors.As(err, &limitErr) {+ ctx.JSON(http.StatusUnprocessableEntity, gin.H{"error": limitErr.Message})+ return+ }+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("check limit hook failed: %w", err))+ return+ }+ }+ }+ id, err := transactional.SyntheticCheckRepository.Create(tx, check)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to create synthetic check: %w", err))+ return+ }+ check.Id = id+ ctx.JSON(http.StatusCreated, check)+}++func (ctrl *syntheticCheckController) Get(ctx *gin.Context) {+ projectId, checkId, ok := checkIdFromPath(ctx)+ if !ok {+ return+ }+ tx := db.GetTx(ctx)+ check, err := transactional.SyntheticCheckRepository.FindByIdForProject(tx, checkId, projectId)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to load synthetic check: %w", err))+ return+ }+ if check == nil {+ ctx.JSON(http.StatusNotFound, gin.H{"error": "Check not found"})+ return+ }+ incidents, err := transactional.CheckIncidentRepository.FindRecentByCheck(tx, checkId, 20)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to load check incidents: %w", err))+ return+ }+ if incidents == nil {+ incidents = []*models.CheckIncident{}+ }+ ctx.JSON(http.StatusOK, gin.H{"check": check, "incidents": incidents})+}++func (ctrl *syntheticCheckController) Update(ctx *gin.Context) {+ projectId, checkId, ok := checkIdFromPath(ctx)+ if !ok {+ return+ }+ var req checkRequest+ if err := ctx.ShouldBindJSON(&req); err != nil {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})+ return+ }++ tx := db.GetTx(ctx)+ check, err := transactional.SyntheticCheckRepository.FindByIdForProject(tx, checkId, projectId)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to load synthetic check: %w", err))+ return+ }+ if check == nil {+ ctx.JSON(http.StatusNotFound, gin.H{"error": "Check not found"})+ return+ }+ // The type shapes the config, the queue rows, and the telemetry history;+ // changing it would corrupt all three.+ req.CheckType = check.CheckType+ if message := validateCheckRequest(&req); message != "" {+ ctx.JSON(http.StatusUnprocessableEntity, gin.H{"error": message})+ return+ }++ now := time.Now().UTC()+ enabled := check.Enabled+ if req.Enabled != nil {+ enabled = *req.Enabled+ }+ wasEnabled := check.Enabled+ check.Name = req.Name+ check.Enabled = enabled+ check.IntervalSeconds = req.IntervalSeconds+ check.TimeoutSeconds = req.TimeoutSeconds+ check.FailureThreshold = req.FailureThreshold+ check.Config = models.JSONText(req.Config)+ check.UpdatedAt = now+ // Apply the new config/interval promptly instead of waiting out the old+ // interval.+ check.NextRunAt = now++ if err := transactional.SyntheticCheckRepository.Update(tx, check); err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to update synthetic check: %w", err))+ return+ }+ if wasEnabled && !enabled {+ if err := transactional.CheckRunRepository.DeleteQueuedByCheck(tx, check.Id); err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to drop queued runs for paused check: %w", err))+ return+ }+ }+ ctx.JSON(http.StatusOK, check)+}++func (ctrl *syntheticCheckController) Delete(ctx *gin.Context) {+ projectId, checkId, ok := checkIdFromPath(ctx)+ if !ok {+ return+ }+ tx := db.GetTx(ctx)+ check, err := transactional.SyntheticCheckRepository.FindByIdForProject(tx, checkId, projectId)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to load synthetic check: %w", err))+ return+ }+ if check == nil {+ ctx.JSON(http.StatusNotFound, gin.H{"error": "Check not found"})+ return+ }+ // Queued runs and incidents cascade with the check, but a page opened by a+ // check_down rule would survive with nothing left to ever resolve it.+ rules, err := transactional.NotificationRuleRepository.FindByProjectWithChannel(tx, projectId)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to load notification rules for check cleanup: %w", err))+ return+ }+ now := time.Now().UTC()+ for _, rule := range rules {+ if rule.RuleType != "check_down" {+ continue+ }+ if _, err := oncall.AutoResolveByDedupKeyTx(tx, rule.Id, fmt.Sprintf("check:%d", checkId), now); err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to resolve pages for deleted check: %w", err))+ return+ }+ }+ if err := transactional.SyntheticCheckRepository.Delete(tx, checkId, projectId); err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to delete synthetic check: %w", err))+ return+ }+ ctx.JSON(http.StatusOK, gin.H{"deleted": true})+}++func (ctrl *syntheticCheckController) RunNow(ctx *gin.Context) {+ projectId, checkId, ok := checkIdFromPath(ctx)+ if !ok {+ return+ }+ tx := db.GetTx(ctx)+ check, err := transactional.SyntheticCheckRepository.FindByIdForProject(tx, checkId, projectId)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to load synthetic check: %w", err))+ return+ }+ if check == nil {+ ctx.JSON(http.StatusNotFound, gin.H{"error": "Check not found"})+ return+ }+ // With the mode off nothing would ever claim the run; it would only sit in+ // the queue and expire as a missed result.+ if check.CheckType == models.CheckTypeBrowser && synthetics.BrowserMode() == synthetics.BrowserModeOff {+ ctx.JSON(http.StatusUnprocessableEntity, gin.H{"error": browserModeOffMessage})+ return+ }+ pending, err := transactional.CheckRunRepository.HasPendingForCheck(tx, checkId)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to inspect queued runs: %w", err))+ return+ }+ if pending {+ ctx.JSON(http.StatusUnprocessableEntity, gin.H{"error": "A run for this check is already queued."})+ return+ }++ now := time.Now().UTC()+ run := &models.CheckRun{+ CheckId: check.Id,+ ProjectId: projectId,+ CheckType: check.CheckType,+ Status: models.CheckRunQueued,+ ScheduledFor: now,+ ExpiresAt: synthetics.RunExpiry(now, check.IntervalSeconds),+ CreatedAt: now,+ }+ if _, err := transactional.CheckRunRepository.Enqueue(tx, run); err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to enqueue check run: %w", err))+ return+ }+ middleware.OnCommit(ctx, synthetics.Wake)+ ctx.JSON(http.StatusOK, gin.H{"queued": true})+}++type checkResultsRequest struct {+ FromDate string `json:"fromDate"`+ ToDate string `json:"toDate"`+ Status string `json:"status"`+ Pagination PaginationParams `json:"pagination"`+}++func (ctrl *syntheticCheckController) Results(ctx *gin.Context) {+ projectId, checkId, ok := checkIdFromPath(ctx)+ if !ok {+ return+ }+ var req checkResultsRequest+ if err := ctx.ShouldBindJSON(&req); err != nil {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})+ return+ }+ from, to, ok := parseCheckRange(ctx, req.FromDate, req.ToDate)+ if !ok {+ return+ }++ if req.Status != "" && req.Status != models.CheckResultUp && req.Status != models.CheckResultDown && req.Status != models.CheckResultMissed {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid status filter"})+ return+ }+ results, total, err := telemetry.CheckResultRepository.FindByCheck(ctx, projectId, checkId, &from, &to, req.Status, req.Pagination.Page, req.Pagination.PageSize)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to list check results: %w", err))+ return+ }+ if results == nil {+ results = []*models.CheckResultEntry{}+ }+ totalPages := total / int64(req.Pagination.PageSize)+ if total%int64(req.Pagination.PageSize) > 0 {+ totalPages+++ }+ ctx.JSON(http.StatusOK, PaginatedResponse[*models.CheckResultEntry]{+ Data: results,+ Pagination: Pagination{+ Page: req.Pagination.Page,+ PageSize: req.Pagination.PageSize,+ Total: total,+ TotalPages: totalPages,+ },+ })+}++type checkSeriesRequest struct {+ FromDate string `json:"fromDate"`+ ToDate string `json:"toDate"`+ IntervalMinutes int `json:"intervalMinutes"`+}++func (ctrl *syntheticCheckController) Series(ctx *gin.Context) {+ projectId, checkId, ok := checkIdFromPath(ctx)+ if !ok {+ return+ }+ var req checkSeriesRequest+ if err := ctx.ShouldBindJSON(&req); err != nil {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})+ return+ }+ from, to, ok := parseCheckRange(ctx, req.FromDate, req.ToDate)+ if !ok {+ return+ }+ interval := req.IntervalMinutes+ if interval < 1 {+ interval = 5+ }+ if interval > 1440 {+ interval = 1440+ }++ points, err := telemetry.CheckResultRepository.SeriesByCheck(ctx, projectId, checkId, from, to, interval)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to load check series: %w", err))+ return+ }+ if points == nil {+ points = []*models.CheckSeriesPoint{}+ }+ ctx.JSON(http.StatusOK, gin.H{"series": points})+}++// Screenshot streams a stored browser-check failure screenshot. The key is+// prefix-checked against the caller's project so one project can never read+// another's screenshots.+func (ctrl *syntheticCheckController) Screenshot(ctx *gin.Context) {+ projectId, err := middleware.GetProjectId(ctx)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("RequireProjectAccess middleware must be applied: %w", err))+ return+ }+ key := ctx.Query("key")+ expectedPrefix := fmt.Sprintf("synthetics/%s/", projectId)+ if !strings.HasPrefix(key, expectedPrefix) || strings.Contains(key, "..") {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid screenshot key"})+ return+ }+ data, err := storage.Store.Read(ctx, key)+ if err != nil {+ ctx.JSON(http.StatusNotFound, gin.H{"error": "Screenshot not found"})+ return+ }+ ctx.Data(http.StatusOK, "image/png", data)+}++// Output streams the stored Playwright output (stdout/stderr tail) of a+// failed browser run, with the same project prefix check as Screenshot.+func (ctrl *syntheticCheckController) Output(ctx *gin.Context) {+ projectId, err := middleware.GetProjectId(ctx)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("RequireProjectAccess middleware must be applied: %w", err))+ return+ }+ key := ctx.Query("key")+ expectedPrefix := fmt.Sprintf("synthetics/%s/", projectId)+ if !strings.HasPrefix(key, expectedPrefix) || strings.Contains(key, "..") || !strings.HasSuffix(key, ".log") {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid output key"})+ return+ }+ data, err := storage.Store.Read(ctx, key)+ if err != nil {+ ctx.JSON(http.StatusNotFound, gin.H{"error": "Output not found"})+ return+ }+ ctx.Data(http.StatusOK, "text/plain; charset=utf-8", data)+}++func (ctrl *syntheticCheckController) OpenCount(ctx *gin.Context) {+ projectId, err := middleware.GetProjectId(ctx)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("RequireProjectAccess middleware must be applied: %w", err))+ return+ }+ tx := db.GetTx(ctx)+ count, err := transactional.SyntheticCheckRepository.CountDownByProject(tx, projectId)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to count down checks: %w", err))+ return+ }+ ctx.JSON(http.StatusOK, gin.H{"count": count})+}++// checkIdFromPath resolves the project id and the :id path param.+func checkIdFromPath(ctx *gin.Context) (projectId uuid.UUID, checkId int, ok bool) {+ pid, err := middleware.GetProjectId(ctx)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("RequireProjectAccess middleware must be applied: %w", err))+ return pid, 0, false+ }+ id, err := strconv.Atoi(ctx.Param("id"))+ if err != nil || id < 1 {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid check id"})+ return pid, 0, false+ }+ return pid, id, true+}++// parseCheckRange parses the fromDate/toDate body fields, defaulting to the+// last 24 hours.+func parseCheckRange(ctx *gin.Context, fromDate string, toDate string) (time.Time, time.Time, bool) {+ now := time.Now().UTC()+ from := now.Add(-24 * time.Hour)+ to := now+ if fromDate != "" {+ parsed, err := time.Parse(time.RFC3339, fromDate)+ if err != nil {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid fromDate"})+ return from, to, false+ }+ from = parsed.UTC()+ }+ if toDate != "" {+ parsed, err := time.Parse(time.RFC3339, toDate)+ if err != nil {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid toDate"})+ return from, to, false+ }+ to = parsed.UTC()+ }+ return from, to, true+}++var SyntheticCheckController = syntheticCheckController{}diff --git a/backend/app/controllers/synthetic_runner.controller.go b/backend/app/controllers/synthetic_runner.controller.gonew file mode 100644index 00000000..dcfbc2ba--- /dev/null+++ b/backend/app/controllers/synthetic_runner.controller.go@@ -0,0 +1,244 @@+package controllers++import (+ "database/sql"+ "encoding/base64"+ "encoding/json"+ "net/http"+ "strconv"+ "strings"+ "time"++ "github.com/gin-gonic/gin"+ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/middleware"+ "github.com/tracewayapp/traceway/backend/app/models"+ "github.com/tracewayapp/traceway/backend/app/repositories/transactional"+ "github.com/tracewayapp/traceway/backend/app/storage"+ "github.com/tracewayapp/traceway/backend/app/synthetics"++ traceway "go.tracewayapp.com"+)++type syntheticRunnerController struct{}++const (+ runnerPollWindow = 25 * time.Second+ runnerPollRecheck = 2 * time.Second+ runnerMaxJobs = 5+ runnerResultBodyLimit = 6 << 20 // screenshotBase64 dominates; gin has no default cap+)++type runnerPollRequest struct {+ MaxJobs int `json:"maxJobs"`+}++type runnerJob struct {+ RunId int `json:"runId"`+ CheckId int `json:"checkId"`+ TimeoutSeconds int `json:"timeoutSeconds"`+ Script string `json:"script"`+ Env map[string]string `json:"env"`+}++// Poll long-polls for claimable browser runs across the whole instance+// (runners are the operator's fleet, not tenant infrastructure).+// Deliberately NOT under middleware.Transactional: the request may hold the+// connection for 25s, and the SQLite main DB has a single connection — each+// claim attempt runs its own short transaction, and the wait happens on the+// browser-run wake channel, never against the DB.+func (ctrl *syntheticRunnerController) Poll(ctx *gin.Context) {+ runner, ok := middleware.GetRunner(ctx)+ if !ok {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("UseRunnerAuth middleware must be applied: %w", errMissingRunner))+ return+ }+ // Only remote mode hands browser runs to the fleet. In embedded mode the+ // in-process executor owns them; serving a stray runner here would split+ // execution across environments the operator did not choose.+ if synthetics.BrowserMode() != synthetics.BrowserModeRemote {+ ctx.JSON(http.StatusForbidden, gin.H{"error": "This instance is not in remote browser mode (SYNTHETICS_BROWSER_MODE=remote)."})+ return+ }+ var req runnerPollRequest+ if err := ctx.ShouldBindJSON(&req); err != nil && err.Error() != "EOF" {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})+ return+ }+ maxJobs := req.MaxJobs+ if maxJobs < 1 {+ maxJobs = 1+ }+ if maxJobs > runnerMaxJobs {+ maxJobs = runnerMaxJobs+ }++ deadline := time.NewTimer(runnerPollWindow)+ defer deadline.Stop()+ for {+ jobs, err := claimRunnerJobs(runner, maxJobs)+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to claim browser runs: %w", err))+ return+ }+ if len(jobs) > 0 {+ ctx.JSON(http.StatusOK, gin.H{"jobs": jobs})+ return+ }++ recheck := time.NewTimer(runnerPollRecheck)+ select {+ case <-ctx.Request.Context().Done():+ recheck.Stop()+ return+ case <-deadline.C:+ recheck.Stop()+ ctx.JSON(http.StatusOK, gin.H{"jobs": []runnerJob{}})+ return+ case <-synthetics.BrowserWakeChannel():+ recheck.Stop()+ case <-recheck.C:+ }+ }+}++func claimRunnerJobs(runner *models.SyntheticRunner, maxJobs int) ([]runnerJob, error) {+ claimedBy := runnerClaimedBy(runner.Name)+ now := time.Now().UTC()+ return db.ExecuteTransaction(func(tx *sql.Tx) ([]runnerJob, error) {+ due, err := transactional.CheckRunRepository.FindClaimableBrowser(tx, now, maxJobs)+ if err != nil {+ return nil, err+ }+ jobs := make([]runnerJob, 0, len(due))+ for _, run := range due {+ won, err := transactional.CheckRunRepository.Claim(tx, run.Id, claimedBy, now)+ if err != nil {+ return nil, err+ }+ if !won {+ continue+ }+ check, err := transactional.SyntheticCheckRepository.FindById(tx, run.CheckId)+ if err != nil {+ return nil, err+ }+ if check == nil {+ continue+ }+ var cfg models.BrowserCheckConfig+ if err := json.Unmarshal(check.Config, &cfg); err != nil {+ continue+ }+ jobs = append(jobs, runnerJob{+ RunId: run.Id,+ CheckId: check.Id,+ TimeoutSeconds: check.TimeoutSeconds,+ Script: cfg.Script,+ Env: cfg.Env,+ })+ }+ return jobs, nil+ })+}++// runnerClaimedBy keys claims by runner name: names are unique, stable+// across restarts, and independent of whether the liveness row insert+// succeeded.+func runnerClaimedBy(runnerName string) string {+ return "runner:" + runnerName+}++type runnerResultRequest struct {+ Status string `json:"status"`+ LatencyMs float64 `json:"latencyMs"`+ ErrorMessage string `json:"errorMessage"`+ ScreenshotBase64 string `json:"screenshotBase64"`+ // OutputTail is the Playwright stdout/stderr tail of a failed run,+ // stored next to the screenshot for debugging.+ OutputTail string `json:"outputTail"`+}++const runnerOutputTailLimit = 16 << 10++// Result finalizes a run a remote runner executed. Idempotent: a missing or+// re-owned run row means the run was already finalized (or reclaimed), and+// the outcome is discarded with a 200. Not under middleware.Transactional:+// ProcessOutcome manages its own transactions.+func (ctrl *syntheticRunnerController) Result(ctx *gin.Context) {+ runner, ok := middleware.GetRunner(ctx)+ if !ok {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("UseRunnerAuth middleware must be applied: %w", errMissingRunner))+ return+ }+ runId, err := strconv.Atoi(ctx.Param("runId"))+ if err != nil || runId < 1 {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid run id"})+ return+ }+ ctx.Request.Body = http.MaxBytesReader(ctx.Writer, ctx.Request.Body, runnerResultBodyLimit)+ var req runnerResultRequest+ if err := ctx.ShouldBindJSON(&req); err != nil {+ ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})+ return+ }+ if req.Status != models.CheckResultUp && req.Status != models.CheckResultDown {+ ctx.JSON(http.StatusUnprocessableEntity, gin.H{"error": "Status must be up or down."})+ return+ }++ run, err := db.ExecuteTransaction(func(tx *sql.Tx) (*models.CheckRun, error) {+ return transactional.CheckRunRepository.FindById(tx, runId)+ })+ if err != nil {+ ctx.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("failed to load run: %w", err))+ return+ }+ claimedBy := runnerClaimedBy(runner.Name)+ if run == nil || run.ClaimedBy != claimedBy {+ ctx.JSON(http.StatusOK, gin.H{"accepted": false})+ return+ }++ now := time.Now().UTC()+ outcome := synthetics.Outcome{+ Status: req.Status,+ LatencyMs: req.LatencyMs,+ ErrorMsg: req.ErrorMessage,+ TlsDaysRemaining: -1,+ ExecutedBy: runner.Name,+ ExecutedAt: now,+ }+ if req.ScreenshotBase64 != "" && req.Status == models.CheckResultDown {+ if data, decodeErr := base64.StdEncoding.DecodeString(req.ScreenshotBase64); decodeErr == nil && len(data) > 0 {+ key := "synthetics/" + run.ProjectId.String() + "/" + strconv.Itoa(run.CheckId) + "/" + strconv.FormatInt(now.UnixNano(), 10) + ".png"+ if writeErr := storage.Store.Write(ctx, key, data); writeErr == nil {+ outcome.ScreenshotKey = key+ } else {+ traceway.CaptureException(traceway.NewStackTraceErrorf("failed to store runner screenshot (run=%d): %w", runId, writeErr))+ }+ }+ }+ if output := strings.TrimSpace(req.OutputTail); output != "" && req.Status == models.CheckResultDown {+ if len(output) > runnerOutputTailLimit {+ output = output[len(output)-runnerOutputTailLimit:]+ }+ key := "synthetics/" + run.ProjectId.String() + "/" + strconv.Itoa(run.CheckId) + "/" + strconv.FormatInt(now.UnixNano(), 10) + ".log"+ if writeErr := storage.Store.Write(ctx, key, []byte(output)); writeErr == nil {+ outcome.OutputKey = key+ } else {+ traceway.CaptureException(traceway.NewStackTraceErrorf("failed to store runner output (run=%d): %w", runId, writeErr))+ }+ }++ synthetics.ProcessOutcome(ctx, run, claimedBy, outcome)+ ctx.JSON(http.StatusOK, gin.H{"accepted": true})+}++var errMissingRunner = &missingRunnerError{}++type missingRunnerError struct{}++func (*missingRunnerError) Error() string { return "no runner in context" }++var SyntheticRunnerController = syntheticRunnerController{}diff --git a/backend/app/middleware/use_health_token.middleware.go b/backend/app/middleware/use_health_token.middleware.gonew file mode 100644index 00000000..c4522002--- /dev/null+++ b/backend/app/middleware/use_health_token.middleware.go@@ -0,0 +1,28 @@+package middleware++import (+ "crypto/subtle"+ "net/http"+ "strings"++ "github.com/gin-gonic/gin"+ "github.com/tracewayapp/traceway/backend/app/config"+)++// UseHealthDeepToken guards the operator health endpoint. Its payload is+// instance-wide (cross-tenant queue depth, runner fleet size, storage+// engine stats), so it is gated on the HEALTH_DEEP_TOKEN deploy secret+// rather than any dashboard role; unset disables the endpoint entirely.+func UseHealthDeepToken(c *gin.Context) {+ token := config.Config.HealthDeepToken+ if token == "" {+ c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "The deep health endpoint is disabled: set HEALTH_DEEP_TOKEN"})+ return+ }+ presented, ok := strings.CutPrefix(c.GetHeader("Authorization"), "Bearer ")+ if !ok || subtle.ConstantTimeCompare([]byte(presented), []byte(token)) != 1 {+ c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Invalid health token"})+ return+ }+ c.Next()+}diff --git a/backend/app/middleware/use_runner_auth.middleware.go b/backend/app/middleware/use_runner_auth.middleware.gonew file mode 100644index 00000000..30be31c6--- /dev/null+++ b/backend/app/middleware/use_runner_auth.middleware.go@@ -0,0 +1,112 @@+package middleware++import (+ "crypto/subtle"+ "database/sql"+ "net/http"+ "strings"+ "sync"+ "time"++ "github.com/gin-gonic/gin"+ "github.com/tracewayapp/traceway/backend/app/config"+ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"+ "github.com/tracewayapp/traceway/backend/app/repositories/transactional"+ traceway "go.tracewayapp.com"+)++const RunnerContextKey = "syntheticRunner"++const runnerTouchInterval = time.Minute++// RunnerVersionHeader lets the runner binary report its version.+const RunnerVersionHeader = "X-Traceway-Runner-Version"++// RunnerNameHeader identifies the runner instance. Runners self-register+// under this name on first contact; it doubles as their claim identity.+const RunnerNameHeader = "X-Traceway-Runner-Name"++var UseRunnerAuth func(c *gin.Context)++type runnerCacheEntry struct {+ runner *models.SyntheticRunner+ touchedAt time.Time+}++var (+ runnerCacheMu sync.Mutex+ runnerCache = map[string]*runnerCacheEntry{}+)++// InitUseRunnerAuth authenticates runners with the shared+// SYNTHETICS_RUNNER_SECRET. Runners are operator infrastructure configured at+// deploy time, not tenant-managed identities, so there are no per-runner+// credentials: any holder of the secret may poll, and the runner+// self-registers a liveness row under its reported name (touched at most once+// a minute).+func InitUseRunnerAuth() {+ secret := config.Config.SyntheticsRunnerSecret+ UseRunnerAuth = func(c *gin.Context) {+ if secret == "" {+ c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Runner support is not enabled on this instance: set SYNTHETICS_RUNNER_SECRET"})+ return+ }+ header := c.GetHeader("Authorization")+ presented, ok := strings.CutPrefix(header, "Bearer ")+ if !ok || subtle.ConstantTimeCompare([]byte(presented), []byte(secret)) != 1 {+ c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Invalid runner secret"})+ return+ }+ runner := resolveRunner(c.GetHeader(RunnerNameHeader), c.GetHeader(RunnerVersionHeader))+ c.Set(RunnerContextKey, runner)+ c.Next()+ }+}++// resolveRunner returns the liveness row for a runner name, registering or+// touching it when the cached copy is stale. A DB failure degrades to a+// transient in-memory row: liveness reporting must never block claiming.+func resolveRunner(name string, version string) *models.SyntheticRunner {+ name = strings.TrimSpace(name)+ if name == "" {+ name = "unnamed"+ }+ if len(name) > 200 {+ name = name[:200]+ }+ now := time.Now().UTC()++ runnerCacheMu.Lock()+ entry, cached := runnerCache[name]+ runnerCacheMu.Unlock()+ if cached && now.Sub(entry.touchedAt) < runnerTouchInterval &&+ (version == "" || version == entry.runner.Version) {+ return entry.runner+ }++ runner, err := db.ExecuteTransaction(func(tx *sql.Tx) (*models.SyntheticRunner, error) {+ return transactional.SyntheticRunnerRepository.UpsertSeen(tx, name, version, now)+ })+ if err != nil {+ traceway.CaptureException(traceway.NewStackTraceErrorf("failed to register runner %q: %w", name, err))+ if cached {+ return entry.runner+ }+ return &models.SyntheticRunner{Name: name, Version: version, FirstSeenAt: now, LastSeenAt: now}+ }+ runnerCacheMu.Lock()+ runnerCache[name] = &runnerCacheEntry{runner: runner, touchedAt: now}+ runnerCacheMu.Unlock()+ return runner+}++// GetRunner returns the authenticated runner set by UseRunnerAuth.+func GetRunner(c *gin.Context) (*models.SyntheticRunner, bool) {+ value, exists := c.Get(RunnerContextKey)+ if !exists {+ return nil, false+ }+ runner, ok := value.(*models.SyntheticRunner)+ return runner, ok+}diff --git a/backend/app/migrations/ch/0082_create_check_results.up.sql b/backend/app/migrations/ch/0082_create_check_results.up.sqlnew file mode 100644index 00000000..6b40f7c3--- /dev/null+++ b/backend/app/migrations/ch/0082_create_check_results.up.sql@@ -0,0 +1,17 @@+CREATE TABLE IF NOT EXISTS check_results (+ project_id UUID,+ check_id Int64,+ run_id Int64,+ check_type String,+ recorded_at DateTime64(3),+ executed_at DateTime64(3),+ status String,+ latency_ms Float64,+ status_code Int32 DEFAULT 0,+ error_message String DEFAULT '',+ executed_by String DEFAULT '',+ screenshot_key String DEFAULT '',+ tls_days_remaining Int32 DEFAULT -1+) ENGINE = MergeTree()+PARTITION BY toYYYYMM(recorded_at)+ORDER BY (project_id, check_id, recorded_at)diff --git a/backend/app/migrations/ch/0083_add_ttl_check_results.up.sql b/backend/app/migrations/ch/0083_add_ttl_check_results.up.sqlnew file mode 100644index 00000000..f707a148--- /dev/null+++ b/backend/app/migrations/ch/0083_add_ttl_check_results.up.sql@@ -0,0 +1 @@+ALTER TABLE check_results MODIFY TTL toDateTime(recorded_at) + INTERVAL 90 DAYdiff --git a/backend/app/migrations/ch/0084_add_output_key_to_check_results.up.sql b/backend/app/migrations/ch/0084_add_output_key_to_check_results.up.sqlnew file mode 100644index 00000000..5e1c8d6f--- /dev/null+++ b/backend/app/migrations/ch/0084_add_output_key_to_check_results.up.sql@@ -0,0 +1 @@+ALTER TABLE check_results ADD COLUMN output_key String DEFAULT ''diff --git a/backend/app/migrations/duckdb_telemetry/0003_create_check_results.up.sql b/backend/app/migrations/duckdb_telemetry/0003_create_check_results.up.sqlnew file mode 100644index 00000000..7c1bcb6f--- /dev/null+++ b/backend/app/migrations/duckdb_telemetry/0003_create_check_results.up.sql@@ -0,0 +1,15 @@+CREATE TABLE IF NOT EXISTS check_results (+ project_id VARCHAR NOT NULL,+ check_id BIGINT NOT NULL DEFAULT 0,+ run_id BIGINT NOT NULL DEFAULT 0,+ check_type VARCHAR NOT NULL DEFAULT '',+ recorded_at TIMESTAMP NOT NULL,+ executed_at TIMESTAMP NOT NULL,+ status VARCHAR NOT NULL DEFAULT '',+ latency_ms DOUBLE NOT NULL DEFAULT 0,+ status_code BIGINT NOT NULL DEFAULT 0,+ error_message VARCHAR NOT NULL DEFAULT '',+ executed_by VARCHAR NOT NULL DEFAULT '',+ screenshot_key VARCHAR NOT NULL DEFAULT '',+ tls_days_remaining BIGINT NOT NULL DEFAULT -1+);diff --git a/backend/app/migrations/duckdb_telemetry/0004_add_output_key_to_check_results.up.sql b/backend/app/migrations/duckdb_telemetry/0004_add_output_key_to_check_results.up.sqlnew file mode 100644index 00000000..2b291eec--- /dev/null+++ b/backend/app/migrations/duckdb_telemetry/0004_add_output_key_to_check_results.up.sql@@ -0,0 +1 @@+ALTER TABLE check_results ADD COLUMN output_key VARCHAR NOT NULL DEFAULT '';diff --git a/backend/app/migrations/pg/0103_create_synthetic_checks.up.sql b/backend/app/migrations/pg/0103_create_synthetic_checks.up.sqlnew file mode 100644index 00000000..580515b4--- /dev/null+++ b/backend/app/migrations/pg/0103_create_synthetic_checks.up.sql@@ -0,0 +1,18 @@+CREATE TABLE IF NOT EXISTS synthetic_checks (+ id SERIAL PRIMARY KEY,+ project_id UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE,+ name VARCHAR(200) NOT NULL,+ check_type VARCHAR(20) NOT NULL,+ enabled BOOLEAN NOT NULL DEFAULT TRUE,+ interval_seconds INT NOT NULL DEFAULT 60,+ timeout_seconds INT NOT NULL DEFAULT 30,+ config JSONB NOT NULL DEFAULT '{}',+ failure_threshold INT NOT NULL DEFAULT 2,+ current_status VARCHAR(10) NOT NULL DEFAULT 'unknown',+ consecutive_failures INT NOT NULL DEFAULT 0,+ last_run_at TIMESTAMPTZ,+ last_state_change_at TIMESTAMPTZ,+ next_run_at TIMESTAMPTZ NOT NULL,+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()+)diff --git a/backend/app/migrations/pg/0104_create_synthetic_checks_due_idx.up.sql b/backend/app/migrations/pg/0104_create_synthetic_checks_due_idx.up.sqlnew file mode 100644index 00000000..84e7c696--- /dev/null+++ b/backend/app/migrations/pg/0104_create_synthetic_checks_due_idx.up.sql@@ -0,0 +1 @@+CREATE INDEX IF NOT EXISTS synthetic_checks_due_idx ON synthetic_checks (enabled, next_run_at)diff --git a/backend/app/migrations/pg/0105_create_synthetic_checks_project_idx.up.sql b/backend/app/migrations/pg/0105_create_synthetic_checks_project_idx.up.sqlnew file mode 100644index 00000000..a120de04--- /dev/null+++ b/backend/app/migrations/pg/0105_create_synthetic_checks_project_idx.up.sql@@ -0,0 +1 @@+CREATE INDEX IF NOT EXISTS synthetic_checks_project_idx ON synthetic_checks (project_id)diff --git a/backend/app/migrations/pg/0106_create_check_runs.up.sql b/backend/app/migrations/pg/0106_create_check_runs.up.sqlnew file mode 100644index 00000000..a413ab11--- /dev/null+++ b/backend/app/migrations/pg/0106_create_check_runs.up.sql@@ -0,0 +1,12 @@+CREATE TABLE IF NOT EXISTS check_runs (+ id SERIAL PRIMARY KEY,+ check_id INT NOT NULL REFERENCES synthetic_checks(id) ON DELETE CASCADE,+ project_id UUID NOT NULL,+ check_type VARCHAR(20) NOT NULL,+ status VARCHAR(10) NOT NULL DEFAULT 'queued',+ scheduled_for TIMESTAMPTZ NOT NULL,+ expires_at TIMESTAMPTZ NOT NULL,+ claimed_at TIMESTAMPTZ,+ claimed_by VARCHAR(100) NOT NULL DEFAULT '',+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()+)diff --git a/backend/app/migrations/pg/0107_create_check_runs_due_idx.up.sql b/backend/app/migrations/pg/0107_create_check_runs_due_idx.up.sqlnew file mode 100644index 00000000..4f040cd9--- /dev/null+++ b/backend/app/migrations/pg/0107_create_check_runs_due_idx.up.sql@@ -0,0 +1 @@+CREATE INDEX IF NOT EXISTS check_runs_due_idx ON check_runs (status, scheduled_for)diff --git a/backend/app/migrations/pg/0108_create_check_runs_check_idx.up.sql b/backend/app/migrations/pg/0108_create_check_runs_check_idx.up.sqlnew file mode 100644index 00000000..828e2ecc--- /dev/null+++ b/backend/app/migrations/pg/0108_create_check_runs_check_idx.up.sql@@ -0,0 +1 @@+CREATE INDEX IF NOT EXISTS check_runs_check_idx ON check_runs (check_id)diff --git a/backend/app/migrations/pg/0109_create_check_incidents.up.sql b/backend/app/migrations/pg/0109_create_check_incidents.up.sqlnew file mode 100644index 00000000..a47d42ed--- /dev/null+++ b/backend/app/migrations/pg/0109_create_check_incidents.up.sql@@ -0,0 +1,8 @@+CREATE TABLE IF NOT EXISTS check_incidents (+ id SERIAL PRIMARY KEY,+ check_id INT NOT NULL REFERENCES synthetic_checks(id) ON DELETE CASCADE,+ project_id UUID NOT NULL,+ started_at TIMESTAMPTZ NOT NULL,+ resolved_at TIMESTAMPTZ,+ error_message TEXT NOT NULL DEFAULT ''+)diff --git a/backend/app/migrations/pg/0110_create_check_incidents_check_idx.up.sql b/backend/app/migrations/pg/0110_create_check_incidents_check_idx.up.sqlnew file mode 100644index 00000000..e50d915b--- /dev/null+++ b/backend/app/migrations/pg/0110_create_check_incidents_check_idx.up.sql@@ -0,0 +1 @@+CREATE INDEX IF NOT EXISTS check_incidents_check_idx ON check_incidents (check_id, started_at)diff --git a/backend/app/migrations/pg/0111_create_synthetic_runners.up.sql b/backend/app/migrations/pg/0111_create_synthetic_runners.up.sqlnew file mode 100644index 00000000..e22931e0--- /dev/null+++ b/backend/app/migrations/pg/0111_create_synthetic_runners.up.sql@@ -0,0 +1,10 @@+CREATE TABLE IF NOT EXISTS synthetic_runners (+ id SERIAL PRIMARY KEY,+ organization_id INT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,+ name VARCHAR(200) NOT NULL,+ token_hash VARCHAR(64) NOT NULL UNIQUE,+ last_seen_at TIMESTAMPTZ,+ version VARCHAR(50) NOT NULL DEFAULT '',+ revoked_at TIMESTAMPTZ,+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()+)diff --git a/backend/app/migrations/pg/0112_create_status_pages.up.sql b/backend/app/migrations/pg/0112_create_status_pages.up.sqlnew file mode 100644index 00000000..004bc7ea--- /dev/null+++ b/backend/app/migrations/pg/0112_create_status_pages.up.sql@@ -0,0 +1,10 @@+CREATE TABLE IF NOT EXISTS status_pages (+ id SERIAL PRIMARY KEY,+ organization_id INT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,+ slug VARCHAR(60) NOT NULL UNIQUE,+ name VARCHAR(200) NOT NULL,+ is_public BOOLEAN NOT NULL DEFAULT FALSE,+ check_ids JSONB NOT NULL DEFAULT '[]',+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()+)diff --git a/backend/app/migrations/pg/0113_add_description_to_status_pages.up.sql b/backend/app/migrations/pg/0113_add_description_to_status_pages.up.sqlnew file mode 100644index 00000000..ba4f45db--- /dev/null+++ b/backend/app/migrations/pg/0113_add_description_to_status_pages.up.sql@@ -0,0 +1 @@+ALTER TABLE status_pages ADD COLUMN IF NOT EXISTS description TEXT NOT NULL DEFAULT ''diff --git a/backend/app/migrations/pg/0114_add_logo_key_to_status_pages.up.sql b/backend/app/migrations/pg/0114_add_logo_key_to_status_pages.up.sqlnew file mode 100644index 00000000..03ab6f30--- /dev/null+++ b/backend/app/migrations/pg/0114_add_logo_key_to_status_pages.up.sql@@ -0,0 +1 @@+ALTER TABLE status_pages ADD COLUMN IF NOT EXISTS logo_key VARCHAR(300) NOT NULL DEFAULT ''diff --git a/backend/app/migrations/pg/0115_add_custom_domain_to_status_pages.up.sql b/backend/app/migrations/pg/0115_add_custom_domain_to_status_pages.up.sqlnew file mode 100644index 00000000..dce8f4b6--- /dev/null+++ b/backend/app/migrations/pg/0115_add_custom_domain_to_status_pages.up.sql@@ -0,0 +1 @@+ALTER TABLE status_pages ADD COLUMN IF NOT EXISTS custom_domain VARCHAR(255) NOT NULL DEFAULT ''diff --git a/backend/app/migrations/pg/0116_create_status_pages_custom_domain_unique.up.sql b/backend/app/migrations/pg/0116_create_status_pages_custom_domain_unique.up.sqlnew file mode 100644index 00000000..deacd128--- /dev/null+++ b/backend/app/migrations/pg/0116_create_status_pages_custom_domain_unique.up.sql@@ -0,0 +1 @@+CREATE UNIQUE INDEX IF NOT EXISTS status_pages_custom_domain_unique ON status_pages (custom_domain) WHERE custom_domain <> ''diff --git a/backend/app/migrations/pg/0117_drop_synthetic_runners.up.sql b/backend/app/migrations/pg/0117_drop_synthetic_runners.up.sqlnew file mode 100644index 00000000..c798e7ea--- /dev/null+++ b/backend/app/migrations/pg/0117_drop_synthetic_runners.up.sql@@ -0,0 +1 @@+DROP TABLE synthetic_runnersdiff --git a/backend/app/migrations/pg/0118_recreate_synthetic_runners.up.sql b/backend/app/migrations/pg/0118_recreate_synthetic_runners.up.sqlnew file mode 100644index 00000000..9524aaf7--- /dev/null+++ b/backend/app/migrations/pg/0118_recreate_synthetic_runners.up.sql@@ -0,0 +1,7 @@+CREATE TABLE synthetic_runners (+ id SERIAL PRIMARY KEY,+ name VARCHAR(200) NOT NULL UNIQUE,+ version VARCHAR(50) NOT NULL DEFAULT '',+ first_seen_at TIMESTAMPTZ NOT NULL,+ last_seen_at TIMESTAMPTZ NOT NULL+)diff --git a/backend/app/migrations/sqlite/0064_create_synthetics.up.sql b/backend/app/migrations/sqlite/0064_create_synthetics.up.sqlnew file mode 100644index 00000000..150bb34d--- /dev/null+++ b/backend/app/migrations/sqlite/0064_create_synthetics.up.sql@@ -0,0 +1,72 @@+CREATE TABLE IF NOT EXISTS synthetic_checks (+ id INTEGER PRIMARY KEY AUTOINCREMENT,+ project_id TEXT NOT NULL REFERENCES projects(id) ON DELETE CASCADE,+ name TEXT NOT NULL,+ check_type TEXT NOT NULL,+ enabled INTEGER NOT NULL DEFAULT 1,+ interval_seconds INTEGER NOT NULL DEFAULT 60,+ timeout_seconds INTEGER NOT NULL DEFAULT 30,+ config TEXT NOT NULL DEFAULT '{}',+ failure_threshold INTEGER NOT NULL DEFAULT 2,+ current_status TEXT NOT NULL DEFAULT 'unknown',+ consecutive_failures INTEGER NOT NULL DEFAULT 0,+ last_run_at DATETIME,+ last_state_change_at DATETIME,+ next_run_at DATETIME NOT NULL,+ created_at DATETIME NOT NULL,+ updated_at DATETIME NOT NULL+);++CREATE INDEX IF NOT EXISTS synthetic_checks_due_idx ON synthetic_checks (enabled, next_run_at);++CREATE INDEX IF NOT EXISTS synthetic_checks_project_idx ON synthetic_checks (project_id);++CREATE TABLE IF NOT EXISTS check_runs (+ id INTEGER PRIMARY KEY AUTOINCREMENT,+ check_id INTEGER NOT NULL REFERENCES synthetic_checks(id) ON DELETE CASCADE,+ project_id TEXT NOT NULL,+ check_type TEXT NOT NULL,+ status TEXT NOT NULL DEFAULT 'queued',+ scheduled_for DATETIME NOT NULL,+ expires_at DATETIME NOT NULL,+ claimed_at DATETIME,+ claimed_by TEXT NOT NULL DEFAULT '',+ created_at DATETIME NOT NULL+);++CREATE INDEX IF NOT EXISTS check_runs_due_idx ON check_runs (status, scheduled_for);++CREATE INDEX IF NOT EXISTS check_runs_check_idx ON check_runs (check_id);++CREATE TABLE IF NOT EXISTS check_incidents (+ id INTEGER PRIMARY KEY AUTOINCREMENT,+ check_id INTEGER NOT NULL REFERENCES synthetic_checks(id) ON DELETE CASCADE,+ project_id TEXT NOT NULL,+ started_at DATETIME NOT NULL,+ resolved_at DATETIME,+ error_message TEXT NOT NULL DEFAULT ''+);++CREATE INDEX IF NOT EXISTS check_incidents_check_idx ON check_incidents (check_id, started_at);++CREATE TABLE IF NOT EXISTS synthetic_runners (+ id INTEGER PRIMARY KEY AUTOINCREMENT,+ organization_id INTEGER NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,+ name TEXT NOT NULL,+ token_hash TEXT NOT NULL UNIQUE,+ last_seen_at DATETIME,+ version TEXT NOT NULL DEFAULT '',+ revoked_at DATETIME,+ created_at DATETIME NOT NULL+);++CREATE TABLE IF NOT EXISTS status_pages (+ id INTEGER PRIMARY KEY AUTOINCREMENT,+ organization_id INTEGER NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,+ slug TEXT NOT NULL UNIQUE,+ name TEXT NOT NULL,+ is_public INTEGER NOT NULL DEFAULT 0,+ check_ids TEXT NOT NULL DEFAULT '[]',+ created_at DATETIME NOT NULL,+ updated_at DATETIME NOT NULL+);diff --git a/backend/app/migrations/sqlite/0065_add_status_page_branding.up.sql b/backend/app/migrations/sqlite/0065_add_status_page_branding.up.sqlnew file mode 100644index 00000000..4c4ce514--- /dev/null+++ b/backend/app/migrations/sqlite/0065_add_status_page_branding.up.sql@@ -0,0 +1,7 @@+ALTER TABLE status_pages ADD COLUMN description TEXT NOT NULL DEFAULT '';++ALTER TABLE status_pages ADD COLUMN logo_key TEXT NOT NULL DEFAULT '';++ALTER TABLE status_pages ADD COLUMN custom_domain TEXT NOT NULL DEFAULT '';++CREATE UNIQUE INDEX IF NOT EXISTS status_pages_custom_domain_unique ON status_pages (custom_domain) WHERE custom_domain <> '';diff --git a/backend/app/migrations/sqlite/0066_recreate_synthetic_runners.up.sql b/backend/app/migrations/sqlite/0066_recreate_synthetic_runners.up.sqlnew file mode 100644index 00000000..584f5d70--- /dev/null+++ b/backend/app/migrations/sqlite/0066_recreate_synthetic_runners.up.sql@@ -0,0 +1,9 @@+DROP TABLE synthetic_runners;++CREATE TABLE synthetic_runners (+ id INTEGER PRIMARY KEY AUTOINCREMENT,+ name TEXT NOT NULL UNIQUE,+ version TEXT NOT NULL DEFAULT '',+ first_seen_at TEXT NOT NULL,+ last_seen_at TEXT NOT NULL+);diff --git a/backend/app/migrations/sqlite_telemetry/0018_create_check_results.up.sql b/backend/app/migrations/sqlite_telemetry/0018_create_check_results.up.sqlnew file mode 100644index 00000000..8b56227d--- /dev/null+++ b/backend/app/migrations/sqlite_telemetry/0018_create_check_results.up.sql@@ -0,0 +1,17 @@+CREATE TABLE IF NOT EXISTS check_results (+ project_id TEXT NOT NULL,+ check_id INTEGER NOT NULL DEFAULT 0,+ run_id INTEGER NOT NULL DEFAULT 0,+ check_type TEXT NOT NULL DEFAULT '',+ recorded_at DATETIME NOT NULL,+ executed_at DATETIME NOT NULL,+ status TEXT NOT NULL DEFAULT '',+ latency_ms REAL NOT NULL DEFAULT 0,+ status_code INTEGER NOT NULL DEFAULT 0,+ error_message TEXT NOT NULL DEFAULT '',+ executed_by TEXT NOT NULL DEFAULT '',+ screenshot_key TEXT NOT NULL DEFAULT '',+ tls_days_remaining INTEGER NOT NULL DEFAULT -1+);++CREATE INDEX IF NOT EXISTS idx_check_results_check_recorded ON check_results(project_id, check_id, recorded_at);diff --git a/backend/app/migrations/sqlite_telemetry/0019_add_output_key_to_check_results.up.sql b/backend/app/migrations/sqlite_telemetry/0019_add_output_key_to_check_results.up.sqlnew file mode 100644index 00000000..7ebe13b6--- /dev/null+++ b/backend/app/migrations/sqlite_telemetry/0019_add_output_key_to_check_results.up.sql@@ -0,0 +1 @@+ALTER TABLE check_results ADD COLUMN output_key TEXT NOT NULL DEFAULT '';diff --git a/backend/app/models/models.go b/backend/app/models/models.goindex 50a9e216..950eda69 100644--- a/backend/app/models/models.go+++ b/backend/app/models/models.go@@ -70,6 +70,12 @@ func Init(driver lit.Driver) {lit.RegisterModelWithNaming[OutboxDelivery](driver, notificationOutboxNaming{})lit.RegisterModel[OutboxRuleEnqueue](driver)lit.RegisterModel[OutboxHealthCounts](driver)+ lit.RegisterModel[SyntheticCheck](driver)+ lit.RegisterModel[CheckRun](driver)+ lit.RegisterModel[CheckRunHealthCounts](driver)+ lit.RegisterModel[CheckIncident](driver)+ lit.RegisterModel[SyntheticRunner](driver)+ lit.RegisterModel[StatusPage](driver)for _, register := range ExtensionModelRegistrations {register(driver)diff --git a/backend/app/models/synthetics.model.go b/backend/app/models/synthetics.model.gonew file mode 100644index 00000000..853f9c6b--- /dev/null+++ b/backend/app/models/synthetics.model.go@@ -0,0 +1,180 @@+package models++import (+ "time"++ "github.com/google/uuid"+)++const (+ CheckTypeHttp = "http"+ CheckTypeTcp = "tcp"+ CheckTypeBrowser = "browser"++ CheckStatusUp = "up"+ CheckStatusDown = "down"+ CheckStatusUnknown = "unknown"++ CheckRunQueued = "queued"+ CheckRunClaimed = "claimed"++ CheckResultUp = "up"+ CheckResultDown = "down"+ CheckResultMissed = "missed"+)++type SyntheticCheck struct {+ Id int `json:"id" lit:"id"`+ ProjectId uuid.UUID `json:"projectId" lit:"project_id"`+ Name string `json:"name" lit:"name"`+ CheckType string `json:"checkType" lit:"check_type"`+ Enabled bool `json:"enabled" lit:"enabled"`+ IntervalSeconds int `json:"intervalSeconds" lit:"interval_seconds"`+ TimeoutSeconds int `json:"timeoutSeconds" lit:"timeout_seconds"`+ Config JSONText `json:"config" lit:"config"`+ FailureThreshold int `json:"failureThreshold" lit:"failure_threshold"`+ CurrentStatus string `json:"currentStatus" lit:"current_status"`+ ConsecutiveFailures int `json:"consecutiveFailures" lit:"consecutive_failures"`+ LastRunAt *time.Time `json:"lastRunAt" lit:"last_run_at"`+ LastStateChangeAt *time.Time `json:"lastStateChangeAt" lit:"last_state_change_at"`+ NextRunAt time.Time `json:"nextRunAt" lit:"next_run_at"`+ CreatedAt time.Time `json:"createdAt" lit:"created_at"`+ UpdatedAt time.Time `json:"updatedAt" lit:"updated_at"`+}++type CheckRun struct {+ Id int `json:"id" lit:"id"`+ CheckId int `json:"checkId" lit:"check_id"`+ ProjectId uuid.UUID `json:"projectId" lit:"project_id"`+ CheckType string `json:"checkType" lit:"check_type"`+ Status string `json:"status" lit:"status"`+ ScheduledFor time.Time `json:"scheduledFor" lit:"scheduled_for"`+ ExpiresAt time.Time `json:"expiresAt" lit:"expires_at"`+ ClaimedAt *time.Time `json:"claimedAt" lit:"claimed_at"`+ ClaimedBy string `json:"claimedBy" lit:"claimed_by"`+ CreatedAt time.Time `json:"createdAt" lit:"created_at"`+}++type CheckIncident struct {+ Id int `json:"id" lit:"id"`+ CheckId int `json:"checkId" lit:"check_id"`+ ProjectId uuid.UUID `json:"projectId" lit:"project_id"`+ StartedAt time.Time `json:"startedAt" lit:"started_at"`+ ResolvedAt *time.Time `json:"resolvedAt" lit:"resolved_at"`+ ErrorMessage string `json:"errorMessage" lit:"error_message"`+}++// SyntheticRunner is a liveness record for a self-registered browser-run+// executor. Runners are operator infrastructure: they authenticate with the+// shared SYNTHETICS_RUNNER_SECRET and register themselves by name on first+// poll, so rows carry no credentials and no tenant scoping.+type SyntheticRunner struct {+ Id int `json:"id" lit:"id"`+ Name string `json:"name" lit:"name"`+ Version string `json:"version" lit:"version"`+ FirstSeenAt time.Time `json:"firstSeenAt" lit:"first_seen_at"`+ LastSeenAt time.Time `json:"lastSeenAt" lit:"last_seen_at"`+}++type StatusPage struct {+ Id int `json:"id" lit:"id"`+ OrganizationId int `json:"organizationId" lit:"organization_id"`+ Slug string `json:"slug" lit:"slug"`+ Name string `json:"name" lit:"name"`+ IsPublic bool `json:"isPublic" lit:"is_public"`+ CheckIds JSONText `json:"checkIds" lit:"check_ids"`+ Description string `json:"description" lit:"description"`+ LogoKey string `json:"logoKey" lit:"logo_key"`+ CustomDomain string `json:"customDomain" lit:"custom_domain"`+ CreatedAt time.Time `json:"createdAt" lit:"created_at"`+ UpdatedAt time.Time `json:"updatedAt" lit:"updated_at"`+}++// Config document shapes stored in synthetic_checks.config, one per check+// type. Auth secrets live inside the main DB like notification channel+// configs, and like channel configs they are returned to any project member+// with read access; readonly gating restricts writes, not reads.++type HttpCheckConfig struct {+ URL string `json:"url"`+ Method string `json:"method"`+ Headers map[string]string `json:"headers"`+ Auth HttpCheckAuth `json:"auth"`+ Body string `json:"body"`+ BodyContentType string `json:"bodyContentType"`+ FollowRedirects bool `json:"followRedirects"`+ SkipTlsVerify bool `json:"skipTlsVerify"`+ Assertions HttpAssertions `json:"assertions"`+}++type HttpCheckAuth struct {+ Type string `json:"type"`+ Username string `json:"username"`+ Password string `json:"password"`+ Token string `json:"token"`+ HeaderName string `json:"headerName"`+ HeaderValue string `json:"headerValue"`+}++type HttpAssertions struct {+ StatusCodes []int `json:"statusCodes"`+ BodyContains string `json:"bodyContains"`+ BodyRegex string `json:"bodyRegex"`+ MaxResponseTimeMs int `json:"maxResponseTimeMs"`+ TlsMinDaysRemaining int `json:"tlsMinDaysRemaining"`+}++type TcpCheckConfig struct {+ Host string `json:"host"`+ Port int `json:"port"`+ UseTls bool `json:"useTls"`+ SendPayload string `json:"sendPayload"`+ ExpectContains string `json:"expectContains"`+ TlsMinDaysRemaining int `json:"tlsMinDaysRemaining"`+}++type BrowserCheckConfig struct {+ Script string `json:"script"`+ Env map[string]string `json:"env"`+}++type CheckRunHealthCounts struct {+ QueuedCount int `lit:"queued_count"`+ ClaimedCount int `lit:"claimed_count"`+}++// CheckAggregates summarizes a check's results over a time range. Latency+// aggregates exclude missed rows (they carry no measurement).+type CheckAggregates struct {+ Total int64 `json:"total"`+ Up int64 `json:"up"`+ Down int64 `json:"down"`+ Missed int64 `json:"missed"`+ AvgLatencyMs float64 `json:"avgLatencyMs"`+}++// CheckSeriesPoint is one time bucket of a check's results.+type CheckSeriesPoint struct {+ Bucket time.Time `json:"bucket"`+ Total int64 `json:"total"`+ Up int64 `json:"up"`+ Missed int64 `json:"missed"`+ AvgLatencyMs float64 `json:"avgLatencyMs"`+ MaxLatencyMs float64 `json:"maxLatencyMs"`+}++// CheckResultEntry is the JSON shape of one telemetry check_results row.+type CheckResultEntry struct {+ RunId int `json:"runId"`+ CheckType string `json:"checkType"`+ RecordedAt time.Time `json:"recordedAt"`+ ExecutedAt time.Time `json:"executedAt"`+ Status string `json:"status"`+ LatencyMs float64 `json:"latencyMs"`+ StatusCode int `json:"statusCode"`+ ErrorMessage string `json:"errorMessage"`+ ExecutedBy string `json:"executedBy"`+ ScreenshotKey string `json:"screenshotKey"`+ OutputKey string `json:"outputKey"`+ TlsDaysRemaining int `json:"tlsDaysRemaining"`+}diff --git a/backend/app/monitoring/synthetics_reporter.go b/backend/app/monitoring/synthetics_reporter.gonew file mode 100644index 00000000..bfcbaf28--- /dev/null+++ b/backend/app/monitoring/synthetics_reporter.go@@ -0,0 +1,60 @@+package monitoring++import (+ "context"+ "fmt"+ "time"++ traceway "go.tracewayapp.com"++ "github.com/tracewayapp/traceway/backend/app/synthetics"+)++const syntheticsReportInterval = 10 * time.Second++type syntheticsBaselines struct {+ executed uint64+ missed uint64+ first bool+}++func StartSyntheticsReporter(ctx context.Context) {+ go func() {+ defer traceway.Recover()++ ticker := time.NewTicker(syntheticsReportInterval)+ defer ticker.Stop()++ baselines := &syntheticsBaselines{first: true}+ reportSyntheticsOnce(baselines)++ for {+ select {+ case <-ctx.Done():+ return+ case <-ticker.C:+ reportSyntheticsOnce(baselines)+ }+ }+ }()+}++func reportSyntheticsOnce(baselines *syntheticsBaselines) {+ stats, err := synthetics.HealthSnapshot()+ if err != nil {+ traceway.CaptureException(fmt.Errorf("failed to snapshot synthetics health for metrics: %w", err))+ return+ }+ traceway.CaptureMetric("traceway.synthetics.queued", float64(stats.QueuedRuns))+ traceway.CaptureMetric("traceway.synthetics.claimed", float64(stats.ClaimedRuns))+ traceway.CaptureMetric("traceway.synthetics.oldest_queued_sec", float64(stats.OldestQueuedAgeSec))+ traceway.CaptureMetric("traceway.synthetics.checks_down", float64(stats.ChecksDown))+ traceway.CaptureMetric("traceway.synthetics.runners_online", float64(stats.RunnersOnline))+ if !baselines.first {+ traceway.CaptureMetric("traceway.synthetics.executed.delta", float64(stats.ExecutedTotal-baselines.executed))+ traceway.CaptureMetric("traceway.synthetics.missed.delta", float64(stats.MissedTotal-baselines.missed))+ }+ baselines.executed = stats.ExecutedTotal+ baselines.missed = stats.MissedTotal+ baselines.first = false+}diff --git a/backend/app/netguard/netguard.go b/backend/app/netguard/netguard.gonew file mode 100644index 00000000..f362f410--- /dev/null+++ b/backend/app/netguard/netguard.go@@ -0,0 +1,89 @@+// Package netguard holds the shared private-address egress guard used by+// notification adapters and synthetic checks. Validation happens both at+// save time (friendly errors) and at dial time (DNS-rebinding safe).+package netguard++import (+ "context"+ "errors"+ "fmt"+ "net"+ "net/url"+ "strings"+ "time"+)++// ValidateURL rejects an http(s) destination that resolves to the server's+// own network. Callers decide whether the guard applies (allowPrivate=true+// short-circuits).+func ValidateURL(raw string, allowPrivate bool) error {+ if allowPrivate {+ return nil+ }+ parsed, err := url.Parse(strings.TrimSpace(raw))+ if err != nil {+ return errors.New("The URL is not valid.")+ }+ if parsed.Scheme != "http" && parsed.Scheme != "https" {+ return errors.New("The URL must start with http:// or https://.")+ }+ host := parsed.Hostname()+ if host == "" {+ return errors.New("The URL is missing a host.")+ }+ return ValidateHost(host)+}++// ValidateHost resolves a hostname and rejects it when any address is+// private/loopback/link-local/CGNAT.+func ValidateHost(host string) error {+ ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)+ defer cancel()+ addrs, err := net.DefaultResolver.LookupIPAddr(ctx, host)+ if err != nil || len(addrs) == 0 {+ return fmt.Errorf("The host %q could not be resolved.", host)+ }+ for _, addr := range addrs {+ if IsPrivateIP(addr.IP) {+ return errors.New("The URL must point at a public address.")+ }+ }+ return nil+}++// GuardedDialContext returns a DialContext that re-checks the resolved+// address at connection time, so a hostname cannot pass save-time validation+// and then be re-pointed at a private address (DNS rebinding).+func GuardedDialContext(timeout time.Duration) func(ctx context.Context, network, addr string) (net.Conn, error) {+ dialer := &net.Dialer{Timeout: timeout}+ return func(ctx context.Context, network, addr string) (net.Conn, error) {+ host, port, err := net.SplitHostPort(addr)+ if err != nil {+ return nil, err+ }+ addrs, err := net.DefaultResolver.LookupIPAddr(ctx, host)+ if err != nil || len(addrs) == 0 {+ return nil, fmt.Errorf("could not resolve %q", host)+ }+ for _, resolved := range addrs {+ if IsPrivateIP(resolved.IP) {+ return nil, fmt.Errorf("destination %q resolves to a private address", host)+ }+ }+ // Dial the vetted address directly so the connection cannot be+ // re-resolved to something else.+ return dialer.DialContext(ctx, network, net.JoinHostPort(addrs[0].IP.String(), port))+ }+}++func IsPrivateIP(ip net.IP) bool {+ if ip.IsLoopback() || ip.IsPrivate() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() ||+ ip.IsUnspecified() || ip.IsInterfaceLocalMulticast() {+ return true+ }+ // 100.64.0.0/10 (CGNAT) and 0.0.0.0/8, which net.IP does not classify.+ if v4 := ip.To4(); v4 != nil {+ return v4[0] == 0 || (v4[0] == 100 && v4[1] >= 64 && v4[1] <= 127)+ }+ return false+}diff --git a/backend/app/notifications/check_state.go b/backend/app/notifications/check_state.gonew file mode 100644index 00000000..ce55ce78--- /dev/null+++ b/backend/app/notifications/check_state.go@@ -0,0 +1,92 @@+package notifications++import (+ "database/sql"+ "fmt"+ "time"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"+ "github.com/tracewayapp/traceway/backend/app/repositories/transactional"+ "github.com/tracewayapp/traceway/backend/app/synthetics"+ traceway "go.tracewayapp.com"+)++// PageResolver auto-resolves the unresolved page a check_down rule opened,+// identified by its rule-scoped dedup token. Implemented by the oncall+// package and registered from cmd/run.go (notifications cannot import oncall).+type PageResolver func(ruleId int, dedupToken string) error++var pageResolver PageResolver++func RegisterPageResolver(resolver PageResolver) {+ pageResolver = resolver+}++// OnCheckStateChange is the synthetics notifier (synthetics.RegisterNotifier+// in cmd/run.go). It runs AFTER the state transaction committed and holds no+// transaction: dispatch opens its own, and the SQLite main DB has a single+// connection, so an ambient transaction here would deadlock.+func OnCheckStateChange(transition synthetics.StateTransition) {+ defer traceway.Recover()++ rules, err := db.ExecuteTransaction(func(tx *sql.Tx) ([]*models.NotificationRuleWithChannel, error) {+ return transactional.NotificationRuleRepository.FindEnabledEventRules(tx, transition.Check.ProjectId)+ })+ if err != nil {+ traceway.CaptureException(fmt.Errorf("failed to load event notification rules for check transition: %w", err))+ return+ }++ wentDown := transition.To == models.CheckStatusDown+ recovered := transition.From == models.CheckStatusDown && transition.To == models.CheckStatusUp+ if !wentDown && !recovered {+ return+ }++ projectName := ""+ for _, rule := range rules {+ if rule.RuleType != "check_down" {+ continue+ }+ if rule.SnoozedUntil != nil && rule.SnoozedUntil.After(time.Now()) {+ continue+ }+ if projectName == "" {+ projectName = getProjectName(transition.Check.ProjectId)+ }++ if wentDown {+ dedupKey := checkDownDedupKey(rule.Id, transition.Check.Id)+ if dedup.isDuplicate(dedupKey, time.Duration(rule.CooldownMinutes)*time.Minute) {+ continue+ }+ msg := buildCheckDownMessage(&transition.Check, transition.ErrorMsg, projectName)+ // Record before dispatch: a persistently failing dispatch retries+ // once per cooldown window, never on every transition.+ dedup.record(dedupKey)+ dispatch(rule, msg)+ continue+ }++ // Recovery. Escalation-channel rules must NOT dispatch: dispatch would+ // open a fresh "recovered" page that stays open forever. Auto-resolve+ // the down page instead.+ if rule.ChannelType == "escalation" {+ if pageResolver == nil {+ continue+ }+ if err := pageResolver(rule.Id, checkPageDedupToken(transition.Check.Id)); err != nil {+ traceway.CaptureException(fmt.Errorf("failed to auto-resolve page for recovered check %d (rule=%d): %w", transition.Check.Id, rule.Id, err))+ }+ continue+ }+ dispatch(rule, buildCheckRecoveredMessage(&transition.Check, projectName))+ }+}++// checkPageDedupToken must match the DedupToken set on check_down messages,+// so recovery can find the page the down transition opened.+func checkPageDedupToken(checkId int) string {+ return fmt.Sprintf("check:%d", checkId)+}diff --git a/backend/app/notifications/cooldown.go b/backend/app/notifications/cooldown.goindex 044fc03c..36c5731c 100644--- a/backend/app/notifications/cooldown.go+++ b/backend/app/notifications/cooldown.go@@ -53,6 +53,10 @@ func aiFlaggedContentDedupKey(ruleId int, subject string) string {return ruleStatePrefix(ruleId) + "ai_flagged:" + subject}+func checkDownDedupKey(ruleId int, checkId int) string {+ return ruleStatePrefix(ruleId) + fmt.Sprintf("check_down:%d", checkId)+}+func ClearRuleState(ruleId int) {cooldowns.mu.Lock()delete(cooldowns.fired, ruleId)diff --git a/backend/app/notifications/egress.go b/backend/app/notifications/egress.goindex 5fc7edfa..ba299b7f 100644--- a/backend/app/notifications/egress.go+++ b/backend/app/notifications/egress.go@@ -1,59 +1,15 @@package notificationsimport (- "context"- "errors"- "fmt"- "net"- "net/url"- "strings"- "time"-"github.com/tracewayapp/traceway/backend/app/config"+ "github.com/tracewayapp/traceway/backend/app/netguard")// ValidateOutboundURL rejects a destination on the server's own network, unless// ALLOW_PRIVATE_NOTIFICATION_TARGETS is set. It guards self-scoped surfaces// (personal contact methods); project webhook channels are deliberately not-// guarded.+// guarded. The shared implementation lives in netguard, which synthetic+// checks use with their own SYNTHETICS_ALLOW_PRIVATE_TARGETS switch.func ValidateOutboundURL(raw string) error {- if config.Config.AllowPrivateNotificationTargets == "true" {- return nil- }- parsed, err := url.Parse(strings.TrimSpace(raw))- if err != nil {- return errors.New("The URL is not valid.")- }- if parsed.Scheme != "http" && parsed.Scheme != "https" {- return errors.New("The URL must start with http:// or https://.")- }- host := parsed.Hostname()- if host == "" {- return errors.New("The URL is missing a host.")- }-- ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)- defer cancel()- addrs, err := net.DefaultResolver.LookupIPAddr(ctx, host)- if err != nil || len(addrs) == 0 {- return fmt.Errorf("The host %q could not be resolved.", host)- }- for _, addr := range addrs {- if isPrivateIP(addr.IP) {- return errors.New("The URL must point at a public address.")- }- }- return nil-}--func isPrivateIP(ip net.IP) bool {- if ip.IsLoopback() || ip.IsPrivate() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() ||- ip.IsUnspecified() || ip.IsInterfaceLocalMulticast() {- return true- }- // 100.64.0.0/10 (CGNAT) and 0.0.0.0/8, which net.IP does not classify.- if v4 := ip.To4(); v4 != nil {- return v4[0] == 0 || (v4[0] == 100 && v4[1] >= 64 && v4[1] <= 127)- }- return false+ return netguard.ValidateURL(raw, config.Config.AllowPrivateNotificationTargets == "true")}diff --git a/backend/app/notifications/messages.go b/backend/app/notifications/messages.goindex 7795359d..6e4513d1 100644--- a/backend/app/notifications/messages.go+++ b/backend/app/notifications/messages.go@@ -5,6 +5,8 @@ import ("sort""strings""time"++ "github.com/tracewayapp/traceway/backend/app/models")func buildErrorRateMessage(rate float64, threshold float64, window int, projectName string) Message {@@ -324,3 +326,27 @@ func buildExceptionBody(headline string, d ExceptionDetails) string {return b.String()}++func buildCheckDownMessage(check *models.SyntheticCheck, errorMsg string, projectName string) Message {+ body := fmt.Sprintf("The synthetic check %q is failing (%d consecutive failures).", check.Name, check.ConsecutiveFailures)+ if errorMsg != "" {+ body += "\n\nLast error: " + errorMsg+ }+ return Message{+ Subject: fmt.Sprintf("[%s] Check %q is down", projectName, check.Name),+ Body: body,+ Severity: SeverityCritical,+ URL: fmt.Sprintf("/monitors/%d", check.Id),+ DedupToken: fmt.Sprintf("check:%d", check.Id),+ }+}++func buildCheckRecoveredMessage(check *models.SyntheticCheck, projectName string) Message {+ return Message{+ Subject: fmt.Sprintf("[%s] Check %q recovered", projectName, check.Name),+ Body: fmt.Sprintf("The synthetic check %q is passing again.", check.Name),+ Severity: SeverityInfo,+ URL: fmt.Sprintf("/monitors/%d", check.Id),+ DedupToken: fmt.Sprintf("check:%d", check.Id),+ }+}diff --git a/backend/app/oncall/auto_resolve.go b/backend/app/oncall/auto_resolve.gonew file mode 100644index 00000000..7f231c98--- /dev/null+++ b/backend/app/oncall/auto_resolve.go@@ -0,0 +1,42 @@+package oncall++import (+ "database/sql"+ "fmt"+ "time"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/outbox"+ "github.com/tracewayapp/traceway/backend/app/repositories/transactional"+)++// AutoResolveByDedupKeyTx resolves the unresolved page holding the+// rule-scoped dedup key with no resolving user (a system resolve, e.g. a+// synthetic check recovering), cancelling its queued deliveries. Runs in the+// caller's transaction. Returns whether a page was resolved.+func AutoResolveByDedupKeyTx(tx *sql.Tx, ruleId int, dedupToken string, now time.Time) (bool, error) {+ key := pageDedupKey(fmt.Sprintf("%d", ruleId), dedupToken)+ page, err := transactional.PageRepository.FindUnresolvedByDedupKey(tx, key)+ if err != nil {+ return false, err+ }+ if page == nil {+ return false, nil+ }+ resolved, err := transactional.PageRepository.ResolveSystem(tx, page.Id, now)+ if err != nil || !resolved {+ return resolved, err+ }+ return true, outbox.CancelByKey(tx, outbox.PageCancelKey(page.Id))+}++// AutoResolveByDedupKey is the transaction-owning variant, registered as the+// notifications page resolver in cmd/run.go (that caller holds no+// transaction; nesting one would deadlock the single-connection SQLite main+// DB).+func AutoResolveByDedupKey(ruleId int, dedupToken string) error {+ _, err := db.ExecuteTransaction(func(tx *sql.Tx) (bool, error) {+ return AutoResolveByDedupKeyTx(tx, ruleId, dedupToken, time.Now().UTC())+ })+ return err+}diff --git a/backend/app/oncall/check_alert_test.go b/backend/app/oncall/check_alert_test.gonew file mode 100644index 00000000..6bd0281e--- /dev/null+++ b/backend/app/oncall/check_alert_test.go@@ -0,0 +1,102 @@+//go:build !transactional_pg && !telemetry_ch && !telemetry_duckdb++package oncall++import (+ "database/sql"+ "fmt"+ "testing"+ "time"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"+ "github.com/tracewayapp/traceway/backend/app/notifications"+ "github.com/tracewayapp/traceway/backend/app/repositories/transactional"+ "github.com/tracewayapp/traceway/backend/app/synthetics"+)++// TestCheckDownOpensPageAndRecoveryAutoResolves exercises the full synthetic+// check alerting loop through an escalation channel: down opens a page,+// recovery resolves it with no resolving user.+func TestCheckDownOpensPageAndRecoveryAutoResolves(t *testing.T) {+ fixture := setupEscalatorDB(t)+ notifications.RegisterPageOpener(OpenPageFromDispatch)+ notifications.RegisterPageResolver(AutoResolveByDedupKey)++ policyId := createPolicy(t, fixture.OrgId, `{"schemaVersion":1,"steps":[{"targets":[{"type":"user","id":`+fmt.Sprintf("%d", fixture.Alice)+`}],"delayMinutes":5}]}`)++ ruleId, err := db.ExecuteTransaction(func(tx *sql.Tx) (int, error) {+ now := time.Now().UTC()+ channel := &models.NotificationChannel{+ ProjectId: fixture.ProjectId,+ Name: "Escalation",+ ChannelType: "escalation",+ Config: []byte(fmt.Sprintf(`{"policyId":%d}`, policyId)),+ Enabled: true,+ CreatedAt: now,+ UpdatedAt: now,+ }+ channelId, err := transactional.NotificationChannelRepository.Create(tx, channel)+ if err != nil {+ return 0, err+ }+ return transactional.NotificationRuleRepository.Create(tx, &models.NotificationRule{+ ProjectId: fixture.ProjectId,+ ChannelId: channelId,+ Name: "Checks down",+ RuleType: "check_down",+ Config: []byte(`{}`),+ Enabled: true,+ CreatedAt: now,+ UpdatedAt: now,+ })+ })+ if err != nil {+ t.Fatalf("seed rule: %v", err)+ }++ check := models.SyntheticCheck{+ Id: 7,+ ProjectId: fixture.ProjectId,+ Name: "API health",+ CheckType: models.CheckTypeHttp,+ ConsecutiveFailures: 2,+ }++ // Down transition opens a page under the rule-scoped dedup key.+ notifications.OnCheckStateChange(synthetics.StateTransition{+ Check: check,+ From: models.CheckStatusUp,+ To: models.CheckStatusDown,+ ErrorMsg: "status code 503",+ At: time.Now().UTC(),+ })++ dedupKey := fmt.Sprintf("%d|check:%d", ruleId, check.Id)+ page := findPageByDedupKey(t, dedupKey)+ if page == nil {+ t.Fatal("expected the down transition to open a page")+ }+ if page.Status != models.PageStatusOpen || page.RuleType != "check_down" {+ t.Fatalf("unexpected page %+v", page)+ }++ // Recovery must resolve the page (system resolve), never open another.+ notifications.OnCheckStateChange(synthetics.StateTransition{+ Check: check,+ From: models.CheckStatusDown,+ To: models.CheckStatusUp,+ At: time.Now().UTC(),+ })++ if open := findPageByDedupKey(t, dedupKey); open != nil {+ t.Fatalf("expected the page resolved after recovery, still open: %+v", open)+ }+ resolved := reloadPage(t, page.Id)+ if resolved.Status != models.PageStatusResolved {+ t.Fatalf("page status = %s, want resolved", resolved.Status)+ }+ if resolved.ResolvedBy != nil {+ t.Fatalf("system resolve must leave resolved_by NULL, got %v", *resolved.ResolvedBy)+ }+}diff --git a/backend/app/repositories/telemetry/clickhouse/check_result.repository.go b/backend/app/repositories/telemetry/clickhouse/check_result.repository.gonew file mode 100644index 00000000..9bdf5cc3--- /dev/null+++ b/backend/app/repositories/telemetry/clickhouse/check_result.repository.go@@ -0,0 +1,169 @@+//go:build telemetry_ch++package clickhouse++import (+ "context"+ "time"++ "github.com/tracewayapp/traceway/backend/app/repositories/telemetry/shared"++ "github.com/google/uuid"+ "github.com/tracewayapp/traceway/backend/app/chdb"+ "github.com/tracewayapp/traceway/backend/app/models"+)++type checkResultRepository struct{}++func (r *checkResultRepository) Insert(ctx context.Context, result shared.CheckResult) error {+ batch, err := chdb.Conn.PrepareBatch(+ chdb.BatchCtx(),+ "INSERT INTO check_results (project_id, check_id, run_id, check_type, recorded_at, executed_at, status, latency_ms, status_code, error_message, executed_by, screenshot_key, output_key, tls_days_remaining)",+ )+ if err != nil {+ return err+ }+ if err := batch.Append(+ result.ProjectId, int64(result.CheckId), int64(result.RunId), result.CheckType,+ result.RecordedAt, result.ExecutedAt, result.Status, result.LatencyMs,+ int32(result.StatusCode), result.ErrorMsg, result.ExecutedBy,+ result.ScreenshotKey, result.OutputKey, int32(result.TlsDaysRemaining),+ ); err != nil {+ return err+ }+ return batch.Send()+}++func (r *checkResultRepository) FindByCheck(ctx context.Context, projectId uuid.UUID, checkId int, from *time.Time, to *time.Time, status string, page int, pageSize int) ([]*models.CheckResultEntry, int64, error) {+ where := "WHERE project_id = ? AND check_id = ?"+ args := []interface{}{projectId, int64(checkId)}++ if status != "" {+ where += " AND status = ?"+ args = append(args, status)+ }++ if from != nil {+ where += " AND recorded_at >= ?"+ args = append(args, *from)+ }+ if to != nil {+ where += " AND recorded_at <= ?"+ args = append(args, *to)+ }++ var total uint64+ if err := chdb.Conn.QueryRow(ctx, "SELECT count() FROM check_results "+where, args...).Scan(&total); err != nil {+ return nil, 0, err+ }++ query := "SELECT run_id, check_type, recorded_at, executed_at, status, latency_ms, status_code, error_message, executed_by, screenshot_key, output_key, tls_days_remaining FROM check_results " ++ where + " ORDER BY recorded_at DESC LIMIT ? OFFSET ?"+ args = append(args, pageSize, (page-1)*pageSize)++ rows, err := chdb.Conn.Query(ctx, query, args...)+ if err != nil {+ return nil, 0, err+ }+ defer rows.Close()++ var items []*models.CheckResultEntry+ for rows.Next() {+ entry := &models.CheckResultEntry{}+ var runId int64+ var statusCode, tlsDaysRemaining int32+ if err := rows.Scan(+ &runId, &entry.CheckType, &entry.RecordedAt, &entry.ExecutedAt, &entry.Status,+ &entry.LatencyMs, &statusCode, &entry.ErrorMessage, &entry.ExecutedBy,+ &entry.ScreenshotKey, &entry.OutputKey, &tlsDaysRemaining,+ ); err != nil {+ return nil, 0, err+ }+ entry.RunId = int(runId)+ entry.StatusCode = int(statusCode)+ entry.TlsDaysRemaining = int(tlsDaysRemaining)+ items = append(items, entry)+ }+ if err := rows.Err(); err != nil {+ return nil, 0, err+ }++ return items, int64(total), nil+}++// AggregatesByProject returns per-check result summaries for the range.+func (r *checkResultRepository) AggregatesByProject(ctx context.Context, projectId uuid.UUID, from time.Time, to time.Time) (map[int]*models.CheckAggregates, error) {+ // avgIf over zero matching rows is NaN (not NULL), which encoding/json+ // rejects; the OrNull combinator makes coalesce actually apply.+ query := `SELECT check_id,+ count(),+ countIf(status = 'up'),+ countIf(status = 'down'),+ countIf(status = 'missed'),+ coalesce(avgOrNullIf(latency_ms, status != 'missed'), 0)+ FROM check_results+ WHERE project_id = ? AND recorded_at >= ? AND recorded_at <= ?+ GROUP BY check_id`++ rows, err := chdb.Conn.Query(ctx, query, projectId, from, to)+ if err != nil {+ return nil, err+ }+ defer rows.Close()++ result := make(map[int]*models.CheckAggregates)+ for rows.Next() {+ var checkId int64+ var total, up, down, missed uint64+ var avgLatency float64+ if err := rows.Scan(&checkId, &total, &up, &down, &missed, &avgLatency); err != nil {+ return nil, err+ }+ result[int(checkId)] = &models.CheckAggregates{+ Total: int64(total),+ Up: int64(up),+ Down: int64(down),+ Missed: int64(missed),+ AvgLatencyMs: avgLatency,+ }+ }+ return result, rows.Err()+}++// SeriesByCheck buckets one check's results for the latency chart and uptime+// bars.+func (r *checkResultRepository) SeriesByCheck(ctx context.Context, projectId uuid.UUID, checkId int, from time.Time, to time.Time, intervalMinutes int) ([]*models.CheckSeriesPoint, error) {+ // OrNull for the same NaN reason as AggregatesByProject: an all-missed+ // bucket must yield 0, not NaN.+ query := `SELECT toStartOfInterval(recorded_at, INTERVAL ? minute) AS bucket,+ count(),+ countIf(status = 'up'),+ countIf(status = 'missed'),+ coalesce(avgOrNullIf(latency_ms, status != 'missed'), 0),+ coalesce(maxOrNullIf(latency_ms, status != 'missed'), 0)+ FROM check_results+ WHERE project_id = ? AND check_id = ? AND recorded_at >= ? AND recorded_at <= ?+ GROUP BY bucket ORDER BY bucket ASC`++ rows, err := chdb.Conn.Query(ctx, query, intervalMinutes, projectId, int64(checkId), from, to)+ if err != nil {+ return nil, err+ }+ defer rows.Close()++ var points []*models.CheckSeriesPoint+ for rows.Next() {+ var total, up, missed uint64+ point := &models.CheckSeriesPoint{}+ if err := rows.Scan(&point.Bucket, &total, &up, &missed, &point.AvgLatencyMs, &point.MaxLatencyMs); err != nil {+ return nil, err+ }+ point.Total = int64(total)+ point.Up = int64(up)+ point.Missed = int64(missed)+ points = append(points, point)+ }+ return points, rows.Err()+}++var CheckResultRepository = &checkResultRepository{}diff --git a/backend/app/repositories/telemetry/duckdb/check_result.repository.go b/backend/app/repositories/telemetry/duckdb/check_result.repository.gonew file mode 100644index 00000000..8f73769d--- /dev/null+++ b/backend/app/repositories/telemetry/duckdb/check_result.repository.go@@ -0,0 +1,168 @@+//go:build telemetry_duckdb++package duckdb++import (+ "context"+ "fmt"+ "time"++ "github.com/tracewayapp/traceway/backend/app/repositories/telemetry/shared"+ "github.com/tracewayapp/traceway/backend/app/repositories/telemetry/sqlitetypes"++ "github.com/duckdb/duckdb-go/v2"+ "github.com/google/uuid"+ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"+)++type checkResultRepository struct{}++func (r *checkResultRepository) Insert(ctx context.Context, result shared.CheckResult) error {+ var rowErr error+ err := withAppender(ctx, "check_results", func(appender *duckdb.Appender) {+ // Column order matches the check_results DDL in duckdb_telemetry/0003+ // plus 0004 (ALTER ADD appends output_key AFTER tls_days_remaining).+ rowErr = appender.AppendRow(+ result.ProjectId.String(),+ int64(result.CheckId),+ int64(result.RunId),+ result.CheckType,+ result.RecordedAt.UTC(),+ result.ExecutedAt.UTC(),+ result.Status,+ result.LatencyMs,+ int64(result.StatusCode),+ result.ErrorMsg,+ result.ExecutedBy,+ result.ScreenshotKey,+ int64(result.TlsDaysRemaining),+ result.OutputKey,+ )+ })+ if rowErr != nil {+ return rowErr+ }+ return err+}++func (r *checkResultRepository) FindByCheck(ctx context.Context, projectId uuid.UUID, checkId int, from *time.Time, to *time.Time, status string, page int, pageSize int) ([]*models.CheckResultEntry, int64, error) {+ where := "WHERE project_id = ? AND check_id = ?"+ args := []interface{}{projectId.String(), checkId}++ if status != "" {+ where += " AND status = ?"+ args = append(args, status)+ }++ if from != nil {+ where += " AND recorded_at >= ?"+ args = append(args, from.UTC())+ }+ if to != nil {+ where += " AND recorded_at <= ?"+ args = append(args, to.UTC())+ }++ var total int64+ if err := db.TelemetryDB.QueryRowContext(ctx, "SELECT CAST(COUNT(*) AS BIGINT) FROM check_results "+where, args...).Scan(&total); err != nil {+ return nil, 0, err+ }++ query := "SELECT CAST(run_id AS BIGINT), check_type, recorded_at, executed_at, status, latency_ms, CAST(status_code AS BIGINT), error_message, executed_by, screenshot_key, output_key, CAST(tls_days_remaining AS BIGINT) FROM check_results " ++ where + " ORDER BY recorded_at DESC LIMIT ? OFFSET ?"+ args = append(args, pageSize, (page-1)*pageSize)++ rows, err := db.TelemetryDB.QueryContext(ctx, query, args...)+ if err != nil {+ return nil, 0, err+ }+ defer rows.Close()++ var items []*models.CheckResultEntry+ for rows.Next() {+ entry := &models.CheckResultEntry{}+ var recordedAt, executedAt sqlitetypes.SQLiteTime+ if err := rows.Scan(+ &entry.RunId, &entry.CheckType, &recordedAt, &executedAt, &entry.Status,+ &entry.LatencyMs, &entry.StatusCode, &entry.ErrorMessage, &entry.ExecutedBy,+ &entry.ScreenshotKey, &entry.OutputKey, &entry.TlsDaysRemaining,+ ); err != nil {+ return nil, 0, err+ }+ entry.RecordedAt = recordedAt.Time+ entry.ExecutedAt = executedAt.Time+ items = append(items, entry)+ }+ if err := rows.Err(); err != nil {+ return nil, 0, err+ }++ return items, total, nil+}++// AggregatesByProject returns per-check result summaries for the range.+func (r *checkResultRepository) AggregatesByProject(ctx context.Context, projectId uuid.UUID, from time.Time, to time.Time) (map[int]*models.CheckAggregates, error) {+ query := `SELECT CAST(check_id AS BIGINT),+ CAST(COUNT(*) AS BIGINT),+ CAST(SUM(CASE WHEN status = 'up' THEN 1 ELSE 0 END) AS BIGINT),+ CAST(SUM(CASE WHEN status = 'down' THEN 1 ELSE 0 END) AS BIGINT),+ CAST(SUM(CASE WHEN status = 'missed' THEN 1 ELSE 0 END) AS BIGINT),+ COALESCE(AVG(CASE WHEN status <> 'missed' THEN latency_ms END), 0)+ FROM check_results+ WHERE project_id = ? AND recorded_at >= ? AND recorded_at <= ?+ GROUP BY check_id`++ rows, err := db.TelemetryDB.QueryContext(ctx, query, projectId.String(), from.UTC(), to.UTC())+ if err != nil {+ return nil, err+ }+ defer rows.Close()++ result := make(map[int]*models.CheckAggregates)+ for rows.Next() {+ var checkId int64+ agg := &models.CheckAggregates{}+ if err := rows.Scan(&checkId, &agg.Total, &agg.Up, &agg.Down, &agg.Missed, &agg.AvgLatencyMs); err != nil {+ return nil, err+ }+ result[int(checkId)] = agg+ }+ return result, rows.Err()+}++// SeriesByCheck buckets one check's results. The explicit epoch origin on+// time_bucket keeps sub-day buckets aligned with the SQLite backend's+// epoch-floored buckets.+func (r *checkResultRepository) SeriesByCheck(ctx context.Context, projectId uuid.UUID, checkId int, from time.Time, to time.Time, intervalMinutes int) ([]*models.CheckSeriesPoint, error) {+ bucketSeconds := intervalMinutes * 60+ query := fmt.Sprintf(`SELECT CAST(epoch(time_bucket(to_seconds(%d), recorded_at, TIMESTAMP '1970-01-01')) AS BIGINT) AS bucket,+ CAST(COUNT(*) AS BIGINT),+ CAST(SUM(CASE WHEN status = 'up' THEN 1 ELSE 0 END) AS BIGINT),+ CAST(SUM(CASE WHEN status = 'missed' THEN 1 ELSE 0 END) AS BIGINT),+ COALESCE(AVG(CASE WHEN status <> 'missed' THEN latency_ms END), 0),+ COALESCE(MAX(CASE WHEN status <> 'missed' THEN latency_ms END), 0)+ FROM check_results+ WHERE project_id = ? AND check_id = ? AND recorded_at >= ? AND recorded_at <= ?+ GROUP BY bucket ORDER BY bucket ASC`, bucketSeconds)++ rows, err := db.TelemetryDB.QueryContext(ctx, query, projectId.String(), checkId, from.UTC(), to.UTC())+ if err != nil {+ return nil, err+ }+ defer rows.Close()++ var points []*models.CheckSeriesPoint+ for rows.Next() {+ var bucket int64+ point := &models.CheckSeriesPoint{}+ if err := rows.Scan(&bucket, &point.Total, &point.Up, &point.Missed, &point.AvgLatencyMs, &point.MaxLatencyMs); err != nil {+ return nil, err+ }+ point.Bucket = time.Unix(bucket, 0).UTC()+ points = append(points, point)+ }+ return points, rows.Err()+}++var CheckResultRepository = &checkResultRepository{}diff --git a/backend/app/repositories/telemetry/shared/types.go b/backend/app/repositories/telemetry/shared/types.goindex d45b9c67..42897866 100644--- a/backend/app/repositories/telemetry/shared/types.go+++ b/backend/app/repositories/telemetry/shared/types.go@@ -23,6 +23,28 @@ type FiredNotification struct {FiredAt time.Time}+// CheckResult is one synthetic-check probe outcome. RecordedAt is the+// scheduled time (the uptime timeline position); ExecutedAt is when the probe+// actually ran.+type CheckResult struct {+ ProjectId uuid.UUID+ CheckId int+ RunId int+ CheckType string+ RecordedAt time.Time+ ExecutedAt time.Time+ Status string+ LatencyMs float64+ StatusCode int+ ErrorMsg string+ ExecutedBy string+ ScreenshotKey string+ // OutputKey references the stored Playwright output (stdout/stderr tail+ // + report error) of a failed browser run, next to the screenshot.+ OutputKey string+ TlsDaysRemaining int+}+// LogAttributeFilter selects logs by attribute value. Scope is one of// "resource", "scope", or "log"; picks which of the three attribute maps to// query (Map columns with bloom-filter indexes on ClickHouse, JSON ondiff --git a/backend/app/repositories/telemetry/sqlite/check_result.repository.go b/backend/app/repositories/telemetry/sqlite/check_result.repository.gonew file mode 100644index 00000000..d050ee3c--- /dev/null+++ b/backend/app/repositories/telemetry/sqlite/check_result.repository.go@@ -0,0 +1,188 @@+//go:build !telemetry_ch && !telemetry_duckdb++package sqlite++import (+ "context"+ "time"++ "github.com/tracewayapp/traceway/backend/app/repositories/telemetry/shared"+ "github.com/tracewayapp/traceway/backend/app/repositories/telemetry/sqlitetypes"++ "github.com/google/uuid"+ "github.com/tracewayapp/lit/v2"+ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"+)++type checkResultRow struct {+ ProjectId uuid.UUID `lit:"project_id"`+ CheckId int `lit:"check_id"`+ RunId int `lit:"run_id"`+ CheckType string `lit:"check_type"`+ RecordedAt sqlitetypes.SQLiteTime `lit:"recorded_at"`+ ExecutedAt sqlitetypes.SQLiteTime `lit:"executed_at"`+ Status string `lit:"status"`+ LatencyMs float64 `lit:"latency_ms"`+ StatusCode int `lit:"status_code"`+ ErrorMsg string `lit:"error_message"`+ ExecutedBy string `lit:"executed_by"`+ ScreenshotKey string `lit:"screenshot_key"`+ OutputKey string `lit:"output_key"`+ TlsDaysRemaining int `lit:"tls_days_remaining"`+}++func init() {+ models.ExtensionModelRegistrations = append(models.ExtensionModelRegistrations, func(driver lit.Driver) {+ lit.RegisterModel[checkResultRow](driver)+ })+}++type checkResultRepository struct{}++func (r *checkResultRepository) Insert(ctx context.Context, result shared.CheckResult) error {+ query, args, err := lit.ParseNamedQuery(db.Driver,+ `INSERT INTO check_results (project_id, check_id, run_id, check_type, recorded_at, executed_at, status, latency_ms, status_code, error_message, executed_by, screenshot_key, output_key, tls_days_remaining)+ VALUES (:project_id, :check_id, :run_id, :check_type, :recorded_at, :executed_at, :status, :latency_ms, :status_code, :error_message, :executed_by, :screenshot_key, :output_key, :tls_days_remaining)`,+ lit.P{+ "project_id": result.ProjectId,+ "check_id": result.CheckId,+ "run_id": result.RunId,+ "check_type": result.CheckType,+ "recorded_at": sqlitetypes.NewSQLiteTime(result.RecordedAt),+ "executed_at": sqlitetypes.NewSQLiteTime(result.ExecutedAt),+ "status": result.Status,+ "latency_ms": result.LatencyMs,+ "status_code": result.StatusCode,+ "error_message": result.ErrorMsg,+ "executed_by": result.ExecutedBy,+ "screenshot_key": result.ScreenshotKey,+ "output_key": result.OutputKey,+ "tls_days_remaining": result.TlsDaysRemaining,+ })+ if err != nil {+ return err+ }+ _, err = db.TelemetryDB.ExecContext(ctx, query, args...)+ return err+}++func (r *checkResultRepository) FindByCheck(ctx context.Context, projectId uuid.UUID, checkId int, from *time.Time, to *time.Time, status string, page int, pageSize int) ([]*models.CheckResultEntry, int64, error) {+ where := "WHERE project_id = ? AND check_id = ?"+ args := []interface{}{projectId.String(), checkId}++ if status != "" {+ where += " AND status = ?"+ args = append(args, status)+ }++ if from != nil {+ where += " AND recorded_at >= ?"+ args = append(args, from.UTC().Format(time.RFC3339Nano))+ }+ if to != nil {+ where += " AND recorded_at <= ?"+ args = append(args, to.UTC().Format(time.RFC3339Nano))+ }++ var total int64+ if err := db.TelemetryDB.QueryRowContext(ctx, "SELECT COUNT(*) FROM check_results "+where, args...).Scan(&total); err != nil {+ return nil, 0, err+ }++ query := "SELECT run_id, check_type, recorded_at, executed_at, status, latency_ms, status_code, error_message, executed_by, screenshot_key, output_key, tls_days_remaining FROM check_results " ++ where + " ORDER BY recorded_at DESC LIMIT ? OFFSET ?"+ args = append(args, pageSize, (page-1)*pageSize)++ rows, err := db.TelemetryDB.QueryContext(ctx, query, args...)+ if err != nil {+ return nil, 0, err+ }+ defer rows.Close()++ var items []*models.CheckResultEntry+ for rows.Next() {+ entry := &models.CheckResultEntry{}+ var recordedAt, executedAt sqlitetypes.SQLiteTime+ if err := rows.Scan(+ &entry.RunId, &entry.CheckType, &recordedAt, &executedAt, &entry.Status,+ &entry.LatencyMs, &entry.StatusCode, &entry.ErrorMessage, &entry.ExecutedBy,+ &entry.ScreenshotKey, &entry.OutputKey, &entry.TlsDaysRemaining,+ ); err != nil {+ return nil, 0, err+ }+ entry.RecordedAt = recordedAt.Time+ entry.ExecutedAt = executedAt.Time+ items = append(items, entry)+ }+ if err := rows.Err(); err != nil {+ return nil, 0, err+ }++ return items, total, nil+}++// AggregatesByProject returns per-check result summaries for the range.+func (r *checkResultRepository) AggregatesByProject(ctx context.Context, projectId uuid.UUID, from time.Time, to time.Time) (map[int]*models.CheckAggregates, error) {+ query := `SELECT check_id,+ COUNT(*),+ SUM(CASE WHEN status = 'up' THEN 1 ELSE 0 END),+ SUM(CASE WHEN status = 'down' THEN 1 ELSE 0 END),+ SUM(CASE WHEN status = 'missed' THEN 1 ELSE 0 END),+ COALESCE(AVG(CASE WHEN status <> 'missed' THEN latency_ms END), 0)+ FROM check_results+ WHERE project_id = ? AND recorded_at >= ? AND recorded_at <= ?+ GROUP BY check_id`++ rows, err := db.TelemetryDB.QueryContext(ctx, query, projectId.String(), from.UTC().Format(time.RFC3339Nano), to.UTC().Format(time.RFC3339Nano))+ if err != nil {+ return nil, err+ }+ defer rows.Close()++ result := make(map[int]*models.CheckAggregates)+ for rows.Next() {+ var checkId int+ agg := &models.CheckAggregates{}+ if err := rows.Scan(&checkId, &agg.Total, &agg.Up, &agg.Down, &agg.Missed, &agg.AvgLatencyMs); err != nil {+ return nil, err+ }+ result[checkId] = agg+ }+ return result, rows.Err()+}++// SeriesByCheck buckets one check's results for the latency chart and uptime+// bars. Buckets are epoch-floored to align with the other backends.+func (r *checkResultRepository) SeriesByCheck(ctx context.Context, projectId uuid.UUID, checkId int, from time.Time, to time.Time, intervalMinutes int) ([]*models.CheckSeriesPoint, error) {+ bucketSeconds := intervalMinutes * 60+ query := `SELECT (CAST(strftime('%s', recorded_at) AS INTEGER) / ?) * ? AS bucket,+ COUNT(*),+ SUM(CASE WHEN status = 'up' THEN 1 ELSE 0 END),+ SUM(CASE WHEN status = 'missed' THEN 1 ELSE 0 END),+ COALESCE(AVG(CASE WHEN status <> 'missed' THEN latency_ms END), 0),+ COALESCE(MAX(CASE WHEN status <> 'missed' THEN latency_ms END), 0)+ FROM check_results+ WHERE project_id = ? AND check_id = ? AND recorded_at >= ? AND recorded_at <= ?+ GROUP BY bucket ORDER BY bucket ASC`++ rows, err := db.TelemetryDB.QueryContext(ctx, query, bucketSeconds, bucketSeconds, projectId.String(), checkId, from.UTC().Format(time.RFC3339Nano), to.UTC().Format(time.RFC3339Nano))+ if err != nil {+ return nil, err+ }+ defer rows.Close()++ var points []*models.CheckSeriesPoint+ for rows.Next() {+ var bucket int64+ point := &models.CheckSeriesPoint{}+ if err := rows.Scan(&bucket, &point.Total, &point.Up, &point.Missed, &point.AvgLatencyMs, &point.MaxLatencyMs); err != nil {+ return nil, err+ }+ point.Bucket = time.Unix(bucket, 0).UTC()+ points = append(points, point)+ }+ return points, rows.Err()+}++var CheckResultRepository = &checkResultRepository{}diff --git a/backend/app/repositories/telemetry/telemetry_ch.go b/backend/app/repositories/telemetry/telemetry_ch.goindex 0d51cabd..4285a693 100644--- a/backend/app/repositories/telemetry/telemetry_ch.go+++ b/backend/app/repositories/telemetry/telemetry_ch.go@@ -6,6 +6,7 @@ import ch "github.com/tracewayapp/traceway/backend/app/repositories/telemetry/clvar (AiTraceRepository = ch.AiTraceRepository+ CheckResultRepository = ch.CheckResultRepositoryEndpointRepository = ch.EndpointRepositoryExceptionStackTraceRepository = ch.ExceptionStackTraceRepositoryFiredNotificationRepository = ch.FiredNotificationRepositorydiff --git a/backend/app/repositories/telemetry/telemetry_duckdb.go b/backend/app/repositories/telemetry/telemetry_duckdb.goindex 19473651..a77939ea 100644--- a/backend/app/repositories/telemetry/telemetry_duckdb.go+++ b/backend/app/repositories/telemetry/telemetry_duckdb.go@@ -6,6 +6,7 @@ import duckdbrepo "github.com/tracewayapp/traceway/backend/app/repositories/televar (AiTraceRepository = duckdbrepo.AiTraceRepository+ CheckResultRepository = duckdbrepo.CheckResultRepositoryEndpointRepository = duckdbrepo.EndpointRepositoryExceptionStackTraceRepository = duckdbrepo.ExceptionStackTraceRepositoryFiredNotificationRepository = duckdbrepo.FiredNotificationRepositorydiff --git a/backend/app/repositories/telemetry/telemetry_shared.go b/backend/app/repositories/telemetry/telemetry_shared.goindex 570a1126..62186e2e 100644--- a/backend/app/repositories/telemetry/telemetry_shared.go+++ b/backend/app/repositories/telemetry/telemetry_shared.go@@ -9,6 +9,7 @@ import (type (SessionAttributeFilter = shared.SessionAttributeFilterFiredNotification = shared.FiredNotification+ CheckResult = shared.CheckResultLogAttributeFilter = shared.LogAttributeFilterLogSearchParams = shared.LogSearchParams)diff --git a/backend/app/repositories/telemetry/telemetry_sqlite.go b/backend/app/repositories/telemetry/telemetry_sqlite.goindex c83a8784..94fa8ec9 100644--- a/backend/app/repositories/telemetry/telemetry_sqlite.go+++ b/backend/app/repositories/telemetry/telemetry_sqlite.go@@ -6,6 +6,7 @@ import sqliterepo "github.com/tracewayapp/traceway/backend/app/repositories/televar (AiTraceRepository = sqliterepo.AiTraceRepository+ CheckResultRepository = sqliterepo.CheckResultRepositoryEndpointRepository = sqliterepo.EndpointRepositoryExceptionStackTraceRepository = sqliterepo.ExceptionStackTraceRepositoryFiredNotificationRepository = sqliterepo.FiredNotificationRepositorydiff --git a/backend/app/repositories/transactional/pg/check_incident.repository.go b/backend/app/repositories/transactional/pg/check_incident.repository.gonew file mode 100644index 00000000..4a7008d1--- /dev/null+++ b/backend/app/repositories/transactional/pg/check_incident.repository.go@@ -0,0 +1,59 @@+//go:build transactional_pg++package pg++import (+ "database/sql"+ "time"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"++ "github.com/tracewayapp/lit/v2"+)++type checkIncidentRepository struct{}++const checkIncidentColumns = "id, check_id, project_id, started_at, resolved_at, error_message"++func (r *checkIncidentRepository) Open(tx *sql.Tx, incident *models.CheckIncident) (int, error) {+ return lit.Insert[models.CheckIncident](tx, incident)+}++func (r *checkIncidentRepository) FindOpenByCheck(tx *sql.Tx, checkId int) (*models.CheckIncident, error) {+ return lit.SelectSingleNamed[models.CheckIncident](+ tx,+ "SELECT "+checkIncidentColumns+" FROM check_incidents WHERE check_id = :check_id AND resolved_at IS NULL ORDER BY started_at DESC, id DESC LIMIT 1",+ lit.P{"check_id": checkId},+ )+}++func (r *checkIncidentRepository) Resolve(tx *sql.Tx, id int, resolvedAt time.Time) error {+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "UPDATE check_incidents SET resolved_at = :resolved_at WHERE id = :id AND resolved_at IS NULL",+ lit.P{"resolved_at": resolvedAt.UTC(), "id": id},+ )+ if err != nil {+ return err+ }+ return lit.UpdateNative(tx, query, args...)+}++func (r *checkIncidentRepository) FindRecentByCheck(tx *sql.Tx, checkId int, limit int) ([]*models.CheckIncident, error) {+ return lit.SelectNamed[models.CheckIncident](+ tx,+ "SELECT "+checkIncidentColumns+" FROM check_incidents WHERE check_id = :check_id ORDER BY started_at DESC, id DESC LIMIT :limit",+ lit.P{"check_id": checkId, "limit": limit},+ )+}++func (r *checkIncidentRepository) FindByCheckSince(tx *sql.Tx, checkId int, since time.Time) ([]*models.CheckIncident, error) {+ return lit.SelectNamed[models.CheckIncident](+ tx,+ "SELECT "+checkIncidentColumns+" FROM check_incidents WHERE check_id = :check_id AND (resolved_at IS NULL OR resolved_at >= :since) ORDER BY started_at DESC, id DESC",+ lit.P{"check_id": checkId, "since": since.UTC()},+ )+}++var CheckIncidentRepository = checkIncidentRepository{}diff --git a/backend/app/repositories/transactional/pg/check_run.repository.go b/backend/app/repositories/transactional/pg/check_run.repository.gonew file mode 100644index 00000000..5beb8900--- /dev/null+++ b/backend/app/repositories/transactional/pg/check_run.repository.go@@ -0,0 +1,158 @@+//go:build transactional_pg++package pg++import (+ "database/sql"+ "time"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"++ "github.com/tracewayapp/lit/v2"+)++type checkRunRepository struct{}++const checkRunColumns = "id, check_id, project_id, check_type, status, scheduled_for, expires_at, claimed_at, claimed_by, created_at"++// Enqueue inserts a queued run in the caller's transaction and returns its id.+func (r *checkRunRepository) Enqueue(tx *sql.Tx, run *models.CheckRun) (int, error) {+ return lit.Insert[models.CheckRun](tx, run)+}++func (r *checkRunRepository) FindById(tx *sql.Tx, id int) (*models.CheckRun, error) {+ return lit.SelectSingleNamed[models.CheckRun](+ tx,+ "SELECT "+checkRunColumns+" FROM check_runs WHERE id = :id",+ lit.P{"id": id},+ )+}++// FindClaimable returns queued, unexpired runs of the given types, oldest+// first. Types are matched positionally because lit has no IN-list expansion+// for named params; callers pass 1-3 types, padding is harmless.+func (r *checkRunRepository) FindClaimable(tx *sql.Tx, typeA string, typeB string, typeC string, now time.Time, limit int) ([]*models.CheckRun, error) {+ return lit.SelectNamed[models.CheckRun](+ tx,+ "SELECT "+checkRunColumns+" FROM check_runs WHERE status = 'queued' AND expires_at > :now AND check_type IN (:type_a, :type_b, :type_c) ORDER BY scheduled_for ASC, id ASC LIMIT :limit",+ lit.P{"now": now.UTC(), "type_a": typeA, "type_b": typeB, "type_c": typeC, "limit": limit},+ )+}++// FindClaimableBrowser returns queued, unexpired browser runs for the+// remote-runner poll endpoint. Runners are operator infrastructure serving+// the whole instance, so there is deliberately no tenant filter.+func (r *checkRunRepository) FindClaimableBrowser(tx *sql.Tx, now time.Time, limit int) ([]*models.CheckRun, error) {+ return lit.SelectNamed[models.CheckRun](+ tx,+ "SELECT id, check_id, project_id, check_type, status, scheduled_for, expires_at, claimed_at, claimed_by, created_at FROM check_runs WHERE status = 'queued' AND check_type = 'browser' AND expires_at > :now ORDER BY scheduled_for ASC, id ASC LIMIT :limit",+ lit.P{"now": now.UTC(), "limit": limit},+ )+}++// Claim transitions one run queued -> claimed. The status guard makes the+// claim lose against a concurrent claimer; returns whether the claim won,+// and callers must not execute when it lost.+func (r *checkRunRepository) Claim(tx *sql.Tx, id int, claimedBy string, now time.Time) (bool, error) {+ return guardedStatusUpdate(+ tx,+ "UPDATE check_runs SET status = 'claimed', claimed_at = :now, claimed_by = :claimed_by WHERE id = :id AND status = 'queued'",+ lit.P{"now": now.UTC(), "claimed_by": claimedBy, "id": id},+ )+}++// Delete removes a finalized run. The telemetry check_results row is the+// durable record; terminal queue rows are never kept.+func (r *checkRunRepository) Delete(tx *sql.Tx, id int) error {+ return lit.DeleteNamed(db.Driver, tx, "DELETE FROM check_runs WHERE id = :id", lit.P{"id": id})+}++// DeleteClaimedBy finalizes a run only while the caller still owns the claim.+// Zero rows means a stale-claim reclaim handed the run to someone else; the+// loser must discard its outcome instead of double-applying state.+func (r *checkRunRepository) DeleteClaimedBy(tx *sql.Tx, id int, claimedBy string) (bool, error) {+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "DELETE FROM check_runs WHERE id = :id AND status = 'claimed' AND claimed_by = :claimed_by",+ lit.P{"id": id, "claimed_by": claimedBy},+ )+ if err != nil {+ return false, err+ }+ result, err := tx.Exec(query, args...)+ if err != nil {+ return false, err+ }+ affected, err := result.RowsAffected()+ if err != nil {+ return false, err+ }+ return affected > 0, nil+}++// DeleteQueuedByCheck drops not-yet-claimed runs, used when a check is+// paused so stale probes don't fire on re-enable.+func (r *checkRunRepository) DeleteQueuedByCheck(tx *sql.Tx, checkId int) error {+ return lit.DeleteNamed(db.Driver, tx, "DELETE FROM check_runs WHERE check_id = :check_id AND status = 'queued'", lit.P{"check_id": checkId})+}++// ReclaimStaleClaimed returns runs claimed before the cutoff (the claimer+// died mid-execution) to queued so another executor can pick them up; their+// expires_at still bounds how stale a probe may run.+func (r *checkRunRepository) ReclaimStaleClaimed(tx *sql.Tx, cutoff time.Time) error {+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "UPDATE check_runs SET status = 'queued', claimed_at = NULL, claimed_by = '' WHERE status = 'claimed' AND claimed_at < :cutoff",+ lit.P{"cutoff": cutoff.UTC()},+ )+ if err != nil {+ return err+ }+ return lit.UpdateNative(tx, query, args...)+}++// FindExpiredQueued returns queued runs past their expiry, to be recorded as+// missed and deleted. Executing them late would corrupt the uptime timeline.+func (r *checkRunRepository) FindExpiredQueued(tx *sql.Tx, now time.Time, limit int) ([]*models.CheckRun, error) {+ return lit.SelectNamed[models.CheckRun](+ tx,+ "SELECT "+checkRunColumns+" FROM check_runs WHERE status = 'queued' AND expires_at <= :now ORDER BY expires_at ASC, id ASC LIMIT :limit",+ lit.P{"now": now.UTC(), "limit": limit},+ )+}++// HasPendingForCheck reports whether a queued or claimed run already exists,+// so run-now cannot pile up duplicates behind a stuck executor.+func (r *checkRunRepository) HasPendingForCheck(tx *sql.Tx, checkId int) (bool, error) {+ result, err := lit.SelectSingleNamed[models.CountResult](+ tx,+ "SELECT COUNT(*) as count FROM check_runs WHERE check_id = :check_id AND status IN ('queued', 'claimed')",+ lit.P{"check_id": checkId},+ )+ if err != nil {+ return false, err+ }+ return result != nil && result.Count > 0, nil+}++func (r *checkRunRepository) CountsForHealth(tx *sql.Tx) (*models.CheckRunHealthCounts, error) {+ return lit.SelectSingleNamed[models.CheckRunHealthCounts](+ tx,+ "SELECT COALESCE(SUM(CASE WHEN status = 'queued' THEN 1 ELSE 0 END), 0) AS queued_count, COALESCE(SUM(CASE WHEN status = 'claimed' THEN 1 ELSE 0 END), 0) AS claimed_count FROM check_runs",+ lit.P{},+ )+}++// OldestQueued returns the queued run with the earliest scheduled_for, or+// nil. A plain-column select, because SQLite loses type affinity on+// timestamp aggregates.+func (r *checkRunRepository) OldestQueued(tx *sql.Tx) (*models.CheckRun, error) {+ return lit.SelectSingleNamed[models.CheckRun](+ tx,+ "SELECT "+checkRunColumns+" FROM check_runs WHERE status = 'queued' ORDER BY scheduled_for ASC, id ASC LIMIT 1",+ lit.P{},+ )+}++var CheckRunRepository = checkRunRepository{}diff --git a/backend/app/repositories/transactional/pg/notification_rule.repository.go b/backend/app/repositories/transactional/pg/notification_rule.repository.goindex ff66d344..91059be9 100644--- a/backend/app/repositories/transactional/pg/notification_rule.repository.go+++ b/backend/app/repositories/transactional/pg/notification_rule.repository.go@@ -44,7 +44,7 @@ func (r *notificationRuleRepository) FindEnabledPolledRules(tx *sql.Tx) ([]*modeFROM notification_rules rJOIN notification_channels c ON c.id = r.channel_idWHERE r.enabled = true AND c.enabled = true- AND r.rule_type NOT IN ('new_error', 'error_regression', 'ai_trace_cost', 'ai_conversation_cost', 'ai_flagged_content')`,+ AND r.rule_type NOT IN ('new_error', 'error_regression', 'ai_trace_cost', 'ai_conversation_cost', 'ai_flagged_content', 'check_down')`,)}@@ -56,7 +56,7 @@ func (r *notificationRuleRepository) FindEnabledEventRules(tx *sql.Tx, projectIdFROM notification_rules rJOIN notification_channels c ON c.id = r.channel_idWHERE r.project_id = :project_id AND r.enabled = true AND c.enabled = true- AND r.rule_type IN ('new_error', 'error_regression', 'ai_trace_cost', 'ai_conversation_cost', 'ai_flagged_content')`,+ AND r.rule_type IN ('new_error', 'error_regression', 'ai_trace_cost', 'ai_conversation_cost', 'ai_flagged_content', 'check_down')`,lit.P{"project_id": projectId},)}diff --git a/backend/app/repositories/transactional/pg/page.repository.go b/backend/app/repositories/transactional/pg/page.repository.goindex 83c16834..80fbf2b6 100644--- a/backend/app/repositories/transactional/pg/page.repository.go+++ b/backend/app/repositories/transactional/pg/page.repository.go@@ -166,4 +166,14 @@ func (r *pageRepository) Resolve(tx *sql.Tx, id int, userId int, now time.Time))}+// ResolveSystem resolves a page with no resolving user, for system-driven+// resolution (a synthetic check recovering). Same guard as Resolve.+func (r *pageRepository) ResolveSystem(tx *sql.Tx, id int, now time.Time) (bool, error) {+ return guardedStatusUpdate(+ tx,+ "UPDATE pages SET status = 'resolved', resolved_by = NULL, resolved_at = :now, next_escalation_at = NULL, updated_at = :now WHERE id = :id AND status <> 'resolved'",+ lit.P{"now": now.UTC(), "id": id},+ )+}+var PageRepository = pageRepository{}diff --git a/backend/app/repositories/transactional/pg/status_page.repository.go b/backend/app/repositories/transactional/pg/status_page.repository.gonew file mode 100644index 00000000..eccf3aca--- /dev/null+++ b/backend/app/repositories/transactional/pg/status_page.repository.go@@ -0,0 +1,83 @@+//go:build transactional_pg++package pg++import (+ "database/sql"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"++ "github.com/tracewayapp/lit/v2"+)++type statusPageRepository struct{}++const statusPageColumns = "id, organization_id, slug, name, is_public, check_ids, description, logo_key, custom_domain, created_at, updated_at"++func (r *statusPageRepository) Create(tx *sql.Tx, page *models.StatusPage) (int, error) {+ return lit.Insert[models.StatusPage](tx, page)+}++func (r *statusPageRepository) Update(tx *sql.Tx, page *models.StatusPage) error {+ return lit.UpdateNamed(tx, page, "id = :id", lit.P{"id": page.Id})+}++func (r *statusPageRepository) Delete(tx *sql.Tx, id int, organizationId int) error {+ return lit.DeleteNamed(db.Driver, tx, "DELETE FROM status_pages WHERE id = :id AND organization_id = :organization_id", lit.P{"id": id, "organization_id": organizationId})+}++func (r *statusPageRepository) FindByIdForOrganization(tx *sql.Tx, id int, organizationId int) (*models.StatusPage, error) {+ return lit.SelectSingleNamed[models.StatusPage](+ tx,+ "SELECT "+statusPageColumns+" FROM status_pages WHERE id = :id AND organization_id = :organization_id",+ lit.P{"id": id, "organization_id": organizationId},+ )+}++func (r *statusPageRepository) ListByOrganization(tx *sql.Tx, organizationId int) ([]*models.StatusPage, error) {+ return lit.SelectNamed[models.StatusPage](+ tx,+ "SELECT "+statusPageColumns+" FROM status_pages WHERE organization_id = :organization_id ORDER BY name ASC, id ASC",+ lit.P{"organization_id": organizationId},+ )+}++func (r *statusPageRepository) FindBySlug(tx *sql.Tx, slug string) (*models.StatusPage, error) {+ return lit.SelectSingleNamed[models.StatusPage](+ tx,+ "SELECT "+statusPageColumns+" FROM status_pages WHERE slug = :slug",+ lit.P{"slug": slug},+ )+}++// FindPublicBySlug backs the anonymous status endpoint: private pages are+// indistinguishable from missing ones.+func (r *statusPageRepository) FindPublicBySlug(tx *sql.Tx, slug string) (*models.StatusPage, error) {+ return lit.SelectSingleNamed[models.StatusPage](+ tx,+ "SELECT "+statusPageColumns+" FROM status_pages WHERE slug = :slug AND is_public = true",+ lit.P{"slug": slug},+ )+}++// FindByCustomDomain backs the create/update uniqueness check.+func (r *statusPageRepository) FindByCustomDomain(tx *sql.Tx, domain string) (*models.StatusPage, error) {+ return lit.SelectSingleNamed[models.StatusPage](+ tx,+ "SELECT "+statusPageColumns+" FROM status_pages WHERE custom_domain <> '' AND custom_domain = :domain",+ lit.P{"domain": domain},+ )+}++// FindPublicByCustomDomain resolves a vanity host (CNAME to this instance)+// to its status page.+func (r *statusPageRepository) FindPublicByCustomDomain(tx *sql.Tx, domain string) (*models.StatusPage, error) {+ return lit.SelectSingleNamed[models.StatusPage](+ tx,+ "SELECT "+statusPageColumns+" FROM status_pages WHERE custom_domain <> '' AND custom_domain = :domain AND is_public = true",+ lit.P{"domain": domain},+ )+}++var StatusPageRepository = statusPageRepository{}diff --git a/backend/app/repositories/transactional/pg/synthetic_check.repository.go b/backend/app/repositories/transactional/pg/synthetic_check.repository.gonew file mode 100644index 00000000..6e251f85--- /dev/null+++ b/backend/app/repositories/transactional/pg/synthetic_check.repository.go@@ -0,0 +1,168 @@+//go:build transactional_pg++package pg++import (+ "database/sql"+ "time"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"++ "github.com/google/uuid"+ "github.com/tracewayapp/lit/v2"+)++type syntheticCheckRepository struct{}++const syntheticCheckColumns = "id, project_id, name, check_type, enabled, interval_seconds, timeout_seconds, config, failure_threshold, current_status, consecutive_failures, last_run_at, last_state_change_at, next_run_at, created_at, updated_at"++func (r *syntheticCheckRepository) Create(tx *sql.Tx, check *models.SyntheticCheck) (int, error) {+ return lit.Insert[models.SyntheticCheck](tx, check)+}++// Update writes only the user-editable columns. The run-state columns+// (current_status, consecutive_failures, last_run_at, last_state_change_at)+// belong to ApplyRunState; a full-row update here could revert a concurrent+// executor finalization on PostgreSQL.+func (r *syntheticCheckRepository) Update(tx *sql.Tx, check *models.SyntheticCheck) error {+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "UPDATE synthetic_checks SET name = :name, enabled = :enabled, interval_seconds = :interval_seconds, timeout_seconds = :timeout_seconds, config = :config, failure_threshold = :failure_threshold, next_run_at = :next_run_at, updated_at = :updated_at WHERE id = :id",+ lit.P{+ "name": check.Name,+ "enabled": check.Enabled,+ "interval_seconds": check.IntervalSeconds,+ "timeout_seconds": check.TimeoutSeconds,+ "config": check.Config,+ "failure_threshold": check.FailureThreshold,+ "next_run_at": check.NextRunAt.UTC(),+ "updated_at": check.UpdatedAt.UTC(),+ "id": check.Id,+ },+ )+ if err != nil {+ return err+ }+ return lit.UpdateNative(tx, query, args...)+}++func (r *syntheticCheckRepository) Delete(tx *sql.Tx, id int, projectId uuid.UUID) error {+ return lit.DeleteNamed(db.Driver, tx, "DELETE FROM synthetic_checks WHERE id = :id AND project_id = :project_id", lit.P{"id": id, "project_id": projectId})+}++func (r *syntheticCheckRepository) FindById(tx *sql.Tx, id int) (*models.SyntheticCheck, error) {+ return lit.SelectSingleNamed[models.SyntheticCheck](+ tx,+ "SELECT "+syntheticCheckColumns+" FROM synthetic_checks WHERE id = :id",+ lit.P{"id": id},+ )+}++func (r *syntheticCheckRepository) FindByIdForProject(tx *sql.Tx, id int, projectId uuid.UUID) (*models.SyntheticCheck, error) {+ return lit.SelectSingleNamed[models.SyntheticCheck](+ tx,+ "SELECT "+syntheticCheckColumns+" FROM synthetic_checks WHERE id = :id AND project_id = :project_id",+ lit.P{"id": id, "project_id": projectId},+ )+}++func (r *syntheticCheckRepository) FindByProject(tx *sql.Tx, projectId uuid.UUID) ([]*models.SyntheticCheck, error) {+ return lit.SelectNamed[models.SyntheticCheck](+ tx,+ "SELECT "+syntheticCheckColumns+" FROM synthetic_checks WHERE project_id = :project_id ORDER BY name ASC, id ASC",+ lit.P{"project_id": projectId},+ )+}++// FindDueEnabled returns enabled checks whose next run time has passed,+// oldest-due first.+func (r *syntheticCheckRepository) FindDueEnabled(tx *sql.Tx, now time.Time, limit int) ([]*models.SyntheticCheck, error) {+ return lit.SelectNamed[models.SyntheticCheck](+ tx,+ "SELECT "+syntheticCheckColumns+" FROM synthetic_checks WHERE enabled = true AND next_run_at <= :now ORDER BY next_run_at ASC, id ASC LIMIT :limit",+ lit.P{"now": now.UTC(), "limit": limit},+ )+}++// SetNextRun advances the schedule pointer. Called in the same transaction+// that enqueues the run row, so multi-instance schedulers (behind the+// advisory lock) never double-enqueue an interval.+func (r *syntheticCheckRepository) SetNextRun(tx *sql.Tx, id int, nextRunAt time.Time) error {+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "UPDATE synthetic_checks SET next_run_at = :next_run_at WHERE id = :id",+ lit.P{"next_run_at": nextRunAt.UTC(), "id": id},+ )+ if err != nil {+ return err+ }+ return lit.UpdateNative(tx, query, args...)+}++// ApplyRunState persists the outcome of one executed run on the check row.+// lastStateChangeAt is only written on transitions (nil leaves it untouched).+func (r *syntheticCheckRepository) ApplyRunState(tx *sql.Tx, id int, currentStatus string, consecutiveFailures int, lastRunAt time.Time, lastStateChangeAt *time.Time) error {+ if lastStateChangeAt != nil {+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "UPDATE synthetic_checks SET current_status = :current_status, consecutive_failures = :consecutive_failures, last_run_at = :last_run_at, last_state_change_at = :last_state_change_at WHERE id = :id",+ lit.P{"current_status": currentStatus, "consecutive_failures": consecutiveFailures, "last_run_at": lastRunAt.UTC(), "last_state_change_at": lastStateChangeAt.UTC(), "id": id},+ )+ if err != nil {+ return err+ }+ return lit.UpdateNative(tx, query, args...)+ }+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "UPDATE synthetic_checks SET current_status = :current_status, consecutive_failures = :consecutive_failures, last_run_at = :last_run_at WHERE id = :id",+ lit.P{"current_status": currentStatus, "consecutive_failures": consecutiveFailures, "last_run_at": lastRunAt.UTC(), "id": id},+ )+ if err != nil {+ return err+ }+ return lit.UpdateNative(tx, query, args...)+}++// FindByIdInOrganization scopes a check lookup to an organization (status+// pages reference checks across all the org's projects).+func (r *syntheticCheckRepository) FindByIdInOrganization(tx *sql.Tx, id int, organizationId int) (*models.SyntheticCheck, error) {+ return lit.SelectSingleNamed[models.SyntheticCheck](+ tx,+ "SELECT c.id, c.project_id, c.name, c.check_type, c.enabled, c.interval_seconds, c.timeout_seconds, c.config, c.failure_threshold, c.current_status, c.consecutive_failures, c.last_run_at, c.last_state_change_at, c.next_run_at, c.created_at, c.updated_at FROM synthetic_checks c JOIN projects p ON p.id = c.project_id WHERE c.id = :id AND p.organization_id = :organization_id",+ lit.P{"id": id, "organization_id": organizationId},+ )+}++func (r *syntheticCheckRepository) CountDownAll(tx *sql.Tx) (int, error) {+ result, err := lit.SelectSingleNamed[models.CountResult](+ tx,+ "SELECT COUNT(*) as count FROM synthetic_checks WHERE enabled = true AND current_status = 'down'",+ lit.P{},+ )+ if err != nil {+ return 0, err+ }+ if result == nil {+ return 0, nil+ }+ return result.Count, nil+}++func (r *syntheticCheckRepository) CountDownByProject(tx *sql.Tx, projectId uuid.UUID) (int, error) {+ result, err := lit.SelectSingleNamed[models.CountResult](+ tx,+ "SELECT COUNT(*) as count FROM synthetic_checks WHERE project_id = :project_id AND enabled = true AND current_status = 'down'",+ lit.P{"project_id": projectId},+ )+ if err != nil {+ return 0, err+ }+ if result == nil {+ return 0, nil+ }+ return result.Count, nil+}++var SyntheticCheckRepository = syntheticCheckRepository{}diff --git a/backend/app/repositories/transactional/pg/synthetic_runner.repository.go b/backend/app/repositories/transactional/pg/synthetic_runner.repository.gonew file mode 100644index 00000000..923ce33d--- /dev/null+++ b/backend/app/repositories/transactional/pg/synthetic_runner.repository.go@@ -0,0 +1,89 @@+//go:build transactional_pg++package pg++import (+ "database/sql"+ "time"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"++ "github.com/tracewayapp/lit/v2"+)++type syntheticRunnerRepository struct{}++const syntheticRunnerColumns = "id, name, version, first_seen_at, last_seen_at"++// UpsertSeen self-registers a runner by name on first contact and refreshes+// its liveness/version afterwards, returning the current row. A lost race on+// the unique name (two first polls at once) falls back to the winner's row.+func (r *syntheticRunnerRepository) UpsertSeen(tx *sql.Tx, name string, version string, now time.Time) (*models.SyntheticRunner, error) {+ existing, err := r.findByName(tx, name)+ if err != nil {+ return nil, err+ }+ if existing == nil {+ runner := &models.SyntheticRunner{+ Name: name,+ Version: version,+ FirstSeenAt: now.UTC(),+ LastSeenAt: now.UTC(),+ }+ id, insertErr := lit.Insert[models.SyntheticRunner](tx, runner)+ if insertErr == nil {+ runner.Id = id+ return runner, nil+ }+ existing, err = r.findByName(tx, name)+ if err != nil {+ return nil, err+ }+ if existing == nil {+ return nil, insertErr+ }+ }+ if version == "" {+ version = existing.Version+ }+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "UPDATE synthetic_runners SET last_seen_at = :now, version = :version WHERE id = :id",+ lit.P{"now": now.UTC(), "version": version, "id": existing.Id},+ )+ if err != nil {+ return nil, err+ }+ if err := lit.UpdateNative(tx, query, args...); err != nil {+ return nil, err+ }+ existing.Version = version+ existing.LastSeenAt = now.UTC()+ return existing, nil+}++func (r *syntheticRunnerRepository) findByName(tx *sql.Tx, name string) (*models.SyntheticRunner, error) {+ return lit.SelectSingleNamed[models.SyntheticRunner](+ tx,+ "SELECT "+syntheticRunnerColumns+" FROM synthetic_runners WHERE name = :name",+ lit.P{"name": name},+ )+}++func (r *syntheticRunnerRepository) CountOnline(tx *sql.Tx, since time.Time) (int, error) {+ result, err := lit.SelectSingleNamed[models.CountResult](+ tx,+ "SELECT COUNT(*) as count FROM synthetic_runners WHERE last_seen_at >= :since",+ lit.P{"since": since.UTC()},+ )+ if err != nil {+ return 0, err+ }+ if result == nil {+ return 0, nil+ }+ return result.Count, nil+}++var SyntheticRunnerRepository = syntheticRunnerRepository{}diff --git a/backend/app/repositories/transactional/sqlite/check_incident.repository.go b/backend/app/repositories/transactional/sqlite/check_incident.repository.gonew file mode 100644index 00000000..f81ae757--- /dev/null+++ b/backend/app/repositories/transactional/sqlite/check_incident.repository.go@@ -0,0 +1,59 @@+//go:build !transactional_pg++package sqlite++import (+ "database/sql"+ "time"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"++ "github.com/tracewayapp/lit/v2"+)++type checkIncidentRepository struct{}++const checkIncidentColumns = "id, check_id, project_id, started_at, resolved_at, error_message"++func (r *checkIncidentRepository) Open(tx *sql.Tx, incident *models.CheckIncident) (int, error) {+ return lit.Insert[models.CheckIncident](tx, incident)+}++func (r *checkIncidentRepository) FindOpenByCheck(tx *sql.Tx, checkId int) (*models.CheckIncident, error) {+ return lit.SelectSingleNamed[models.CheckIncident](+ tx,+ "SELECT "+checkIncidentColumns+" FROM check_incidents WHERE check_id = :check_id AND resolved_at IS NULL ORDER BY started_at DESC, id DESC LIMIT 1",+ lit.P{"check_id": checkId},+ )+}++func (r *checkIncidentRepository) Resolve(tx *sql.Tx, id int, resolvedAt time.Time) error {+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "UPDATE check_incidents SET resolved_at = :resolved_at WHERE id = :id AND resolved_at IS NULL",+ lit.P{"resolved_at": resolvedAt.UTC(), "id": id},+ )+ if err != nil {+ return err+ }+ return lit.UpdateNative(tx, query, args...)+}++func (r *checkIncidentRepository) FindRecentByCheck(tx *sql.Tx, checkId int, limit int) ([]*models.CheckIncident, error) {+ return lit.SelectNamed[models.CheckIncident](+ tx,+ "SELECT "+checkIncidentColumns+" FROM check_incidents WHERE check_id = :check_id ORDER BY started_at DESC, id DESC LIMIT :limit",+ lit.P{"check_id": checkId, "limit": limit},+ )+}++func (r *checkIncidentRepository) FindByCheckSince(tx *sql.Tx, checkId int, since time.Time) ([]*models.CheckIncident, error) {+ return lit.SelectNamed[models.CheckIncident](+ tx,+ "SELECT "+checkIncidentColumns+" FROM check_incidents WHERE check_id = :check_id AND (resolved_at IS NULL OR resolved_at >= :since) ORDER BY started_at DESC, id DESC",+ lit.P{"check_id": checkId, "since": since.UTC()},+ )+}++var CheckIncidentRepository = checkIncidentRepository{}diff --git a/backend/app/repositories/transactional/sqlite/check_run.repository.go b/backend/app/repositories/transactional/sqlite/check_run.repository.gonew file mode 100644index 00000000..9e2446c2--- /dev/null+++ b/backend/app/repositories/transactional/sqlite/check_run.repository.go@@ -0,0 +1,158 @@+//go:build !transactional_pg++package sqlite++import (+ "database/sql"+ "time"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"++ "github.com/tracewayapp/lit/v2"+)++type checkRunRepository struct{}++const checkRunColumns = "id, check_id, project_id, check_type, status, scheduled_for, expires_at, claimed_at, claimed_by, created_at"++// Enqueue inserts a queued run in the caller's transaction and returns its id.+func (r *checkRunRepository) Enqueue(tx *sql.Tx, run *models.CheckRun) (int, error) {+ return lit.Insert[models.CheckRun](tx, run)+}++func (r *checkRunRepository) FindById(tx *sql.Tx, id int) (*models.CheckRun, error) {+ return lit.SelectSingleNamed[models.CheckRun](+ tx,+ "SELECT "+checkRunColumns+" FROM check_runs WHERE id = :id",+ lit.P{"id": id},+ )+}++// FindClaimable returns queued, unexpired runs of the given types, oldest+// first. Types are matched positionally because lit has no IN-list expansion+// for named params; callers pass 1-3 types, padding is harmless.+func (r *checkRunRepository) FindClaimable(tx *sql.Tx, typeA string, typeB string, typeC string, now time.Time, limit int) ([]*models.CheckRun, error) {+ return lit.SelectNamed[models.CheckRun](+ tx,+ "SELECT "+checkRunColumns+" FROM check_runs WHERE status = 'queued' AND expires_at > :now AND check_type IN (:type_a, :type_b, :type_c) ORDER BY scheduled_for ASC, id ASC LIMIT :limit",+ lit.P{"now": now.UTC(), "type_a": typeA, "type_b": typeB, "type_c": typeC, "limit": limit},+ )+}++// FindClaimableBrowser returns queued, unexpired browser runs for the+// remote-runner poll endpoint. Runners are operator infrastructure serving+// the whole instance, so there is deliberately no tenant filter.+func (r *checkRunRepository) FindClaimableBrowser(tx *sql.Tx, now time.Time, limit int) ([]*models.CheckRun, error) {+ return lit.SelectNamed[models.CheckRun](+ tx,+ "SELECT id, check_id, project_id, check_type, status, scheduled_for, expires_at, claimed_at, claimed_by, created_at FROM check_runs WHERE status = 'queued' AND check_type = 'browser' AND expires_at > :now ORDER BY scheduled_for ASC, id ASC LIMIT :limit",+ lit.P{"now": now.UTC(), "limit": limit},+ )+}++// Claim transitions one run queued -> claimed. The status guard makes the+// claim lose against a concurrent claimer; returns whether the claim won,+// and callers must not execute when it lost.+func (r *checkRunRepository) Claim(tx *sql.Tx, id int, claimedBy string, now time.Time) (bool, error) {+ return guardedStatusUpdate(+ tx,+ "UPDATE check_runs SET status = 'claimed', claimed_at = :now, claimed_by = :claimed_by WHERE id = :id AND status = 'queued'",+ lit.P{"now": now.UTC(), "claimed_by": claimedBy, "id": id},+ )+}++// Delete removes a finalized run. The telemetry check_results row is the+// durable record; terminal queue rows are never kept.+func (r *checkRunRepository) Delete(tx *sql.Tx, id int) error {+ return lit.DeleteNamed(db.Driver, tx, "DELETE FROM check_runs WHERE id = :id", lit.P{"id": id})+}++// DeleteClaimedBy finalizes a run only while the caller still owns the claim.+// Zero rows means a stale-claim reclaim handed the run to someone else; the+// loser must discard its outcome instead of double-applying state.+func (r *checkRunRepository) DeleteClaimedBy(tx *sql.Tx, id int, claimedBy string) (bool, error) {+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "DELETE FROM check_runs WHERE id = :id AND status = 'claimed' AND claimed_by = :claimed_by",+ lit.P{"id": id, "claimed_by": claimedBy},+ )+ if err != nil {+ return false, err+ }+ result, err := tx.Exec(query, args...)+ if err != nil {+ return false, err+ }+ affected, err := result.RowsAffected()+ if err != nil {+ return false, err+ }+ return affected > 0, nil+}++// DeleteQueuedByCheck drops not-yet-claimed runs, used when a check is+// paused so stale probes don't fire on re-enable.+func (r *checkRunRepository) DeleteQueuedByCheck(tx *sql.Tx, checkId int) error {+ return lit.DeleteNamed(db.Driver, tx, "DELETE FROM check_runs WHERE check_id = :check_id AND status = 'queued'", lit.P{"check_id": checkId})+}++// ReclaimStaleClaimed returns runs claimed before the cutoff (the claimer+// died mid-execution) to queued so another executor can pick them up; their+// expires_at still bounds how stale a probe may run.+func (r *checkRunRepository) ReclaimStaleClaimed(tx *sql.Tx, cutoff time.Time) error {+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "UPDATE check_runs SET status = 'queued', claimed_at = NULL, claimed_by = '' WHERE status = 'claimed' AND claimed_at < :cutoff",+ lit.P{"cutoff": cutoff.UTC()},+ )+ if err != nil {+ return err+ }+ return lit.UpdateNative(tx, query, args...)+}++// FindExpiredQueued returns queued runs past their expiry, to be recorded as+// missed and deleted. Executing them late would corrupt the uptime timeline.+func (r *checkRunRepository) FindExpiredQueued(tx *sql.Tx, now time.Time, limit int) ([]*models.CheckRun, error) {+ return lit.SelectNamed[models.CheckRun](+ tx,+ "SELECT "+checkRunColumns+" FROM check_runs WHERE status = 'queued' AND expires_at <= :now ORDER BY expires_at ASC, id ASC LIMIT :limit",+ lit.P{"now": now.UTC(), "limit": limit},+ )+}++// HasPendingForCheck reports whether a queued or claimed run already exists,+// so run-now cannot pile up duplicates behind a stuck executor.+func (r *checkRunRepository) HasPendingForCheck(tx *sql.Tx, checkId int) (bool, error) {+ result, err := lit.SelectSingleNamed[models.CountResult](+ tx,+ "SELECT COUNT(*) as count FROM check_runs WHERE check_id = :check_id AND status IN ('queued', 'claimed')",+ lit.P{"check_id": checkId},+ )+ if err != nil {+ return false, err+ }+ return result != nil && result.Count > 0, nil+}++func (r *checkRunRepository) CountsForHealth(tx *sql.Tx) (*models.CheckRunHealthCounts, error) {+ return lit.SelectSingleNamed[models.CheckRunHealthCounts](+ tx,+ "SELECT COALESCE(SUM(CASE WHEN status = 'queued' THEN 1 ELSE 0 END), 0) AS queued_count, COALESCE(SUM(CASE WHEN status = 'claimed' THEN 1 ELSE 0 END), 0) AS claimed_count FROM check_runs",+ lit.P{},+ )+}++// OldestQueued returns the queued run with the earliest scheduled_for, or+// nil. A plain-column select, because SQLite loses type affinity on+// timestamp aggregates.+func (r *checkRunRepository) OldestQueued(tx *sql.Tx) (*models.CheckRun, error) {+ return lit.SelectSingleNamed[models.CheckRun](+ tx,+ "SELECT "+checkRunColumns+" FROM check_runs WHERE status = 'queued' ORDER BY scheduled_for ASC, id ASC LIMIT 1",+ lit.P{},+ )+}++var CheckRunRepository = checkRunRepository{}diff --git a/backend/app/repositories/transactional/sqlite/notification_rule.repository.go b/backend/app/repositories/transactional/sqlite/notification_rule.repository.goindex 4df3f858..a90ecf63 100644--- a/backend/app/repositories/transactional/sqlite/notification_rule.repository.go+++ b/backend/app/repositories/transactional/sqlite/notification_rule.repository.go@@ -44,7 +44,7 @@ func (r *notificationRuleRepository) FindEnabledPolledRules(tx *sql.Tx) ([]*modeFROM notification_rules rJOIN notification_channels c ON c.id = r.channel_idWHERE r.enabled = true AND c.enabled = true- AND r.rule_type NOT IN ('new_error', 'error_regression', 'ai_trace_cost', 'ai_conversation_cost', 'ai_flagged_content')`,+ AND r.rule_type NOT IN ('new_error', 'error_regression', 'ai_trace_cost', 'ai_conversation_cost', 'ai_flagged_content', 'check_down')`,)}@@ -56,7 +56,7 @@ func (r *notificationRuleRepository) FindEnabledEventRules(tx *sql.Tx, projectIdFROM notification_rules rJOIN notification_channels c ON c.id = r.channel_idWHERE r.project_id = :project_id AND r.enabled = true AND c.enabled = true- AND r.rule_type IN ('new_error', 'error_regression', 'ai_trace_cost', 'ai_conversation_cost', 'ai_flagged_content')`,+ AND r.rule_type IN ('new_error', 'error_regression', 'ai_trace_cost', 'ai_conversation_cost', 'ai_flagged_content', 'check_down')`,lit.P{"project_id": projectId},)}diff --git a/backend/app/repositories/transactional/sqlite/page.repository.go b/backend/app/repositories/transactional/sqlite/page.repository.goindex f35f648d..45e107bc 100644--- a/backend/app/repositories/transactional/sqlite/page.repository.go+++ b/backend/app/repositories/transactional/sqlite/page.repository.go@@ -166,4 +166,14 @@ func (r *pageRepository) Resolve(tx *sql.Tx, id int, userId int, now time.Time))}+// ResolveSystem resolves a page with no resolving user, for system-driven+// resolution (a synthetic check recovering). Same guard as Resolve.+func (r *pageRepository) ResolveSystem(tx *sql.Tx, id int, now time.Time) (bool, error) {+ return guardedStatusUpdate(+ tx,+ "UPDATE pages SET status = 'resolved', resolved_by = NULL, resolved_at = :now, next_escalation_at = NULL, updated_at = :now WHERE id = :id AND status <> 'resolved'",+ lit.P{"now": now.UTC(), "id": id},+ )+}+var PageRepository = pageRepository{}diff --git a/backend/app/repositories/transactional/sqlite/status_page.repository.go b/backend/app/repositories/transactional/sqlite/status_page.repository.gonew file mode 100644index 00000000..2b79dd33--- /dev/null+++ b/backend/app/repositories/transactional/sqlite/status_page.repository.go@@ -0,0 +1,83 @@+//go:build !transactional_pg++package sqlite++import (+ "database/sql"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"++ "github.com/tracewayapp/lit/v2"+)++type statusPageRepository struct{}++const statusPageColumns = "id, organization_id, slug, name, is_public, check_ids, description, logo_key, custom_domain, created_at, updated_at"++func (r *statusPageRepository) Create(tx *sql.Tx, page *models.StatusPage) (int, error) {+ return lit.Insert[models.StatusPage](tx, page)+}++func (r *statusPageRepository) Update(tx *sql.Tx, page *models.StatusPage) error {+ return lit.UpdateNamed(tx, page, "id = :id", lit.P{"id": page.Id})+}++func (r *statusPageRepository) Delete(tx *sql.Tx, id int, organizationId int) error {+ return lit.DeleteNamed(db.Driver, tx, "DELETE FROM status_pages WHERE id = :id AND organization_id = :organization_id", lit.P{"id": id, "organization_id": organizationId})+}++func (r *statusPageRepository) FindByIdForOrganization(tx *sql.Tx, id int, organizationId int) (*models.StatusPage, error) {+ return lit.SelectSingleNamed[models.StatusPage](+ tx,+ "SELECT "+statusPageColumns+" FROM status_pages WHERE id = :id AND organization_id = :organization_id",+ lit.P{"id": id, "organization_id": organizationId},+ )+}++func (r *statusPageRepository) ListByOrganization(tx *sql.Tx, organizationId int) ([]*models.StatusPage, error) {+ return lit.SelectNamed[models.StatusPage](+ tx,+ "SELECT "+statusPageColumns+" FROM status_pages WHERE organization_id = :organization_id ORDER BY name ASC, id ASC",+ lit.P{"organization_id": organizationId},+ )+}++func (r *statusPageRepository) FindBySlug(tx *sql.Tx, slug string) (*models.StatusPage, error) {+ return lit.SelectSingleNamed[models.StatusPage](+ tx,+ "SELECT "+statusPageColumns+" FROM status_pages WHERE slug = :slug",+ lit.P{"slug": slug},+ )+}++// FindPublicBySlug backs the anonymous status endpoint: private pages are+// indistinguishable from missing ones.+func (r *statusPageRepository) FindPublicBySlug(tx *sql.Tx, slug string) (*models.StatusPage, error) {+ return lit.SelectSingleNamed[models.StatusPage](+ tx,+ "SELECT "+statusPageColumns+" FROM status_pages WHERE slug = :slug AND is_public = true",+ lit.P{"slug": slug},+ )+}++// FindByCustomDomain backs the create/update uniqueness check.+func (r *statusPageRepository) FindByCustomDomain(tx *sql.Tx, domain string) (*models.StatusPage, error) {+ return lit.SelectSingleNamed[models.StatusPage](+ tx,+ "SELECT "+statusPageColumns+" FROM status_pages WHERE custom_domain <> '' AND custom_domain = :domain",+ lit.P{"domain": domain},+ )+}++// FindPublicByCustomDomain resolves a vanity host (CNAME to this instance)+// to its status page.+func (r *statusPageRepository) FindPublicByCustomDomain(tx *sql.Tx, domain string) (*models.StatusPage, error) {+ return lit.SelectSingleNamed[models.StatusPage](+ tx,+ "SELECT "+statusPageColumns+" FROM status_pages WHERE custom_domain <> '' AND custom_domain = :domain AND is_public = true",+ lit.P{"domain": domain},+ )+}++var StatusPageRepository = statusPageRepository{}diff --git a/backend/app/repositories/transactional/sqlite/synthetic_check.repository.go b/backend/app/repositories/transactional/sqlite/synthetic_check.repository.gonew file mode 100644index 00000000..116c6a5b--- /dev/null+++ b/backend/app/repositories/transactional/sqlite/synthetic_check.repository.go@@ -0,0 +1,168 @@+//go:build !transactional_pg++package sqlite++import (+ "database/sql"+ "time"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"++ "github.com/google/uuid"+ "github.com/tracewayapp/lit/v2"+)++type syntheticCheckRepository struct{}++const syntheticCheckColumns = "id, project_id, name, check_type, enabled, interval_seconds, timeout_seconds, config, failure_threshold, current_status, consecutive_failures, last_run_at, last_state_change_at, next_run_at, created_at, updated_at"++func (r *syntheticCheckRepository) Create(tx *sql.Tx, check *models.SyntheticCheck) (int, error) {+ return lit.Insert[models.SyntheticCheck](tx, check)+}++// Update writes only the user-editable columns. The run-state columns+// (current_status, consecutive_failures, last_run_at, last_state_change_at)+// belong to ApplyRunState; a full-row update here could revert a concurrent+// executor finalization on PostgreSQL.+func (r *syntheticCheckRepository) Update(tx *sql.Tx, check *models.SyntheticCheck) error {+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "UPDATE synthetic_checks SET name = :name, enabled = :enabled, interval_seconds = :interval_seconds, timeout_seconds = :timeout_seconds, config = :config, failure_threshold = :failure_threshold, next_run_at = :next_run_at, updated_at = :updated_at WHERE id = :id",+ lit.P{+ "name": check.Name,+ "enabled": check.Enabled,+ "interval_seconds": check.IntervalSeconds,+ "timeout_seconds": check.TimeoutSeconds,+ "config": check.Config,+ "failure_threshold": check.FailureThreshold,+ "next_run_at": check.NextRunAt.UTC(),+ "updated_at": check.UpdatedAt.UTC(),+ "id": check.Id,+ },+ )+ if err != nil {+ return err+ }+ return lit.UpdateNative(tx, query, args...)+}++func (r *syntheticCheckRepository) Delete(tx *sql.Tx, id int, projectId uuid.UUID) error {+ return lit.DeleteNamed(db.Driver, tx, "DELETE FROM synthetic_checks WHERE id = :id AND project_id = :project_id", lit.P{"id": id, "project_id": projectId})+}++func (r *syntheticCheckRepository) FindById(tx *sql.Tx, id int) (*models.SyntheticCheck, error) {+ return lit.SelectSingleNamed[models.SyntheticCheck](+ tx,+ "SELECT "+syntheticCheckColumns+" FROM synthetic_checks WHERE id = :id",+ lit.P{"id": id},+ )+}++func (r *syntheticCheckRepository) FindByIdForProject(tx *sql.Tx, id int, projectId uuid.UUID) (*models.SyntheticCheck, error) {+ return lit.SelectSingleNamed[models.SyntheticCheck](+ tx,+ "SELECT "+syntheticCheckColumns+" FROM synthetic_checks WHERE id = :id AND project_id = :project_id",+ lit.P{"id": id, "project_id": projectId},+ )+}++func (r *syntheticCheckRepository) FindByProject(tx *sql.Tx, projectId uuid.UUID) ([]*models.SyntheticCheck, error) {+ return lit.SelectNamed[models.SyntheticCheck](+ tx,+ "SELECT "+syntheticCheckColumns+" FROM synthetic_checks WHERE project_id = :project_id ORDER BY name ASC, id ASC",+ lit.P{"project_id": projectId},+ )+}++// FindDueEnabled returns enabled checks whose next run time has passed,+// oldest-due first.+func (r *syntheticCheckRepository) FindDueEnabled(tx *sql.Tx, now time.Time, limit int) ([]*models.SyntheticCheck, error) {+ return lit.SelectNamed[models.SyntheticCheck](+ tx,+ "SELECT "+syntheticCheckColumns+" FROM synthetic_checks WHERE enabled = true AND next_run_at <= :now ORDER BY next_run_at ASC, id ASC LIMIT :limit",+ lit.P{"now": now.UTC(), "limit": limit},+ )+}++// SetNextRun advances the schedule pointer. Called in the same transaction+// that enqueues the run row, so multi-instance schedulers (behind the+// advisory lock) never double-enqueue an interval.+func (r *syntheticCheckRepository) SetNextRun(tx *sql.Tx, id int, nextRunAt time.Time) error {+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "UPDATE synthetic_checks SET next_run_at = :next_run_at WHERE id = :id",+ lit.P{"next_run_at": nextRunAt.UTC(), "id": id},+ )+ if err != nil {+ return err+ }+ return lit.UpdateNative(tx, query, args...)+}++// ApplyRunState persists the outcome of one executed run on the check row.+// lastStateChangeAt is only written on transitions (nil leaves it untouched).+func (r *syntheticCheckRepository) ApplyRunState(tx *sql.Tx, id int, currentStatus string, consecutiveFailures int, lastRunAt time.Time, lastStateChangeAt *time.Time) error {+ if lastStateChangeAt != nil {+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "UPDATE synthetic_checks SET current_status = :current_status, consecutive_failures = :consecutive_failures, last_run_at = :last_run_at, last_state_change_at = :last_state_change_at WHERE id = :id",+ lit.P{"current_status": currentStatus, "consecutive_failures": consecutiveFailures, "last_run_at": lastRunAt.UTC(), "last_state_change_at": lastStateChangeAt.UTC(), "id": id},+ )+ if err != nil {+ return err+ }+ return lit.UpdateNative(tx, query, args...)+ }+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "UPDATE synthetic_checks SET current_status = :current_status, consecutive_failures = :consecutive_failures, last_run_at = :last_run_at WHERE id = :id",+ lit.P{"current_status": currentStatus, "consecutive_failures": consecutiveFailures, "last_run_at": lastRunAt.UTC(), "id": id},+ )+ if err != nil {+ return err+ }+ return lit.UpdateNative(tx, query, args...)+}++// FindByIdInOrganization scopes a check lookup to an organization (status+// pages reference checks across all the org's projects).+func (r *syntheticCheckRepository) FindByIdInOrganization(tx *sql.Tx, id int, organizationId int) (*models.SyntheticCheck, error) {+ return lit.SelectSingleNamed[models.SyntheticCheck](+ tx,+ "SELECT c.id, c.project_id, c.name, c.check_type, c.enabled, c.interval_seconds, c.timeout_seconds, c.config, c.failure_threshold, c.current_status, c.consecutive_failures, c.last_run_at, c.last_state_change_at, c.next_run_at, c.created_at, c.updated_at FROM synthetic_checks c JOIN projects p ON p.id = c.project_id WHERE c.id = :id AND p.organization_id = :organization_id",+ lit.P{"id": id, "organization_id": organizationId},+ )+}++func (r *syntheticCheckRepository) CountDownAll(tx *sql.Tx) (int, error) {+ result, err := lit.SelectSingleNamed[models.CountResult](+ tx,+ "SELECT COUNT(*) as count FROM synthetic_checks WHERE enabled = true AND current_status = 'down'",+ lit.P{},+ )+ if err != nil {+ return 0, err+ }+ if result == nil {+ return 0, nil+ }+ return result.Count, nil+}++func (r *syntheticCheckRepository) CountDownByProject(tx *sql.Tx, projectId uuid.UUID) (int, error) {+ result, err := lit.SelectSingleNamed[models.CountResult](+ tx,+ "SELECT COUNT(*) as count FROM synthetic_checks WHERE project_id = :project_id AND enabled = true AND current_status = 'down'",+ lit.P{"project_id": projectId},+ )+ if err != nil {+ return 0, err+ }+ if result == nil {+ return 0, nil+ }+ return result.Count, nil+}++var SyntheticCheckRepository = syntheticCheckRepository{}diff --git a/backend/app/repositories/transactional/sqlite/synthetic_runner.repository.go b/backend/app/repositories/transactional/sqlite/synthetic_runner.repository.gonew file mode 100644index 00000000..d7cb19db--- /dev/null+++ b/backend/app/repositories/transactional/sqlite/synthetic_runner.repository.go@@ -0,0 +1,89 @@+//go:build !transactional_pg++package sqlite++import (+ "database/sql"+ "time"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"++ "github.com/tracewayapp/lit/v2"+)++type syntheticRunnerRepository struct{}++const syntheticRunnerColumns = "id, name, version, first_seen_at, last_seen_at"++// UpsertSeen self-registers a runner by name on first contact and refreshes+// its liveness/version afterwards, returning the current row. A lost race on+// the unique name (two first polls at once) falls back to the winner's row.+func (r *syntheticRunnerRepository) UpsertSeen(tx *sql.Tx, name string, version string, now time.Time) (*models.SyntheticRunner, error) {+ existing, err := r.findByName(tx, name)+ if err != nil {+ return nil, err+ }+ if existing == nil {+ runner := &models.SyntheticRunner{+ Name: name,+ Version: version,+ FirstSeenAt: now.UTC(),+ LastSeenAt: now.UTC(),+ }+ id, insertErr := lit.Insert[models.SyntheticRunner](tx, runner)+ if insertErr == nil {+ runner.Id = id+ return runner, nil+ }+ existing, err = r.findByName(tx, name)+ if err != nil {+ return nil, err+ }+ if existing == nil {+ return nil, insertErr+ }+ }+ if version == "" {+ version = existing.Version+ }+ query, args, err := lit.ParseNamedQuery(+ db.Driver,+ "UPDATE synthetic_runners SET last_seen_at = :now, version = :version WHERE id = :id",+ lit.P{"now": now.UTC(), "version": version, "id": existing.Id},+ )+ if err != nil {+ return nil, err+ }+ if err := lit.UpdateNative(tx, query, args...); err != nil {+ return nil, err+ }+ existing.Version = version+ existing.LastSeenAt = now.UTC()+ return existing, nil+}++func (r *syntheticRunnerRepository) findByName(tx *sql.Tx, name string) (*models.SyntheticRunner, error) {+ return lit.SelectSingleNamed[models.SyntheticRunner](+ tx,+ "SELECT "+syntheticRunnerColumns+" FROM synthetic_runners WHERE name = :name",+ lit.P{"name": name},+ )+}++func (r *syntheticRunnerRepository) CountOnline(tx *sql.Tx, since time.Time) (int, error) {+ result, err := lit.SelectSingleNamed[models.CountResult](+ tx,+ "SELECT COUNT(*) as count FROM synthetic_runners WHERE last_seen_at >= :since",+ lit.P{"since": since.UTC()},+ )+ if err != nil {+ return 0, err+ }+ if result == nil {+ return 0, nil+ }+ return result.Count, nil+}++var SyntheticRunnerRepository = syntheticRunnerRepository{}diff --git a/backend/app/repositories/transactional/transactional_pg.go b/backend/app/repositories/transactional/transactional_pg.goindex ea01e64b..89484981 100644--- a/backend/app/repositories/transactional/transactional_pg.go+++ b/backend/app/repositories/transactional/transactional_pg.go@@ -6,6 +6,8 @@ import pgrepo "github.com/tracewayapp/traceway/backend/app/repositories/transactvar (AuthorizationCodeRepository = pgrepo.AuthorizationCodeRepository+ CheckIncidentRepository = pgrepo.CheckIncidentRepository+ CheckRunRepository = pgrepo.CheckRunRepositoryDashboardRepository = pgrepo.DashboardRepositoryDashboardTemplateRepository = pgrepo.DashboardTemplateRepositoryDeviceAuthorizationRepository = pgrepo.DeviceAuthorizationRepository@@ -26,6 +28,9 @@ var (ProjectRepository = pgrepo.ProjectRepositoryProjectUserRoleRepository = pgrepo.ProjectUserRoleRepositoryRefreshTokenRepository = pgrepo.RefreshTokenRepository+ StatusPageRepository = pgrepo.StatusPageRepository+ SyntheticCheckRepository = pgrepo.SyntheticCheckRepository+ SyntheticRunnerRepository = pgrepo.SyntheticRunnerRepositoryTeamRepository = pgrepo.TeamRepositoryUserContactMethodRepository = pgrepo.UserContactMethodRepositoryUserNotificationRuleRepository = pgrepo.UserNotificationRuleRepositorydiff --git a/backend/app/repositories/transactional/transactional_sqlite.go b/backend/app/repositories/transactional/transactional_sqlite.goindex a797335b..3b7754c9 100644--- a/backend/app/repositories/transactional/transactional_sqlite.go+++ b/backend/app/repositories/transactional/transactional_sqlite.go@@ -6,6 +6,8 @@ import sqliterepo "github.com/tracewayapp/traceway/backend/app/repositories/tranvar (AuthorizationCodeRepository = sqliterepo.AuthorizationCodeRepository+ CheckIncidentRepository = sqliterepo.CheckIncidentRepository+ CheckRunRepository = sqliterepo.CheckRunRepositoryDashboardRepository = sqliterepo.DashboardRepositoryDashboardTemplateRepository = sqliterepo.DashboardTemplateRepositoryDeviceAuthorizationRepository = sqliterepo.DeviceAuthorizationRepository@@ -26,6 +28,9 @@ var (ProjectRepository = sqliterepo.ProjectRepositoryProjectUserRoleRepository = sqliterepo.ProjectUserRoleRepositoryRefreshTokenRepository = sqliterepo.RefreshTokenRepository+ StatusPageRepository = sqliterepo.StatusPageRepository+ SyntheticCheckRepository = sqliterepo.SyntheticCheckRepository+ SyntheticRunnerRepository = sqliterepo.SyntheticRunnerRepositoryTeamRepository = sqliterepo.TeamRepositoryUserContactMethodRepository = sqliterepo.UserContactMethodRepositoryUserNotificationRuleRepository = sqliterepo.UserNotificationRuleRepositorydiff --git a/backend/app/retention/retention.go b/backend/app/retention/retention.goindex 0df631d8..c361f732 100644--- a/backend/app/retention/retention.go+++ b/backend/app/retention/retention.go@@ -23,6 +23,7 @@ func Start(ctx context.Context) {startLogRecordsCap(ctx, parseMaxRows(cfg.LogRecordsMaxRows))startRecordingDiskCleanup(ctx, parseRetentionDays(cfg.SessionRecordingRetentionDays))startProfileArchiveDiskCleanup(ctx, parseRetentionDays(cfg.ProfileRetentionDays))+ startSyntheticsScreenshotCleanup(ctx, parseRetentionDays(cfg.SyntheticsScreenshotRetentionDays))startOAuthSessionsPrune(ctx)startAuthTokensPrune(ctx)startOutboxPrune(ctx)diff --git a/backend/app/retention/sqlite.go b/backend/app/retention/sqlite.goindex efabd7a4..1028ecb7 100644--- a/backend/app/retention/sqlite.go+++ b/backend/app/retention/sqlite.go@@ -22,6 +22,7 @@ var telemetryRetentionTargets = []struct {{"metric_points", "recorded_at"},{"session_recordings", "recorded_at"},{"fired_notifications", "fired_at"},+ {"check_results", "recorded_at"},{"ai_traces", "recorded_at"},{"log_records", "timestamp"},{"sessions", "started_at"},diff --git a/backend/app/retention/synthetics.go b/backend/app/retention/synthetics.gonew file mode 100644index 00000000..1feb0ddf--- /dev/null+++ b/backend/app/retention/synthetics.go@@ -0,0 +1,67 @@+package retention++import (+ "context"+ "fmt"+ "path/filepath"+ "time"++ "github.com/tracewayapp/traceway/backend/app/config"+ traceway "go.tracewayapp.com"+)++const syntheticsSubdir = "synthetics"++// startSyntheticsScreenshotCleanup ages out browser-check failure screenshots+// written to local disk under <STORAGE_PATH>/synthetics/. The check_results+// rows referencing them are pruned by the telemetry retention (SQLite worker+// or ClickHouse TTL); the two are deliberately not coupled, mirroring the+// session-recording split.+func startSyntheticsScreenshotCleanup(ctx context.Context, days int) {+ if days == 0 {+ return+ }+ cfg := config.Config+ storageType := cfg.StorageType+ if storageType == "" {+ storageType = "local"+ }+ if storageType != "local" {+ return+ }++ basePath := cfg.StoragePath+ if basePath == "" {+ basePath = "./storage"+ }+ abs, err := filepath.Abs(basePath)+ if err != nil {+ traceway.CaptureException(fmt.Errorf("retention: cannot resolve storage path %q: %w", basePath, err))+ return+ }+ screenshotsDir := filepath.Clean(filepath.Join(abs, syntheticsSubdir))++ if !isSafeStorageSubdir(screenshotsDir) {+ traceway.CaptureException(fmt.Errorf("retention: refusing to clean shallow synthetics dir %q — set STORAGE_PATH to a dedicated directory", screenshotsDir))+ return+ }++ config.Logf("Starting synthetics screenshot disk cleanup worker (TTL: %d days, dir: %s)", days, screenshotsDir)++ go func() {+ defer traceway.Recover()++ runDirAgeCleanup(screenshotsDir, days)++ ticker := time.NewTicker(tickInterval)+ defer ticker.Stop()+ for {+ select {+ case <-ctx.Done():+ return+ case <-ticker.C:+ runDirAgeCleanup(screenshotsDir, days)+ }+ }+ }()+}diff --git a/backend/app/synthetics/browserexec/browserexec.go b/backend/app/synthetics/browserexec/browserexec.gonew file mode 100644index 00000000..57214f07--- /dev/null+++ b/backend/app/synthetics/browserexec/browserexec.go@@ -0,0 +1,333 @@+// Package browserexec runs @playwright/test specs by spawning Node against a+// prepared harness directory (package.json + node_modules with a pinned+// @playwright/test). It is shared by the embedded browser executor and the+// standalone traceway-runner binary. The harness never uses npm/npx at+// runtime: the Playwright CLI is invoked as+// node <harness>/node_modules/@playwright/test/cli.js.+package browserexec++import (+ "context"+ "encoding/json"+ "fmt"+ "os"+ "os/exec"+ "path/filepath"+ "regexp"+ "runtime"+ "strings"+ "time"+)++type Options struct {+ // HarnessDir holds package.json + node_modules with @playwright/test.+ HarnessDir string+ // Script is the full @playwright/test spec text.+ Script string+ // Env is the check-scoped environment passed to the spec. The parent+ // process environment is deliberately NOT inherited: user scripts must+ // never see JWT_SECRET, DB credentials, or anything else from the server.+ Env map[string]string+ // Timeout bounds the whole run; the per-test Playwright timeout is set+ // slightly below it so test failures surface as test errors, not kills.+ Timeout time.Duration+}++type Result struct {+ Passed bool+ DurationMs float64+ ErrorMsg string+ // Screenshot is the first failure screenshot Playwright captured, if any.+ Screenshot []byte+ // Output is the tail of stdout+stderr for runs that died before the JSON+ // report existed.+ Output string+}++const maxOutputBytes = 16 << 10++// Validate reports whether browser checks can execute with this harness:+// node resolvable and the Playwright CLI present.+func Validate(harnessDir string) error {+ if _, err := exec.LookPath("node"); err != nil {+ return fmt.Errorf("node is not on PATH: %w", err)+ }+ cli := filepath.Join(harnessDir, "node_modules", "@playwright", "test", "cli.js")+ if _, err := os.Stat(cli); err != nil {+ return fmt.Errorf("playwright CLI not found at %s (install @playwright/test in the harness directory): %w", cli, err)+ }+ return nil+}++// Run executes one spec and parses the JSON reporter output.+func Run(ctx context.Context, opts Options) (*Result, error) {+ // The run dir lives INSIDE the harness dir so Node module resolution+ // walks up into the harness node_modules from the spec file.+ runsDir := filepath.Join(opts.HarnessDir, ".runs")+ if err := os.MkdirAll(runsDir, 0o755); err != nil {+ return nil, fmt.Errorf("failed to create runs dir: %w", err)+ }+ runDir, err := os.MkdirTemp(runsDir, "run-*")+ if err != nil {+ return nil, fmt.Errorf("failed to create run dir: %w", err)+ }+ defer os.RemoveAll(runDir)++ specDir := filepath.Join(runDir, "spec")+ outputDir := filepath.Join(runDir, "output")+ homeDir := filepath.Join(runDir, "home")+ for _, dir := range []string{specDir, outputDir, homeDir} {+ if err := os.MkdirAll(dir, 0o755); err != nil {+ return nil, fmt.Errorf("failed to create run subdir: %w", err)+ }+ }+ if err := os.WriteFile(filepath.Join(specDir, "check.spec.ts"), []byte(opts.Script), 0o644); err != nil {+ return nil, fmt.Errorf("failed to write spec: %w", err)+ }++ // The per-test timeout stays under the hard deadline so assertion+ // failures and hangs surface as Playwright errors instead of a kill.+ testTimeout := opts.Timeout - 5*time.Second+ if testTimeout < 5*time.Second {+ testTimeout = opts.Timeout * 8 / 10+ }+ configPath := filepath.Join(runDir, "traceway.config.cjs")+ configSrc := fmt.Sprintf(`module.exports = {+ testDir: %q,+ outputDir: %q,+ timeout: %d,+ retries: 0,+ workers: 1,+ reporter: [['json']],+ use: {+ headless: true,+ screenshot: 'only-on-failure',+ launchOptions: { args: ['--no-sandbox', '--disable-dev-shm-usage'] },+ },+};+`, specDir, outputDir, testTimeout.Milliseconds())+ if err := os.WriteFile(configPath, []byte(configSrc), 0o644); err != nil {+ return nil, fmt.Errorf("failed to write config: %w", err)+ }++ reportPath := filepath.Join(runDir, "report.json")+ cli := filepath.Join(opts.HarnessDir, "node_modules", "@playwright", "test", "cli.js")++ cmd := exec.CommandContext(ctx, "node", cli, "test", "--config", configPath)+ cmd.Dir = opts.HarnessDir+ // A leaked descendant holding the output pipe (a daemon the user script+ // spawned, or Chromium surviving the plain kill on Windows) must not wedge+ // this worker forever: force the pipes closed shortly after node exits or+ // the deadline kills it.+ cmd.WaitDelay = 10 * time.Second+ // Allowlisted environment only; see Options.Env.+ env := []string{+ "PATH=" + os.Getenv("PATH"),+ "HOME=" + homeDir,+ "TMPDIR=" + runDir,+ "PLAYWRIGHT_JSON_OUTPUT_NAME=" + reportPath,+ }+ // HOME is sandboxed to the run dir, which would also hide Playwright's+ // default per-user browser cache; resolve it from the REAL home first.+ browsers := os.Getenv("PLAYWRIGHT_BROWSERS_PATH")+ if browsers == "" {+ browsers = defaultBrowsersPath()+ }+ if browsers != "" {+ env = append(env, "PLAYWRIGHT_BROWSERS_PATH="+browsers)+ }+ for name, value := range opts.Env {+ name = strings.TrimSpace(name)+ if name == "" || strings.ContainsAny(name, "=\x00") {+ continue+ }+ env = append(env, name+"="+value)+ }+ cmd.Env = env+ configureProcessGroup(cmd)++ output, runErr := cmd.CombinedOutput()+ if len(output) > maxOutputBytes {+ output = output[len(output)-maxOutputBytes:]+ }++ result := &Result{Output: string(output)}++ report, reportErr := os.ReadFile(reportPath)+ if reportErr != nil {+ // The runner died before writing a report (bad node install, OOM,+ // killed by the deadline).+ if ctx.Err() != nil {+ result.ErrorMsg = "the test run exceeded its timeout and was killed"+ } else if runErr != nil {+ result.ErrorMsg = "playwright did not produce a report: " + firstOutputLines(string(output), 5)+ } else {+ result.ErrorMsg = "playwright did not produce a report"+ }+ return result, nil+ }++ parsed, err := parseReport(report)+ if err != nil {+ result.ErrorMsg = "failed to parse the playwright report: " + err.Error()+ return result, nil+ }+ result.Passed = parsed.passed+ result.DurationMs = parsed.durationMs+ result.ErrorMsg = parsed.errorMsg+ if parsed.screenshotPath != "" {+ if data, err := os.ReadFile(parsed.screenshotPath); err == nil {+ result.Screenshot = data+ }+ }+ return result, nil+}++type reportSummary struct {+ passed bool+ durationMs float64+ errorMsg string+ screenshotPath string+}++type jsonReport struct {+ Suites []jsonSuite `json:"suites"`+ Errors []jsonError `json:"errors"`+ Stats struct {+ Duration float64 `json:"duration"`+ Expected int `json:"expected"`+ Unexpected int `json:"unexpected"`+ } `json:"stats"`+}++type jsonSuite struct {+ Suites []jsonSuite `json:"suites"`+ Specs []jsonSpec `json:"specs"`+}++type jsonSpec struct {+ Title string `json:"title"`+ Ok bool `json:"ok"`+ Tests []jsonTest `json:"tests"`+}++type jsonTest struct {+ Results []jsonTestResult `json:"results"`+}++type jsonTestResult struct {+ Status string `json:"status"`+ Duration float64 `json:"duration"`+ Error *jsonError `json:"error"`+ Errors []jsonError `json:"errors"`+ Attachments []jsonAttachment `json:"attachments"`+}++type jsonError struct {+ Message string `json:"message"`+}++type jsonAttachment struct {+ Name string `json:"name"`+ ContentType string `json:"contentType"`+ Path string `json:"path"`+}++func parseReport(data []byte) (*reportSummary, error) {+ var report jsonReport+ if err := json.Unmarshal(data, &report); err != nil {+ return nil, err+ }++ summary := &reportSummary{passed: true, durationMs: report.Stats.Duration}+ specCount := 0+ var walk func(suite jsonSuite)+ walk = func(suite jsonSuite) {+ for _, spec := range suite.Specs {+ specCount+++ if !spec.Ok {+ summary.passed = false+ }+ for _, test := range spec.Tests {+ for _, testResult := range test.Results {+ if testResult.Status == "passed" || testResult.Status == "skipped" {+ continue+ }+ if summary.errorMsg == "" {+ summary.errorMsg = spec.Title + ": " + stripAnsi(firstErrorMessage(testResult))+ }+ if summary.screenshotPath == "" {+ for _, attachment := range testResult.Attachments {+ if attachment.ContentType == "image/png" && attachment.Path != "" {+ summary.screenshotPath = attachment.Path+ break+ }+ }+ }+ }+ }+ }+ for _, child := range suite.Suites {+ walk(child)+ }+ }+ for _, suite := range report.Suites {+ walk(suite)+ }++ if specCount == 0 {+ summary.passed = false+ summary.errorMsg = "the script contains no tests"+ if len(report.Errors) > 0 {+ summary.errorMsg = stripAnsi(report.Errors[0].Message)+ }+ }+ return summary, nil+}++func firstErrorMessage(result jsonTestResult) string {+ if result.Error != nil && result.Error.Message != "" {+ return result.Error.Message+ }+ for _, e := range result.Errors {+ if e.Message != "" {+ return e.Message+ }+ }+ return "test " + result.Status+}++// defaultBrowsersPath mirrors Playwright's per-OS registry default, needed+// because the subprocess runs with a sandboxed HOME.+func defaultBrowsersPath() string {+ home, err := os.UserHomeDir()+ if err != nil {+ return ""+ }+ switch runtime.GOOS {+ case "darwin":+ return filepath.Join(home, "Library", "Caches", "ms-playwright")+ case "windows":+ return filepath.Join(home, "AppData", "Local", "ms-playwright")+ default:+ return filepath.Join(home, ".cache", "ms-playwright")+ }+}++var ansiPattern = regexp.MustCompile(`\x1b\[[0-9;]*m`)++func stripAnsi(s string) string {+ s = ansiPattern.ReplaceAllString(s, "")+ if len(s) > 2000 {+ s = s[:2000]+ }+ return s+}++func firstOutputLines(output string, n int) string {+ lines := strings.Split(strings.TrimSpace(output), "\n")+ if len(lines) > n {+ lines = lines[:n]+ }+ return stripAnsi(strings.Join(lines, " | "))+}diff --git a/backend/app/synthetics/browserexec/browserexec_live_test.go b/backend/app/synthetics/browserexec/browserexec_live_test.gonew file mode 100644index 00000000..4cc3b6f4--- /dev/null+++ b/backend/app/synthetics/browserexec/browserexec_live_test.go@@ -0,0 +1,107 @@+package browserexec++import (+ "context"+ "net/http"+ "net/http/httptest"+ "os"+ "strings"+ "testing"+ "time"+)++// TestRunLive executes real Playwright specs against a local server. Skipped+// unless TRACEWAY_BROWSEREXEC_LIVE_HARNESS points at a harness directory with+// @playwright/test and Chromium installed (CI does not run browsers).+func TestRunLive(t *testing.T) {+ harness := os.Getenv("TRACEWAY_BROWSEREXEC_LIVE_HARNESS")+ if harness == "" {+ t.Skip("TRACEWAY_BROWSEREXEC_LIVE_HARNESS not set")+ }+ if err := Validate(harness); err != nil {+ t.Fatalf("harness invalid: %v", err)+ }++ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ w.Header().Set("Content-Type", "text/html")+ w.Write([]byte(`<html><head><title>Traceway Test</title></head><body><h1 id="msg">hello from ` + os.Getenv("USER") + `</h1></body></html>`))+ }))+ defer server.Close()++ t.Run("passing spec", func(t *testing.T) {+ script := `import { test, expect } from '@playwright/test';++test('page loads', async ({ page }) => {+ await page.goto(process.env.TARGET_URL!);+ await expect(page).toHaveTitle(/Traceway Test/);+ await expect(page.locator('#msg')).toContainText('hello');+});+`+ result, err := Run(context.Background(), Options{+ HarnessDir: harness,+ Script: script,+ Env: map[string]string{"TARGET_URL": server.URL},+ Timeout: 60 * time.Second,+ })+ if err != nil {+ t.Fatalf("run: %v", err)+ }+ if !result.Passed {+ t.Fatalf("expected pass, got error %q output %q", result.ErrorMsg, result.Output)+ }+ if result.DurationMs <= 0 {+ t.Errorf("duration = %f, want > 0", result.DurationMs)+ }+ })++ t.Run("failing spec with screenshot", func(t *testing.T) {+ script := `import { test, expect } from '@playwright/test';++test('wrong title', async ({ page }) => {+ await page.goto(process.env.TARGET_URL!);+ await expect(page.locator('#msg')).toContainText('definitely not there', { timeout: 2000 });+});+`+ result, err := Run(context.Background(), Options{+ HarnessDir: harness,+ Script: script,+ Env: map[string]string{"TARGET_URL": server.URL},+ Timeout: 60 * time.Second,+ })+ if err != nil {+ t.Fatalf("run: %v", err)+ }+ if result.Passed {+ t.Fatal("expected failure")+ }+ if !strings.Contains(result.ErrorMsg, "definitely not there") && !strings.Contains(result.ErrorMsg, "toContainText") {+ t.Errorf("unexpected error message: %q", result.ErrorMsg)+ }+ if len(result.Screenshot) == 0 {+ t.Error("expected a failure screenshot")+ }+ })++ t.Run("secrets are not inherited", func(t *testing.T) {+ script := `import { test, expect } from '@playwright/test';++test('env allowlist', async () => {+ expect(process.env.TRACEWAY_FAKE_SECRET).toBeUndefined();+ expect(process.env.CHECK_VAR).toBe('visible');+});+`+ t.Setenv("TRACEWAY_FAKE_SECRET", "must-not-leak")+ result, err := Run(context.Background(), Options{+ HarnessDir: harness,+ Script: script,+ Env: map[string]string{"CHECK_VAR": "visible"},+ Timeout: 60 * time.Second,+ })+ if err != nil {+ t.Fatalf("run: %v", err)+ }+ if !result.Passed {+ t.Fatalf("env allowlist violated: %q", result.ErrorMsg)+ }+ })+}diff --git a/backend/app/synthetics/browserexec/browserexec_test.go b/backend/app/synthetics/browserexec/browserexec_test.gonew file mode 100644index 00000000..a3e5f93a--- /dev/null+++ b/backend/app/synthetics/browserexec/browserexec_test.go@@ -0,0 +1,84 @@+package browserexec++import (+ "strings"+ "testing"+)++func TestParseReportPassed(t *testing.T) {+ report := `{+ "suites": [{+ "specs": [{+ "title": "page loads",+ "ok": true,+ "tests": [{"results": [{"status": "passed", "duration": 812}]}]+ }]+ }],+ "stats": {"duration": 950, "expected": 1, "unexpected": 0}+ }`+ summary, err := parseReport([]byte(report))+ if err != nil {+ t.Fatalf("parse: %v", err)+ }+ if !summary.passed || summary.errorMsg != "" {+ t.Fatalf("expected pass, got %+v", summary)+ }+ if summary.durationMs != 950 {+ t.Errorf("duration = %f, want 950", summary.durationMs)+ }+}++func TestParseReportFailureWithScreenshot(t *testing.T) {+ report := `{+ "suites": [{+ "suites": [{+ "specs": [{+ "title": "login works",+ "ok": false,+ "tests": [{"results": [{+ "status": "failed",+ "duration": 3000,+ "error": {"message": "\u001b[31mexpect(locator).toContainText\u001b[0m failed"},+ "attachments": [+ {"name": "trace", "contentType": "application/zip", "path": "/tmp/x/trace.zip"},+ {"name": "screenshot", "contentType": "image/png", "path": "/tmp/x/test-failed-1.png"}+ ]+ }]}]+ }]+ }]+ }],+ "stats": {"duration": 3200}+ }`+ summary, err := parseReport([]byte(report))+ if err != nil {+ t.Fatalf("parse: %v", err)+ }+ if summary.passed {+ t.Fatal("expected failure")+ }+ if !strings.HasPrefix(summary.errorMsg, "login works: ") || strings.Contains(summary.errorMsg, "\x1b") {+ t.Errorf("error message not prefixed/ANSI-stripped: %q", summary.errorMsg)+ }+ if summary.screenshotPath != "/tmp/x/test-failed-1.png" {+ t.Errorf("screenshot path = %q", summary.screenshotPath)+ }+}++func TestParseReportNoTests(t *testing.T) {+ summary, err := parseReport([]byte(`{"suites": [], "errors": [{"message": "SyntaxError: unexpected token"}], "stats": {"duration": 12}}`))+ if err != nil {+ t.Fatalf("parse: %v", err)+ }+ if summary.passed {+ t.Fatal("a report with no tests must not pass")+ }+ if !strings.Contains(summary.errorMsg, "SyntaxError") {+ t.Errorf("expected the top-level error surfaced, got %q", summary.errorMsg)+ }+}++func TestValidateMissingHarness(t *testing.T) {+ if err := Validate(t.TempDir()); err == nil {+ t.Fatal("expected an error for an empty harness dir")+ }+}diff --git a/backend/app/synthetics/browserexec/proc_unix.go b/backend/app/synthetics/browserexec/proc_unix.gonew file mode 100644index 00000000..915043c8--- /dev/null+++ b/backend/app/synthetics/browserexec/proc_unix.go@@ -0,0 +1,21 @@+//go:build !windows++package browserexec++import (+ "os/exec"+ "syscall"+)++// configureProcessGroup makes the node process lead its own process group and+// kills the whole group on context cancellation, so orphaned Chromium+// processes never outlive a timed-out run.+func configureProcessGroup(cmd *exec.Cmd) {+ cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}+ cmd.Cancel = func() error {+ if cmd.Process == nil {+ return nil+ }+ return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)+ }+}diff --git a/backend/app/synthetics/browserexec/proc_windows.go b/backend/app/synthetics/browserexec/proc_windows.gonew file mode 100644index 00000000..60178bb4--- /dev/null+++ b/backend/app/synthetics/browserexec/proc_windows.go@@ -0,0 +1,10 @@+//go:build windows++package browserexec++import "os/exec"++// On Windows the default CommandContext kill is used; Playwright's own+// process management cleans up browser children well enough there, and the+// runner binary is the only consumer.+func configureProcessGroup(cmd *exec.Cmd) {}diff --git a/backend/app/synthetics/executor.go b/backend/app/synthetics/executor.gonew file mode 100644index 00000000..c0e1de63--- /dev/null+++ b/backend/app/synthetics/executor.go@@ -0,0 +1,139 @@+package synthetics++import (+ "context"+ "database/sql"+ "fmt"+ "sync"+ "time"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"+ "github.com/tracewayapp/traceway/backend/app/repositories/transactional"+ traceway "go.tracewayapp.com"+)++// browserExecWakeCh nudges the embedded browser executor loop separately from+// the http/tcp loop, so a 2-minute browser run never delays fast probes.+var browserExecWakeCh = make(chan struct{}, 1)++func startExecutor(ctx context.Context) {+ go executorLoop(ctx, wakeCh, func(now time.Time) {+ executeBatch(ctx, now, [3]string{models.CheckTypeHttp, models.CheckTypeTcp, models.CheckTypeTcp}, httpConcurrency())+ })+ if BrowserMode() == BrowserModeEmbedded {+ go executorLoop(ctx, browserExecWakeCh, func(now time.Time) {+ executeBatch(ctx, now, [3]string{models.CheckTypeBrowser, models.CheckTypeBrowser, models.CheckTypeBrowser}, browserConcurrency())+ })+ }+}++func executorLoop(ctx context.Context, wake <-chan struct{}, tick func(now time.Time)) {+ defer traceway.Recover()++ ticker := time.NewTicker(pollInterval())+ defer ticker.Stop()+ for {+ select {+ case <-ctx.Done():+ return+ case <-ticker.C:+ case <-wake:+ }+ tick(time.Now().UTC())+ }+}++// ExecuteOnce claims and executes every currently claimable run class this+// instance handles. Exported so tests can drive the executor deterministically.+func ExecuteOnce(ctx context.Context, now time.Time) {+ executeBatch(ctx, now, [3]string{models.CheckTypeHttp, models.CheckTypeTcp, models.CheckTypeTcp}, httpConcurrency())+ if BrowserMode() == BrowserModeEmbedded {+ executeBatch(ctx, now, [3]string{models.CheckTypeBrowser, models.CheckTypeBrowser, models.CheckTypeBrowser}, browserConcurrency())+ }+}++func executeBatch(ctx context.Context, now time.Time, types [3]string, concurrency int) {+ type claimedRun struct {+ run *models.CheckRun+ check *models.SyntheticCheck+ }+ claimedCount := 0+ claimed, err := db.ExecuteTransaction(func(tx *sql.Tx) ([]claimedRun, error) {+ due, err := transactional.CheckRunRepository.FindClaimable(tx, types[0], types[1], types[2], now, claimBatchSize)+ if err != nil {+ return nil, err+ }+ claimedCount = len(due)+ claimed := make([]claimedRun, 0, len(due))+ for _, run := range due {+ won, err := transactional.CheckRunRepository.Claim(tx, run.Id, instanceName, now)+ if err != nil {+ return nil, err+ }+ if !won {+ continue+ }+ check, err := transactional.SyntheticCheckRepository.FindById(tx, run.CheckId)+ if err != nil {+ return nil, err+ }+ if check == nil {+ // Deleted since the run was queued; the cascade removed the+ // row already (or will), nothing to execute.+ continue+ }+ run.ClaimedBy = instanceName+ claimed = append(claimed, claimedRun{run: run, check: check})+ }+ return claimed, nil+ })+ if err != nil {+ traceway.CaptureException(fmt.Errorf("synthetics executor claim failed: %w", err))+ return+ }++ var wg sync.WaitGroup+ sem := make(chan struct{}, concurrency)+ for _, item := range claimed {+ wg.Add(1)+ sem <- struct{}{}+ go func(item claimedRun) {+ defer traceway.Recover()+ defer wg.Done()+ defer func() { <-sem }()+ outcome := executeProbe(ctx, item.check)+ ProcessOutcome(ctx, item.run, instanceName, outcome)+ }(item)+ }+ wg.Wait()++ if claimedCount == claimBatchSize {+ // A full batch means more runs may already be claimable.+ Wake()+ }+}++// executeProbe runs one check with its timeout and normalizes the outcome.+func executeProbe(ctx context.Context, check *models.SyntheticCheck) Outcome {+ probeCtx, cancel := context.WithTimeout(ctx, EffectiveTimeout(check))+ defer cancel()++ started := time.Now().UTC()+ var outcome Outcome+ switch check.CheckType {+ case models.CheckTypeHttp:+ outcome = probeHttp(probeCtx, check)+ case models.CheckTypeTcp:+ outcome = probeTcp(probeCtx, check)+ case models.CheckTypeBrowser:+ outcome = probeBrowser(probeCtx, check)+ default:+ outcome = Outcome{Status: models.CheckResultDown, ErrorMsg: "unknown check type " + check.CheckType, TlsDaysRemaining: -1}+ }+ outcome.ExecutedAt = started+ if outcome.ExecutedBy == "" {+ outcome.ExecutedBy = "embedded"+ }+ return outcome+}diff --git a/backend/app/synthetics/health.go b/backend/app/synthetics/health.gonew file mode 100644index 00000000..d04528f3--- /dev/null+++ b/backend/app/synthetics/health.go@@ -0,0 +1,76 @@+package synthetics++import (+ "database/sql"+ "sync/atomic"+ "time"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"+ "github.com/tracewayapp/traceway/backend/app/repositories/transactional"+)++type HealthStats struct {+ BrowserMode string `json:"browserMode"`+ QueuedRuns int `json:"queuedRuns"`+ ClaimedRuns int `json:"claimedRuns"`+ OldestQueuedAgeSec int64 `json:"oldestQueuedAgeSec"`+ ChecksDown int `json:"checksDown"`+ RunnersOnline int `json:"runnersOnline"`+ ExecutedTotal uint64 `json:"executedTotal"`+ MissedTotal uint64 `json:"missedTotal"`+}++// runnerOnlineWindow: a runner counts as online while its last poll was+// within this window (polls arrive at least every ~25s while it runs).+const runnerOnlineWindow = 2 * time.Minute++// HealthSnapshot powers /api/health/deep. OldestQueuedAgeSec measures from+// scheduled_for, so a healthy queue shows near-zero even under load.+func HealthSnapshot() (*HealthStats, error) {+ type snapshot struct {+ Counts *models.CheckRunHealthCounts+ Oldest *models.CheckRun+ ChecksDown int+ RunnersOnline int+ }+ loaded, err := db.ExecuteTransaction(func(tx *sql.Tx) (snapshot, error) {+ counts, err := transactional.CheckRunRepository.CountsForHealth(tx)+ if err != nil {+ return snapshot{}, err+ }+ oldest, err := transactional.CheckRunRepository.OldestQueued(tx)+ if err != nil {+ return snapshot{}, err+ }+ down, err := transactional.SyntheticCheckRepository.CountDownAll(tx)+ if err != nil {+ return snapshot{}, err+ }+ online, err := transactional.SyntheticRunnerRepository.CountOnline(tx, time.Now().Add(-runnerOnlineWindow))+ if err != nil {+ return snapshot{}, err+ }+ return snapshot{Counts: counts, Oldest: oldest, ChecksDown: down, RunnersOnline: online}, nil+ })+ if err != nil {+ return nil, err+ }+ stats := &HealthStats{+ BrowserMode: BrowserMode(),+ ChecksDown: loaded.ChecksDown,+ RunnersOnline: loaded.RunnersOnline,+ ExecutedTotal: atomic.LoadUint64(&executedTotal),+ MissedTotal: atomic.LoadUint64(&missedTotal),+ }+ if loaded.Counts != nil {+ stats.QueuedRuns = loaded.Counts.QueuedCount+ stats.ClaimedRuns = loaded.Counts.ClaimedCount+ }+ if loaded.Oldest != nil {+ if age := time.Since(loaded.Oldest.ScheduledFor); age > 0 {+ stats.OldestQueuedAgeSec = int64(age.Seconds())+ }+ }+ return stats, nil+}diff --git a/backend/app/synthetics/result.go b/backend/app/synthetics/result.gonew file mode 100644index 00000000..99a47073--- /dev/null+++ b/backend/app/synthetics/result.go@@ -0,0 +1,182 @@+package synthetics++import (+ "context"+ "database/sql"+ "fmt"+ "sync/atomic"+ "time"++ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"+ "github.com/tracewayapp/traceway/backend/app/repositories/telemetry"+ "github.com/tracewayapp/traceway/backend/app/repositories/transactional"+ traceway "go.tracewayapp.com"+)++var executedTotal uint64++// Outcome is one executed probe's result, produced by the in-process runners+// or posted by a remote runner.+type Outcome struct {+ Status string // models.CheckResultUp or models.CheckResultDown+ LatencyMs float64+ StatusCode int+ ErrorMsg string+ ScreenshotKey string+ OutputKey string+ TlsDaysRemaining int+ ExecutedBy string+ ExecutedAt time.Time+}++// ProcessOutcome finalizes one executed run. Order matters: the main-DB+// transaction (state transition + incident + run-row delete) commits FIRST,+// then the telemetry insert, then the notify hook. A crash between the two+// DB writes loses one result row (an uptime gap), which is benign; the+// reverse order would re-execute after reclaim and double-apply the state+// transition. The notify hook runs with no transaction held: it opens its+// own, and the SQLite main DB has a single connection.+func ProcessOutcome(ctx context.Context, run *models.CheckRun, claimedBy string, outcome Outcome) {+ type finalization struct {+ finalized bool+ check *models.SyntheticCheck+ fromStatus string+ toStatus string+ }+ result, err := db.ExecuteTransaction(func(tx *sql.Tx) (finalization, error) {+ var res finalization+ won, err := transactional.CheckRunRepository.DeleteClaimedBy(tx, run.Id, claimedBy)+ if err != nil {+ return res, err+ }+ if !won {+ // A stale-claim reclaim handed this run to someone else, or the+ // check (and its runs, via cascade) was deleted mid-flight.+ return res, nil+ }+ check, err := transactional.SyntheticCheckRepository.FindById(tx, run.CheckId)+ if err != nil {+ return res, err+ }+ if check == nil {+ return res, nil+ }++ fromStatus := check.CurrentStatus+ toStatus := fromStatus+ consecutiveFailures := 0+ if outcome.Status == models.CheckResultUp {+ toStatus = models.CheckStatusUp+ } else {+ consecutiveFailures = check.ConsecutiveFailures + 1+ threshold := check.FailureThreshold+ if threshold < 1 {+ threshold = 1+ }+ if consecutiveFailures >= threshold {+ toStatus = models.CheckStatusDown+ }+ }++ var stateChangedAt *time.Time+ if toStatus != fromStatus {+ stateChangedAt = &outcome.ExecutedAt+ }+ if err := transactional.SyntheticCheckRepository.ApplyRunState(tx, check.Id, toStatus, consecutiveFailures, outcome.ExecutedAt, stateChangedAt); err != nil {+ return res, err+ }+ // Mirror the persisted state onto the struct handed to the notifier;+ // the "N consecutive failures" in the alert must be the post-run count.+ check.CurrentStatus = toStatus+ check.ConsecutiveFailures = consecutiveFailures+ check.LastRunAt = &outcome.ExecutedAt+ if stateChangedAt != nil {+ check.LastStateChangeAt = stateChangedAt+ }++ if toStatus == models.CheckStatusDown && fromStatus != models.CheckStatusDown {+ open, err := transactional.CheckIncidentRepository.FindOpenByCheck(tx, check.Id)+ if err != nil {+ return res, err+ }+ if open == nil {+ incident := &models.CheckIncident{+ CheckId: check.Id,+ ProjectId: check.ProjectId,+ StartedAt: outcome.ExecutedAt,+ ErrorMessage: outcome.ErrorMsg,+ }+ if _, err := transactional.CheckIncidentRepository.Open(tx, incident); err != nil {+ return res, err+ }+ }+ }+ if toStatus == models.CheckStatusUp && fromStatus == models.CheckStatusDown {+ open, err := transactional.CheckIncidentRepository.FindOpenByCheck(tx, check.Id)+ if err != nil {+ return res, err+ }+ if open != nil {+ if err := transactional.CheckIncidentRepository.Resolve(tx, open.Id, outcome.ExecutedAt); err != nil {+ return res, err+ }+ }+ }++ res.finalized = true+ res.check = check+ res.fromStatus = fromStatus+ res.toStatus = toStatus+ return res, nil+ })+ if err != nil {+ traceway.CaptureException(fmt.Errorf("failed to finalize check run %d: %w", run.Id, err))+ return+ }+ if !result.finalized {+ return+ }++ atomic.AddUint64(&executedTotal, 1)++ insertErr := telemetry.CheckResultRepository.Insert(ctx, telemetry.CheckResult{+ ProjectId: run.ProjectId,+ CheckId: run.CheckId,+ RunId: run.Id,+ CheckType: run.CheckType,+ RecordedAt: run.ScheduledFor,+ ExecutedAt: outcome.ExecutedAt,+ Status: outcome.Status,+ LatencyMs: outcome.LatencyMs,+ StatusCode: outcome.StatusCode,+ ErrorMsg: outcome.ErrorMsg,+ ExecutedBy: outcome.ExecutedBy,+ ScreenshotKey: outcome.ScreenshotKey,+ OutputKey: outcome.OutputKey,+ TlsDaysRemaining: outcome.TlsDaysRemaining,+ })+ if insertErr != nil {+ traceway.CaptureException(fmt.Errorf("failed to record check result (check=%d run=%d): %w", run.CheckId, run.Id, insertErr))+ }++ if result.fromStatus == result.toStatus || notifier == nil {+ return+ }+ wentDown := result.toStatus == models.CheckStatusDown+ recovered := result.fromStatus == models.CheckStatusDown && result.toStatus == models.CheckStatusUp+ if !wentDown && !recovered {+ return+ }+ transition := StateTransition{+ Check: *result.check,+ From: result.fromStatus,+ To: result.toStatus,+ ErrorMsg: outcome.ErrorMsg,+ At: outcome.ExecutedAt,+ }+ go func() {+ defer traceway.Recover()+ notifier(transition)+ }()+}diff --git a/backend/app/synthetics/runner_browser.go b/backend/app/synthetics/runner_browser.gonew file mode 100644index 00000000..483bab0d--- /dev/null+++ b/backend/app/synthetics/runner_browser.go@@ -0,0 +1,83 @@+package synthetics++import (+ "context"+ "encoding/json"+ "fmt"+ "strings"+ "time"++ "github.com/tracewayapp/traceway/backend/app/config"+ "github.com/tracewayapp/traceway/backend/app/models"+ "github.com/tracewayapp/traceway/backend/app/storage"+ "github.com/tracewayapp/traceway/backend/app/synthetics/browserexec"+ traceway "go.tracewayapp.com"+)++const defaultPlaywrightDir = "/opt/traceway-playwright"++// PlaywrightDir is the harness directory holding node_modules with+// @playwright/test (baked into the :browser image, or operator-provided).+func PlaywrightDir() string {+ if dir := config.Config.SyntheticsPlaywrightDir; dir != "" {+ return dir+ }+ return defaultPlaywrightDir+}++// probeBrowser executes a @playwright/test spec via the Node harness. Only+// reached in embedded mode (the executor claims browser runs solely then).+func probeBrowser(ctx context.Context, check *models.SyntheticCheck) Outcome {+ outcome := Outcome{Status: models.CheckResultDown, TlsDaysRemaining: -1}++ var cfg models.BrowserCheckConfig+ if err := json.Unmarshal(check.Config, &cfg); err != nil {+ outcome.ErrorMsg = "invalid check config: " + err.Error()+ return outcome+ }++ started := time.Now()+ result, err := browserexec.Run(ctx, browserexec.Options{+ HarnessDir: PlaywrightDir(),+ Script: cfg.Script,+ Env: cfg.Env,+ Timeout: EffectiveTimeout(check),+ })+ if err != nil {+ outcome.LatencyMs = float64(time.Since(started).Microseconds()) / 1000+ outcome.ErrorMsg = "browser run failed to start: " + err.Error()+ return outcome+ }++ outcome.LatencyMs = result.DurationMs+ if outcome.LatencyMs <= 0 {+ outcome.LatencyMs = float64(time.Since(started).Microseconds()) / 1000+ }+ if result.Passed {+ outcome.Status = models.CheckResultUp+ return outcome+ }++ outcome.ErrorMsg = result.ErrorMsg+ // On a timed-out run ctx is already expired; the artifacts (especially the+ // output tail explaining the timeout) must still be storable.+ storeCtx := context.WithoutCancel(ctx)+ artifactStamp := time.Now().UTC().UnixNano()+ if len(result.Screenshot) > 0 {+ key := fmt.Sprintf("synthetics/%s/%d/%d.png", check.ProjectId, check.Id, artifactStamp)+ if err := storage.Store.Write(storeCtx, key, result.Screenshot); err != nil {+ traceway.CaptureException(fmt.Errorf("failed to store check failure screenshot (check=%d): %w", check.Id, err))+ } else {+ outcome.ScreenshotKey = key+ }+ }+ if output := strings.TrimSpace(result.Output); output != "" {+ key := fmt.Sprintf("synthetics/%s/%d/%d.log", check.ProjectId, check.Id, artifactStamp)+ if err := storage.Store.Write(storeCtx, key, []byte(output)); err != nil {+ traceway.CaptureException(fmt.Errorf("failed to store check failure output (check=%d): %w", check.Id, err))+ } else {+ outcome.OutputKey = key+ }+ }+ return outcome+}diff --git a/backend/app/synthetics/runner_http.go b/backend/app/synthetics/runner_http.gonew file mode 100644index 00000000..07ef5c61--- /dev/null+++ b/backend/app/synthetics/runner_http.go@@ -0,0 +1,166 @@+package synthetics++import (+ "context"+ "crypto/tls"+ "encoding/json"+ "fmt"+ "io"+ "net/http"+ "regexp"+ "strings"+ "time"++ "github.com/tracewayapp/traceway/backend/app/models"+ "github.com/tracewayapp/traceway/backend/app/netguard"+)++// maxProbeBodyBytes caps how much of the response body is read for+// assertions; probes must never buffer arbitrarily large downloads.+const maxProbeBodyBytes = 1 << 20++func probeHttp(ctx context.Context, check *models.SyntheticCheck) Outcome {+ outcome := Outcome{Status: models.CheckResultDown, TlsDaysRemaining: -1}++ var cfg models.HttpCheckConfig+ if err := json.Unmarshal(check.Config, &cfg); err != nil {+ outcome.ErrorMsg = "invalid check config: " + err.Error()+ return outcome+ }++ method := strings.ToUpper(strings.TrimSpace(cfg.Method))+ if method == "" {+ method = http.MethodGet+ }+ var body io.Reader+ if cfg.Body != "" {+ body = strings.NewReader(cfg.Body)+ }+ req, err := http.NewRequestWithContext(ctx, method, cfg.URL, body)+ if err != nil {+ outcome.ErrorMsg = "invalid request: " + err.Error()+ return outcome+ }+ for name, value := range cfg.Headers {+ if strings.TrimSpace(name) == "" {+ continue+ }+ req.Header.Set(name, value)+ }+ if cfg.Body != "" && cfg.BodyContentType != "" && req.Header.Get("Content-Type") == "" {+ req.Header.Set("Content-Type", cfg.BodyContentType)+ }+ switch cfg.Auth.Type {+ case "basic":+ req.SetBasicAuth(cfg.Auth.Username, cfg.Auth.Password)+ case "bearer":+ req.Header.Set("Authorization", "Bearer "+cfg.Auth.Token)+ case "header":+ if cfg.Auth.HeaderName != "" {+ req.Header.Set(cfg.Auth.HeaderName, cfg.Auth.HeaderValue)+ }+ }+ if req.Header.Get("User-Agent") == "" {+ req.Header.Set("User-Agent", "Traceway-Synthetics/1.0")+ }++ transport := &http.Transport{+ TLSClientConfig: &tls.Config{InsecureSkipVerify: cfg.SkipTlsVerify},+ DisableKeepAlives: true,+ }+ if AllowPrivateTargets() {+ // Honor HTTP(S)_PROXY like the default transport, so probes work on+ // instances that can only egress through a proxy.+ transport.Proxy = http.ProxyFromEnvironment+ } else {+ // Guard at dial time so a hostname cannot pass save-time validation+ // and be re-pointed at a private address (DNS rebinding). No proxy in+ // this mode: a CONNECT tunnel would move the dial to the proxy address+ // and blind the guard to the real target.+ transport.DialContext = netguard.GuardedDialContext(EffectiveTimeout(check))+ }+ client := &http.Client{Transport: transport}+ if !cfg.FollowRedirects {+ client.CheckRedirect = func(req *http.Request, via []*http.Request) error {+ return http.ErrUseLastResponse+ }+ }++ started := time.Now()+ resp, err := client.Do(req)+ if err != nil {+ outcome.LatencyMs = float64(time.Since(started).Microseconds()) / 1000+ outcome.ErrorMsg = err.Error()+ return outcome+ }+ defer resp.Body.Close()+ bodyBytes, readErr := io.ReadAll(io.LimitReader(resp.Body, maxProbeBodyBytes))+ outcome.LatencyMs = float64(time.Since(started).Microseconds()) / 1000+ outcome.StatusCode = resp.StatusCode+ if resp.TLS != nil && len(resp.TLS.PeerCertificates) > 0 {+ outcome.TlsDaysRemaining = daysUntil(resp.TLS.PeerCertificates[0].NotAfter)+ }+ if readErr != nil {+ outcome.ErrorMsg = "failed to read response body: " + readErr.Error()+ return outcome+ }++ if failures := evaluateHttpAssertions(&cfg.Assertions, resp.StatusCode, bodyBytes, outcome.LatencyMs, outcome.TlsDaysRemaining); len(failures) > 0 {+ outcome.ErrorMsg = strings.Join(failures, "; ")+ return outcome+ }++ outcome.Status = models.CheckResultUp+ return outcome+}++func evaluateHttpAssertions(assertions *models.HttpAssertions, statusCode int, body []byte, latencyMs float64, tlsDaysRemaining int) []string {+ var failures []string++ if len(assertions.StatusCodes) > 0 {+ matched := false+ for _, code := range assertions.StatusCodes {+ if statusCode == code {+ matched = true+ break+ }+ }+ if !matched {+ failures = append(failures, fmt.Sprintf("status code %d not in expected set %v", statusCode, assertions.StatusCodes))+ }+ } else if statusCode >= 400 {+ failures = append(failures, fmt.Sprintf("status code %d", statusCode))+ }++ if assertions.BodyContains != "" && !strings.Contains(string(body), assertions.BodyContains) {+ failures = append(failures, fmt.Sprintf("body does not contain %q", assertions.BodyContains))+ }+ if assertions.BodyRegex != "" {+ re, err := regexp.Compile(assertions.BodyRegex)+ if err != nil {+ failures = append(failures, "invalid body regex: "+err.Error())+ } else if !re.Match(body) {+ failures = append(failures, fmt.Sprintf("body does not match regex %q", assertions.BodyRegex))+ }+ }+ if assertions.MaxResponseTimeMs > 0 && latencyMs > float64(assertions.MaxResponseTimeMs) {+ failures = append(failures, fmt.Sprintf("response time %.0fms exceeds %dms", latencyMs, assertions.MaxResponseTimeMs))+ }+ if assertions.TlsMinDaysRemaining > 0 {+ if tlsDaysRemaining < 0 {+ failures = append(failures, "TLS expiry assertion set but the connection was not TLS")+ } else if tlsDaysRemaining < assertions.TlsMinDaysRemaining {+ failures = append(failures, fmt.Sprintf("TLS certificate expires in %d days (minimum %d)", tlsDaysRemaining, assertions.TlsMinDaysRemaining))+ }+ }++ return failures+}++func daysUntil(t time.Time) int {+ days := int(time.Until(t).Hours() / 24)+ if days < 0 {+ days = 0+ }+ return days+}diff --git a/backend/app/synthetics/runner_tcp.go b/backend/app/synthetics/runner_tcp.gonew file mode 100644index 00000000..622341ef--- /dev/null+++ b/backend/app/synthetics/runner_tcp.go@@ -0,0 +1,123 @@+package synthetics++import (+ "context"+ "crypto/tls"+ "encoding/json"+ "fmt"+ "net"+ "strings"+ "time"++ "github.com/tracewayapp/traceway/backend/app/models"+ "github.com/tracewayapp/traceway/backend/app/netguard"+)++const maxTcpReadBytes = 64 << 10++func probeTcp(ctx context.Context, check *models.SyntheticCheck) Outcome {+ outcome := Outcome{Status: models.CheckResultDown, TlsDaysRemaining: -1}++ var cfg models.TcpCheckConfig+ if err := json.Unmarshal(check.Config, &cfg); err != nil {+ outcome.ErrorMsg = "invalid check config: " + err.Error()+ return outcome+ }+ if cfg.Host == "" || cfg.Port < 1 || cfg.Port > 65535 {+ outcome.ErrorMsg = "invalid host or port"+ return outcome+ }++ address := net.JoinHostPort(cfg.Host, fmt.Sprintf("%d", cfg.Port))+ timeout := EffectiveTimeout(check)+ dial := (&net.Dialer{Timeout: timeout}).DialContext+ if !AllowPrivateTargets() {+ // Vet the resolved address and dial exactly that address, like the+ // http probe: a validate-then-redial-by-hostname sequence would leave+ // a DNS-rebinding window between the check and the connection.+ dial = netguard.GuardedDialContext(timeout)+ }++ started := time.Now()+ conn, err := dial(ctx, "tcp", address)+ if err != nil {+ outcome.LatencyMs = float64(time.Since(started).Microseconds()) / 1000+ outcome.ErrorMsg = err.Error()+ return outcome+ }+ defer conn.Close()++ if deadline, ok := ctx.Deadline(); ok {+ _ = conn.SetDeadline(deadline)+ }++ if cfg.UseTls {+ tlsConn := tls.Client(conn, &tls.Config{ServerName: cfg.Host})+ if err := tlsConn.HandshakeContext(ctx); err != nil {+ outcome.LatencyMs = float64(time.Since(started).Microseconds()) / 1000+ outcome.ErrorMsg = "TLS handshake failed: " + err.Error()+ return outcome+ }+ state := tlsConn.ConnectionState()+ if len(state.PeerCertificates) > 0 {+ outcome.TlsDaysRemaining = daysUntil(state.PeerCertificates[0].NotAfter)+ }+ conn = tlsConn+ }++ if cfg.SendPayload != "" {+ if _, err := conn.Write([]byte(cfg.SendPayload)); err != nil {+ outcome.LatencyMs = float64(time.Since(started).Microseconds()) / 1000+ outcome.ErrorMsg = "write failed: " + err.Error()+ return outcome+ }+ }+ if cfg.ExpectContains != "" {+ received, matched := readUntilMatch(conn, cfg.ExpectContains)+ if !matched {+ outcome.LatencyMs = float64(time.Since(started).Microseconds()) / 1000+ preview := received+ if len(preview) > 200 {+ preview = preview[:200]+ }+ outcome.ErrorMsg = fmt.Sprintf("response does not contain %q (got %q)", cfg.ExpectContains, preview)+ return outcome+ }+ }++ outcome.LatencyMs = float64(time.Since(started).Microseconds()) / 1000++ if cfg.TlsMinDaysRemaining > 0 {+ if outcome.TlsDaysRemaining < 0 {+ outcome.ErrorMsg = "TLS expiry assertion set but the check does not use TLS"+ return outcome+ }+ if outcome.TlsDaysRemaining < cfg.TlsMinDaysRemaining {+ outcome.ErrorMsg = fmt.Sprintf("TLS certificate expires in %d days (minimum %d)", outcome.TlsDaysRemaining, cfg.TlsMinDaysRemaining)+ return outcome+ }+ }++ outcome.Status = models.CheckResultUp+ return outcome+}++// readUntilMatch reads until the buffer contains the expected substring, the+// connection closes, the deadline passes, or the read cap is hit.+func readUntilMatch(conn net.Conn, expect string) (string, bool) {+ var builder strings.Builder+ buf := make([]byte, 4096)+ for builder.Len() < maxTcpReadBytes {+ n, err := conn.Read(buf)+ if n > 0 {+ builder.Write(buf[:n])+ if strings.Contains(builder.String(), expect) {+ return builder.String(), true+ }+ }+ if err != nil {+ break+ }+ }+ return builder.String(), strings.Contains(builder.String(), expect)+}diff --git a/backend/app/synthetics/scheduler.go b/backend/app/synthetics/scheduler.gonew file mode 100644index 00000000..584db996--- /dev/null+++ b/backend/app/synthetics/scheduler.go@@ -0,0 +1,162 @@+package synthetics++import (+ "context"+ "database/sql"+ "fmt"+ "sync/atomic"+ "time"++ "github.com/tracewayapp/traceway/backend/app/config"+ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/models"+ "github.com/tracewayapp/traceway/backend/app/repositories/telemetry"+ "github.com/tracewayapp/traceway/backend/app/repositories/transactional"+ "github.com/tracewayapp/traceway/backend/app/synthetics/browserexec"+ traceway "go.tracewayapp.com"+)++var missedTotal uint64++// Start runs the scheduler and the in-process executor.+func Start(ctx context.Context) {+ // Browser checks are arbitrary code execution on the server; they must be+ // impossible to enable in cloud mode.+ if config.Config.CloudMode == "true" && BrowserMode() != BrowserModeOff {+ panic("SYNTHETICS_BROWSER_MODE must be off in cloud mode: browser checks execute user-authored scripts on the server")+ }+ // Fail fast instead of failing every browser run: embedded mode is only+ // meaningful with the Node harness present (the :browser image).+ if BrowserMode() == BrowserModeEmbedded {+ if err := browserexec.Validate(PlaywrightDir()); err != nil {+ panic(fmt.Sprintf("SYNTHETICS_BROWSER_MODE=embedded but the Playwright harness is unusable (%v); use the ghcr.io/tracewayapp/traceway:browser image or point SYNTHETICS_PLAYWRIGHT_DIR at a directory with @playwright/test installed", err))+ }+ }+ // Same fail-fast principle for remote mode: without the shared secret no+ // runner can ever authenticate, so every browser run would expire missed.+ if BrowserMode() == BrowserModeRemote && config.Config.SyntheticsRunnerSecret == "" {+ panic("SYNTHETICS_BROWSER_MODE=remote requires SYNTHETICS_RUNNER_SECRET so runners can authenticate")+ }+ config.Logf("Starting synthetics scheduler (interval: %s, browser mode: %s)", pollInterval(), BrowserMode())++ go func() {+ defer traceway.Recover()++ ticker := time.NewTicker(pollInterval())+ defer ticker.Stop()+ for {+ select {+ case <-ctx.Done():+ return+ case <-ticker.C:+ }+ ScheduleOnce(ctx, time.Now().UTC())+ }+ }()++ startExecutor(ctx)+}++// ScheduleOnce runs a single scheduler tick: reclaim stale claims, expire+// overdue queued runs as missed, enqueue due checks, advance their+// next_run_at. Exported so tests can drive the scheduler deterministically.+func ScheduleOnce(ctx context.Context, now time.Time) {+ type tickResult struct {+ missed []*models.CheckRun+ enqueued int+ browserRuns bool+ dueSaturated bool+ }+ result, err := db.ExecuteTransaction(func(tx *sql.Tx) (tickResult, error) {+ var res tickResult+ if !db.IsSQLite() {+ if _, err := tx.Exec(fmt.Sprintf("SELECT pg_advisory_xact_lock(%d)", schedulerAdvisoryLockId)); err != nil {+ return res, fmt.Errorf("failed to take synthetics scheduler lock: %w", err)+ }+ }+ if err := transactional.CheckRunRepository.ReclaimStaleClaimed(tx, now.Add(-staleClaimAge)); err != nil {+ return res, err+ }++ expired, err := transactional.CheckRunRepository.FindExpiredQueued(tx, now, expiredBatchSize)+ if err != nil {+ return res, err+ }+ for _, run := range expired {+ if err := transactional.CheckRunRepository.Delete(tx, run.Id); err != nil {+ return res, err+ }+ }+ res.missed = expired++ due, err := transactional.SyntheticCheckRepository.FindDueEnabled(tx, now, scheduleBatchSize)+ if err != nil {+ return res, err+ }+ res.dueSaturated = len(due) == scheduleBatchSize+ browserOff := BrowserMode() == BrowserModeOff+ for _, check := range due {+ if browserOff && check.CheckType == models.CheckTypeBrowser {+ // Nothing can ever claim a browser run with the mode off;+ // enqueueing would only produce missed-result noise. Advance+ // the pointer so the check resumes on schedule when the mode+ // comes back.+ if err := transactional.SyntheticCheckRepository.SetNextRun(tx, check.Id, now.Add(time.Duration(check.IntervalSeconds)*time.Second)); err != nil {+ return res, err+ }+ continue+ }+ run := &models.CheckRun{+ CheckId: check.Id,+ ProjectId: check.ProjectId,+ CheckType: check.CheckType,+ Status: models.CheckRunQueued,+ ScheduledFor: now,+ ExpiresAt: RunExpiry(now, check.IntervalSeconds),+ CreatedAt: now,+ }+ if _, err := transactional.CheckRunRepository.Enqueue(tx, run); err != nil {+ return res, err+ }+ if err := transactional.SyntheticCheckRepository.SetNextRun(tx, check.Id, now.Add(time.Duration(check.IntervalSeconds)*time.Second)); err != nil {+ return res, err+ }+ res.enqueued+++ if check.CheckType == models.CheckTypeBrowser {+ res.browserRuns = true+ }+ }+ return res, nil+ })+ if err != nil {+ traceway.CaptureException(fmt.Errorf("synthetics scheduler tick failed: %w", err))+ return+ }++ // Missed runs are recorded to telemetry after the delete committed: a+ // crash in between loses the missed marker (a gap), never duplicates it.+ for _, run := range result.missed {+ atomic.AddUint64(&missedTotal, 1)+ insertErr := telemetry.CheckResultRepository.Insert(ctx, telemetry.CheckResult{+ ProjectId: run.ProjectId,+ CheckId: run.CheckId,+ RunId: run.Id,+ CheckType: run.CheckType,+ RecordedAt: run.ScheduledFor,+ ExecutedAt: now,+ Status: models.CheckResultMissed,+ ExecutedBy: "scheduler",+ TlsDaysRemaining: -1,+ })+ if insertErr != nil {+ traceway.CaptureException(fmt.Errorf("failed to record missed check result (check=%d run=%d): %w", run.CheckId, run.Id, insertErr))+ }+ }++ if result.enqueued > 0 || result.dueSaturated {+ Wake()+ }+ if result.browserRuns {+ wakeBrowser()+ }+}diff --git a/backend/app/synthetics/synthetics.go b/backend/app/synthetics/synthetics.gonew file mode 100644index 00000000..193a85ad--- /dev/null+++ b/backend/app/synthetics/synthetics.go@@ -0,0 +1,180 @@+// Package synthetics runs scheduled synthetic checks (http, tcp, browser)+// from a durable queue in the main DB. The scheduler enqueues due runs, the+// in-process executor claims and probes, and results land in the telemetry+// check_results table. Modeled on the notification outbox: guarded status+// transitions, stale-claim reclaim, advisory-locked ticks. Unlike the outbox+// there is no retry/backoff — a failed probe IS a result — and terminal queue+// rows are deleted; expired queued runs are recorded as missed, never+// executed late.+package synthetics++import (+ "fmt"+ "os"+ "strconv"+ "time"++ "github.com/tracewayapp/traceway/backend/app/config"+ "github.com/tracewayapp/traceway/backend/app/models"+)++const (+ schedulerAdvisoryLockId = 824737004 // outbox: 824737003, escalator: 824737002, backfill: 824737001++ // staleClaimAge must exceed the largest per-check timeout (browser 120s)+ // plus result-processing headroom.+ staleClaimAge = 5 * time.Minute++ // maxRunExpiry caps how stale a queued probe may execute; per-check+ // expiry is min(interval, maxRunExpiry).+ maxRunExpiry = 5 * time.Minute++ scheduleBatchSize = 200+ claimBatchSize = 50+ expiredBatchSize = 500++ BrowserModeOff = "off"+ BrowserModeEmbedded = "embedded"+ BrowserModeRemote = "remote"+)++// Browser execution limits; validation clamps to these.+const (+ MinIntervalSeconds = 30+ DefaultTimeoutSeconds = 30+ MaxTimeoutSeconds = 120+ MaxBrowserTimeoutSeconds = 120+)++func pollInterval() time.Duration {+ return config.PollSeconds(config.Config.SyntheticsPollSeconds, 15)+}++// BrowserMode returns the validated SYNTHETICS_BROWSER_MODE, defaulting to off.+func BrowserMode() string {+ switch config.Config.SyntheticsBrowserMode {+ case BrowserModeEmbedded:+ return BrowserModeEmbedded+ case BrowserModeRemote:+ return BrowserModeRemote+ default:+ return BrowserModeOff+ }+}++func AllowPrivateTargets() bool {+ // Multi-tenant cloud must never let a check probe the platform's own+ // network (metadata endpoints, databases, localhost); the guard is forced+ // on there regardless of environment.+ if config.Config.CloudMode == "true" {+ return false+ }+ // Default allow: probing LAN services is a core self-hosted use case.+ return config.Config.SyntheticsAllowPrivateTargets != "false"+}++func httpConcurrency() int {+ return parsePositiveInt(config.Config.SyntheticsHTTPConcurrency, 8)+}++func browserConcurrency() int {+ return parsePositiveInt(config.Config.SyntheticsBrowserConcurrency, 2)+}++func parsePositiveInt(value string, fallback int) int {+ if value == "" {+ return fallback+ }+ parsed, err := strconv.Atoi(value)+ if err != nil || parsed < 1 {+ return fallback+ }+ return parsed+}++// instanceName identifies this process in check_runs.claimed_by.+var instanceName = func() string {+ host, err := os.Hostname()+ if err != nil || host == "" {+ host = "traceway"+ }+ return fmt.Sprintf("%s-%d", host, os.Getpid())+}()++// wakeCh nudges the executor loop; a full channel means a wake-up is already+// scheduled.+var wakeCh = make(chan struct{}, 1)++// Wake nudges the executor loops (and any waiting remote-runner long-poll) to+// look for claimable runs without waiting for the next tick. Call after the+// enqueueing transaction commits.+func Wake() {+ select {+ case wakeCh <- struct{}{}:+ default:+ }+ select {+ case browserExecWakeCh <- struct{}{}:+ default:+ }+ wakeBrowser()+}++// browserWakeCh nudges remote-runner long-polls when browser runs are queued.+var browserWakeCh = make(chan struct{}, 1)++func wakeBrowser() {+ select {+ case browserWakeCh <- struct{}{}:+ default:+ }+}++// BrowserWakeChannel is drained by the runner long-poll endpoint so a freshly+// queued browser run answers a waiting runner immediately.+func BrowserWakeChannel() <-chan struct{} {+ return browserWakeCh+}++// StateTransition describes a check crossing up<->down, delivered to the+// notify hook AFTER the state transaction commits (the hook opens its own+// transactions; calling it with one held would deadlock the single-connection+// SQLite main DB).+type StateTransition struct {+ Check models.SyntheticCheck+ From string+ To string+ ErrorMsg string+ At time.Time+}++// NotifierFunc is implemented by the notifications package and registered in+// cmd/run.go; the indirection avoids an import cycle.+type NotifierFunc func(transition StateTransition)++var notifier NotifierFunc++func RegisterNotifier(fn NotifierFunc) {+ notifier = fn+}++// RunExpiry computes when a queued run stops being worth executing.+func RunExpiry(scheduledFor time.Time, intervalSeconds int) time.Time {+ expiry := time.Duration(intervalSeconds) * time.Second+ if expiry > maxRunExpiry {+ expiry = maxRunExpiry+ }+ return scheduledFor.Add(expiry)+}++// EffectiveTimeout clamps a check's timeout to sane bounds.+func EffectiveTimeout(check *models.SyntheticCheck) time.Duration {+ seconds := check.TimeoutSeconds+ if seconds < 1 {+ seconds = DefaultTimeoutSeconds+ }+ if seconds > MaxTimeoutSeconds {+ seconds = MaxTimeoutSeconds+ }+ return time.Duration(seconds) * time.Second+}diff --git a/backend/app/synthetics/synthetics_sqlite_test.go b/backend/app/synthetics/synthetics_sqlite_test.gonew file mode 100644index 00000000..b1c0e4c8--- /dev/null+++ b/backend/app/synthetics/synthetics_sqlite_test.go@@ -0,0 +1,493 @@+//go:build !transactional_pg && !telemetry_ch && !telemetry_duckdb++package synthetics++import (+ "context"+ "database/sql"+ "fmt"+ "net"+ "net/http"+ "net/http/httptest"+ "sync/atomic"+ "testing"+ "time"++ "github.com/google/uuid"+ "github.com/tracewayapp/lit/v2"+ "github.com/tracewayapp/traceway/backend/app/config"+ "github.com/tracewayapp/traceway/backend/app/db"+ "github.com/tracewayapp/traceway/backend/app/dbtest"+ "github.com/tracewayapp/traceway/backend/app/models"+ "github.com/tracewayapp/traceway/backend/app/repositories/telemetry"+ "github.com/tracewayapp/traceway/backend/app/repositories/transactional"+)++func setupSyntheticsDB(t *testing.T) uuid.UUID {+ t.Helper()+ dbtest.SetupSQLite(t)+ t.Cleanup(func() { notifier = nil })++ project, err := db.ExecuteTransaction(func(tx *sql.Tx) (*models.Project, error) {+ return transactional.ProjectRepository.Create(tx, "synthetics-test", "gin")+ })+ if err != nil {+ t.Fatalf("create project: %v", err)+ }+ return project.Id+}++func createTestCheck(t *testing.T, projectId uuid.UUID, checkType string, config string, intervalSeconds int, failureThreshold int, nextRunAt time.Time) *models.SyntheticCheck {+ t.Helper()+ check := &models.SyntheticCheck{+ ProjectId: projectId,+ Name: "test check",+ CheckType: checkType,+ Enabled: true,+ IntervalSeconds: intervalSeconds,+ TimeoutSeconds: 5,+ Config: models.JSONText(config),+ FailureThreshold: failureThreshold,+ CurrentStatus: models.CheckStatusUnknown,+ NextRunAt: nextRunAt,+ CreatedAt: time.Now().UTC(),+ UpdatedAt: time.Now().UTC(),+ }+ id, err := db.ExecuteTransaction(func(tx *sql.Tx) (int, error) {+ return transactional.SyntheticCheckRepository.Create(tx, check)+ })+ if err != nil {+ t.Fatalf("create check: %v", err)+ }+ check.Id = id+ return check+}++func reloadCheck(t *testing.T, id int) *models.SyntheticCheck {+ t.Helper()+ check, err := db.ExecuteTransaction(func(tx *sql.Tx) (*models.SyntheticCheck, error) {+ return transactional.SyntheticCheckRepository.FindById(tx, id)+ })+ if err != nil || check == nil {+ t.Fatalf("reload check %d: %v", id, err)+ }+ return check+}++func allRuns(t *testing.T) []*models.CheckRun {+ t.Helper()+ runs, err := db.ExecuteTransaction(func(tx *sql.Tx) ([]*models.CheckRun, error) {+ return lit.SelectNamed[models.CheckRun](+ tx,+ "SELECT id, check_id, project_id, check_type, status, scheduled_for, expires_at, claimed_at, claimed_by, created_at FROM check_runs ORDER BY id ASC",+ lit.P{},+ )+ })+ if err != nil {+ t.Fatalf("list runs: %v", err)+ }+ return runs+}++func checkResults(t *testing.T, projectId uuid.UUID, checkId int) []*models.CheckResultEntry {+ t.Helper()+ results, _, err := telemetry.CheckResultRepository.FindByCheck(context.Background(), projectId, checkId, nil, nil, "", 1, 100)+ if err != nil {+ t.Fatalf("list check results: %v", err)+ }+ return results+}++func httpConfig(url string, extra string) string {+ if extra != "" {+ extra = "," + extra+ }+ return fmt.Sprintf(`{"url":%q,"method":"GET","followRedirects":true,"assertions":{}%s}`, url, extra)+}++func TestScheduleEnqueuesDueChecksOnce(t *testing.T) {+ projectId := setupSyntheticsDB(t)+ now := time.Now().UTC()+ check := createTestCheck(t, projectId, models.CheckTypeHttp, httpConfig("http://example.invalid", ""), 60, 1, now.Add(-time.Minute))++ ScheduleOnce(context.Background(), now)++ runs := allRuns(t)+ if len(runs) != 1 {+ t.Fatalf("expected 1 queued run, got %d", len(runs))+ }+ if runs[0].Status != models.CheckRunQueued || runs[0].CheckId != check.Id {+ t.Fatalf("unexpected run %+v", runs[0])+ }+ wantExpiry := now.Add(60 * time.Second)+ if !runs[0].ExpiresAt.Equal(wantExpiry) {+ t.Errorf("expires_at = %s, want %s", runs[0].ExpiresAt, wantExpiry)+ }+ reloaded := reloadCheck(t, check.Id)+ if !reloaded.NextRunAt.Equal(now.Add(60 * time.Second)) {+ t.Errorf("next_run_at = %s, want %s", reloaded.NextRunAt, now.Add(60*time.Second))+ }++ // The same tick must not double-enqueue.+ ScheduleOnce(context.Background(), now)+ if runs := allRuns(t); len(runs) != 1 {+ t.Fatalf("expected still 1 run after second tick, got %d", len(runs))+ }+}++func TestScheduleSkipsDisabledChecks(t *testing.T) {+ projectId := setupSyntheticsDB(t)+ now := time.Now().UTC()+ check := createTestCheck(t, projectId, models.CheckTypeHttp, httpConfig("http://example.invalid", ""), 60, 1, now.Add(-time.Minute))+ check.Enabled = false+ if _, err := db.ExecuteTransaction(func(tx *sql.Tx) (struct{}, error) {+ return struct{}{}, transactional.SyntheticCheckRepository.Update(tx, check)+ }); err != nil {+ t.Fatalf("disable check: %v", err)+ }++ ScheduleOnce(context.Background(), now)+ if runs := allRuns(t); len(runs) != 0 {+ t.Fatalf("expected no runs for a disabled check, got %d", len(runs))+ }+}++func TestAllowPrivateTargetsForcedOffInCloudMode(t *testing.T) {+ setupSyntheticsDB(t)+ previousCloud := config.Config.CloudMode+ previousAllow := config.Config.SyntheticsAllowPrivateTargets+ t.Cleanup(func() {+ config.Config.CloudMode = previousCloud+ config.Config.SyntheticsAllowPrivateTargets = previousAllow+ })++ config.Config.CloudMode = ""+ config.Config.SyntheticsAllowPrivateTargets = ""+ if !AllowPrivateTargets() {+ t.Fatal("self-hosted default must allow private targets")+ }++ // Cloud mode must force the SSRF guard on even when the env var says allow.+ config.Config.CloudMode = "true"+ config.Config.SyntheticsAllowPrivateTargets = "true"+ if AllowPrivateTargets() {+ t.Fatal("cloud mode must never allow private targets")+ }+}++func TestScheduleSkipsBrowserChecksWhenModeOff(t *testing.T) {+ projectId := setupSyntheticsDB(t)+ previousMode := config.Config.SyntheticsBrowserMode+ t.Cleanup(func() { config.Config.SyntheticsBrowserMode = previousMode })++ config.Config.SyntheticsBrowserMode = BrowserModeOff+ now := time.Now().UTC()+ check := createTestCheck(t, projectId, models.CheckTypeBrowser, `{"script":"import {} from '@playwright/test';"}`, 60, 1, now.Add(-time.Minute))++ ScheduleOnce(context.Background(), now)+ if runs := allRuns(t); len(runs) != 0 {+ t.Fatalf("expected no queued runs with browser mode off, got %d", len(runs))+ }+ // The pointer must still advance so the check resumes on schedule (and the+ // scheduler does not refetch it every tick) once the mode comes back.+ reloaded := reloadCheck(t, check.Id)+ if !reloaded.NextRunAt.Equal(now.Add(60 * time.Second)) {+ t.Errorf("next_run_at = %s, want %s", reloaded.NextRunAt, now.Add(60*time.Second))+ }++ config.Config.SyntheticsBrowserMode = BrowserModeRemote+ later := now.Add(2 * time.Minute)+ ScheduleOnce(context.Background(), later)+ if runs := allRuns(t); len(runs) != 1 {+ t.Fatalf("expected 1 queued run with browser mode on, got %d", len(runs))+ }+}++func TestExecuteHttpCheckRecordsUp(t *testing.T) {+ projectId := setupSyntheticsDB(t)+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ w.WriteHeader(200)+ fmt.Fprint(w, "hello world")+ }))+ defer server.Close()++ now := time.Now().UTC()+ check := createTestCheck(t, projectId, models.CheckTypeHttp, httpConfig(server.URL, `"assertions":{"bodyContains":"hello"}`), 60, 1, now.Add(-time.Minute))++ ScheduleOnce(context.Background(), now)+ ExecuteOnce(context.Background(), now)++ if runs := allRuns(t); len(runs) != 0 {+ t.Fatalf("expected run row deleted after execution, got %d rows", len(runs))+ }+ reloaded := reloadCheck(t, check.Id)+ if reloaded.CurrentStatus != models.CheckStatusUp {+ t.Errorf("current_status = %s, want up", reloaded.CurrentStatus)+ }+ if reloaded.ConsecutiveFailures != 0 {+ t.Errorf("consecutive_failures = %d, want 0", reloaded.ConsecutiveFailures)+ }+ if reloaded.LastRunAt == nil {+ t.Error("last_run_at not set")+ }++ results := checkResults(t, projectId, check.Id)+ if len(results) != 1 {+ t.Fatalf("expected 1 telemetry result, got %d", len(results))+ }+ if results[0].Status != models.CheckResultUp || results[0].StatusCode != 200 {+ t.Errorf("unexpected result %+v", results[0])+ }+ if results[0].LatencyMs <= 0 {+ t.Errorf("latency_ms = %f, want > 0", results[0].LatencyMs)+ }+}++func TestFailureThresholdIncidentAndRecovery(t *testing.T) {+ projectId := setupSyntheticsDB(t)+ var failing atomic.Bool+ failing.Store(true)+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ if failing.Load() {+ w.WriteHeader(500)+ return+ }+ w.WriteHeader(200)+ }))+ defer server.Close()++ transitions := make(chan StateTransition, 4)+ RegisterNotifier(func(transition StateTransition) { transitions <- transition })++ now := time.Now().UTC()+ check := createTestCheck(t, projectId, models.CheckTypeHttp, httpConfig(server.URL, ""), 60, 2, now.Add(-time.Minute))++ runOnce := func(tick time.Time) {+ ScheduleOnce(context.Background(), tick)+ ExecuteOnce(context.Background(), tick)+ }++ // First failure: below the threshold, no transition.+ runOnce(now)+ reloaded := reloadCheck(t, check.Id)+ if reloaded.CurrentStatus != models.CheckStatusUnknown || reloaded.ConsecutiveFailures != 1 {+ t.Fatalf("after first failure: status=%s failures=%d, want unknown/1", reloaded.CurrentStatus, reloaded.ConsecutiveFailures)+ }+ select {+ case tr := <-transitions:+ t.Fatalf("unexpected transition after first failure: %+v", tr)+ case <-time.After(100 * time.Millisecond):+ }++ // Second failure crosses the threshold: down + incident + notification.+ runOnce(now.Add(61 * time.Second))+ reloaded = reloadCheck(t, check.Id)+ if reloaded.CurrentStatus != models.CheckStatusDown || reloaded.ConsecutiveFailures != 2 {+ t.Fatalf("after second failure: status=%s failures=%d, want down/2", reloaded.CurrentStatus, reloaded.ConsecutiveFailures)+ }+ select {+ case tr := <-transitions:+ if tr.To != models.CheckStatusDown || tr.Check.Id != check.Id {+ t.Fatalf("unexpected transition %+v", tr)+ }+ case <-time.After(2 * time.Second):+ t.Fatal("expected a down transition notification")+ }+ openIncident, err := db.ExecuteTransaction(func(tx *sql.Tx) (*models.CheckIncident, error) {+ return transactional.CheckIncidentRepository.FindOpenByCheck(tx, check.Id)+ })+ if err != nil || openIncident == nil {+ t.Fatalf("expected an open incident, got %+v (%v)", openIncident, err)+ }++ // A third failure must not re-notify or duplicate the incident.+ runOnce(now.Add(122 * time.Second))+ select {+ case tr := <-transitions:+ t.Fatalf("unexpected transition while already down: %+v", tr)+ case <-time.After(100 * time.Millisecond):+ }++ // Recovery: up + incident resolved + notification.+ failing.Store(false)+ runOnce(now.Add(183 * time.Second))+ reloaded = reloadCheck(t, check.Id)+ if reloaded.CurrentStatus != models.CheckStatusUp || reloaded.ConsecutiveFailures != 0 {+ t.Fatalf("after recovery: status=%s failures=%d, want up/0", reloaded.CurrentStatus, reloaded.ConsecutiveFailures)+ }+ select {+ case tr := <-transitions:+ if tr.From != models.CheckStatusDown || tr.To != models.CheckStatusUp {+ t.Fatalf("unexpected recovery transition %+v", tr)+ }+ case <-time.After(2 * time.Second):+ t.Fatal("expected a recovery transition notification")+ }+ stillOpen, err := db.ExecuteTransaction(func(tx *sql.Tx) (*models.CheckIncident, error) {+ return transactional.CheckIncidentRepository.FindOpenByCheck(tx, check.Id)+ })+ if err != nil {+ t.Fatalf("find open incident: %v", err)+ }+ if stillOpen != nil {+ t.Fatalf("incident not resolved: %+v", stillOpen)+ }++ results := checkResults(t, projectId, check.Id)+ if len(results) != 4 {+ t.Fatalf("expected 4 telemetry results, got %d", len(results))+ }+}++func TestExpiredQueuedRunRecordedAsMissed(t *testing.T) {+ projectId := setupSyntheticsDB(t)+ now := time.Now().UTC()+ check := createTestCheck(t, projectId, models.CheckTypeHttp, httpConfig("http://example.invalid", ""), 30, 1, now.Add(time.Hour))++ if _, err := db.ExecuteTransaction(func(tx *sql.Tx) (int, error) {+ return transactional.CheckRunRepository.Enqueue(tx, &models.CheckRun{+ CheckId: check.Id,+ ProjectId: projectId,+ CheckType: check.CheckType,+ Status: models.CheckRunQueued,+ ScheduledFor: now.Add(-10 * time.Minute),+ ExpiresAt: now.Add(-9 * time.Minute),+ CreatedAt: now.Add(-10 * time.Minute),+ })+ }); err != nil {+ t.Fatalf("enqueue stale run: %v", err)+ }++ ScheduleOnce(context.Background(), now)++ if runs := allRuns(t); len(runs) != 0 {+ t.Fatalf("expected expired run deleted, got %d rows", len(runs))+ }+ results := checkResults(t, projectId, check.Id)+ if len(results) != 1 || results[0].Status != models.CheckResultMissed {+ t.Fatalf("expected 1 missed result, got %+v", results)+ }+ // A missed probe is no evidence of health: state must be untouched.+ if reloaded := reloadCheck(t, check.Id); reloaded.CurrentStatus != models.CheckStatusUnknown {+ t.Errorf("current_status = %s, want unknown", reloaded.CurrentStatus)+ }+}++func TestStaleClaimedRunIsReclaimed(t *testing.T) {+ projectId := setupSyntheticsDB(t)+ now := time.Now().UTC()+ check := createTestCheck(t, projectId, models.CheckTypeHttp, httpConfig("http://example.invalid", ""), 600, 1, now.Add(time.Hour))++ runId, err := db.ExecuteTransaction(func(tx *sql.Tx) (int, error) {+ id, err := transactional.CheckRunRepository.Enqueue(tx, &models.CheckRun{+ CheckId: check.Id,+ ProjectId: projectId,+ CheckType: check.CheckType,+ Status: models.CheckRunQueued,+ ScheduledFor: now.Add(-time.Minute),+ ExpiresAt: now.Add(4 * time.Minute),+ CreatedAt: now.Add(-time.Minute),+ })+ if err != nil {+ return 0, err+ }+ // Claimed 10 minutes ago by an executor that died.+ if _, err := transactional.CheckRunRepository.Claim(tx, id, "dead-instance", now.Add(-10*time.Minute)); err != nil {+ return 0, err+ }+ return id, nil+ })+ if err != nil {+ t.Fatalf("enqueue+claim: %v", err)+ }++ ScheduleOnce(context.Background(), now)++ runs := allRuns(t)+ if len(runs) != 1 || runs[0].Id != runId {+ t.Fatalf("expected the run to survive, got %+v", runs)+ }+ if runs[0].Status != models.CheckRunQueued || runs[0].ClaimedAt != nil {+ t.Fatalf("expected the stale claim reclaimed to queued, got %+v", runs[0])+ }+}++func TestProcessOutcomeDiscardsLostClaim(t *testing.T) {+ projectId := setupSyntheticsDB(t)+ now := time.Now().UTC()+ check := createTestCheck(t, projectId, models.CheckTypeHttp, httpConfig("http://example.invalid", ""), 60, 1, now.Add(time.Hour))++ run := &models.CheckRun{+ CheckId: check.Id,+ ProjectId: projectId,+ CheckType: check.CheckType,+ Status: models.CheckRunQueued,+ ScheduledFor: now,+ ExpiresAt: now.Add(time.Minute),+ CreatedAt: now,+ }+ if _, err := db.ExecuteTransaction(func(tx *sql.Tx) (int, error) {+ id, err := transactional.CheckRunRepository.Enqueue(tx, run)+ run.Id = id+ if err != nil {+ return 0, err+ }+ _, err = transactional.CheckRunRepository.Claim(tx, id, "owner-a", now)+ return id, err+ }); err != nil {+ t.Fatalf("enqueue+claim: %v", err)+ }++ // owner-b lost the claim to owner-a; its outcome must be discarded.+ ProcessOutcome(context.Background(), run, "owner-b", Outcome{+ Status: models.CheckResultDown, ErrorMsg: "boom", ExecutedAt: now, ExecutedBy: "owner-b", TlsDaysRemaining: -1,+ })++ if reloaded := reloadCheck(t, check.Id); reloaded.CurrentStatus != models.CheckStatusUnknown || reloaded.ConsecutiveFailures != 0 {+ t.Fatalf("lost claim must not change state, got %+v", reloaded)+ }+ if results := checkResults(t, projectId, check.Id); len(results) != 0 {+ t.Fatalf("lost claim must not record telemetry, got %d rows", len(results))+ }+ if runs := allRuns(t); len(runs) != 1 {+ t.Fatalf("run row must survive a lost finalize, got %d", len(runs))+ }+}++func TestTcpCheckUpAndDown(t *testing.T) {+ projectId := setupSyntheticsDB(t)+ listener, err := net.Listen("tcp", "127.0.0.1:0")+ if err != nil {+ t.Fatalf("listen: %v", err)+ }+ defer listener.Close()+ go func() {+ for {+ conn, err := listener.Accept()+ if err != nil {+ return+ }+ fmt.Fprint(conn, "WELCOME traceway\n")+ conn.Close()+ }+ }()++ port := listener.Addr().(*net.TCPAddr).Port+ now := time.Now().UTC()+ upCheck := createTestCheck(t, projectId, models.CheckTypeTcp,+ fmt.Sprintf(`{"host":"127.0.0.1","port":%d,"expectContains":"WELCOME"}`, port), 60, 1, now.Add(-time.Minute))++ closedPort := port + 1+ downCheck := createTestCheck(t, projectId, models.CheckTypeTcp,+ fmt.Sprintf(`{"host":"127.0.0.1","port":%d}`, closedPort), 60, 1, now.Add(-time.Minute))++ ScheduleOnce(context.Background(), now)+ ExecuteOnce(context.Background(), now)++ if reloaded := reloadCheck(t, upCheck.Id); reloaded.CurrentStatus != models.CheckStatusUp {+ t.Errorf("tcp up check status = %s, want up", reloaded.CurrentStatus)+ }+ if reloaded := reloadCheck(t, downCheck.Id); reloaded.CurrentStatus != models.CheckStatusDown {+ t.Errorf("tcp down check status = %s, want down", reloaded.CurrentStatus)+ }+}diff --git a/backend/cmd/run.go b/backend/cmd/run.goindex 13044411..6f34d064 100644--- a/backend/cmd/run.go+++ b/backend/cmd/run.go@@ -30,6 +30,7 @@ import ("github.com/tracewayapp/traceway/backend/app/sourcemapbackfill""github.com/tracewayapp/traceway/backend/app/storage""github.com/tracewayapp/traceway/backend/app/symbolicator/sourcemap/scopes"+ "github.com/tracewayapp/traceway/backend/app/synthetics""github.com/tracewayapp/traceway/backend/static""github.com/coreos/go-systemd/v22/daemon"@@ -150,6 +151,7 @@ func Run(opts ...Option) {middleware.InitRequireAdminAccess()middleware.InitRequireOrganizationAccess()middleware.InitUseSourceMapAuth()+ middleware.InitUseRunnerAuth()services.InitEmail()services.InitTurnstile()@@ -162,9 +164,12 @@ func Run(opts ...Option) {outbox.RegisterSender(notifications.AdapterSend)outbox.RegisterTerminalHook(notifications.OnOutboxTerminal)notifications.RegisterPageOpener(oncall.OpenPageFromDispatch)+ notifications.RegisterPageResolver(oncall.AutoResolveByDedupKey)+ synthetics.RegisterNotifier(notifications.OnCheckStateChange)outbox.StartDrain(ctx)oncall.StartEscalator(ctx)notifications.StartEvaluator(ctx)+ synthetics.Start(ctx)retention.Start(ctx)recordings.Start(ctx)sourcemapbackfill.Start(ctx)@@ -194,6 +199,12 @@ func Run(opts ...Option) {c.Next()return}+ // The runner poll long-polls for up to 25s; recording it would+ // register as 25s endpoint samples and wreck self-monitoring p95.+ if c.Request.URL.Path == "/api/runners/poll" {+ c.Next()+ return+ }twmw(c)})@@ -201,6 +212,7 @@ func Run(opts ...Option) {monitoring.StartBackendReporter(ctx)monitoring.StartTelemetryDBReporter(ctx)monitoring.StartOutboxReporter(ctx)+ monitoring.StartSyntheticsReporter(ctx)}router.GET("/health", func(c *gin.Context) {@@ -294,6 +306,15 @@ func applyEnvOverrides(cfg *config.Cfg) {{"SMTP_FROM", &cfg.SMTPFrom},{"ONCALL_POLL_SECONDS", &cfg.OncallPollSeconds},{"OUTBOX_POLL_SECONDS", &cfg.OutboxPollSeconds},+ {"SYNTHETICS_POLL_SECONDS", &cfg.SyntheticsPollSeconds},+ {"SYNTHETICS_BROWSER_MODE", &cfg.SyntheticsBrowserMode},+ {"SYNTHETICS_HTTP_CONCURRENCY", &cfg.SyntheticsHTTPConcurrency},+ {"SYNTHETICS_BROWSER_CONCURRENCY", &cfg.SyntheticsBrowserConcurrency},+ {"SYNTHETICS_ALLOW_PRIVATE_TARGETS", &cfg.SyntheticsAllowPrivateTargets},+ {"SYNTHETICS_PLAYWRIGHT_DIR", &cfg.SyntheticsPlaywrightDir},+ {"SYNTHETICS_SCREENSHOT_RETENTION_DAYS", &cfg.SyntheticsScreenshotRetentionDays},+ {"SYNTHETICS_RUNNER_SECRET", &cfg.SyntheticsRunnerSecret},+ {"HEALTH_DEEP_TOKEN", &cfg.HealthDeepToken},{"TWILIO_ACCOUNT_SID", &cfg.TwilioAccountSID},{"TWILIO_AUTH_TOKEN", &cfg.TwilioAuthToken},{"TWILIO_FROM_NUMBER", &cfg.TwilioFromNumber},diff --git a/backend/cmd/traceway-runner/main.go b/backend/cmd/traceway-runner/main.gonew file mode 100644index 00000000..d1a95671--- /dev/null+++ b/backend/cmd/traceway-runner/main.go@@ -0,0 +1,310 @@+// traceway-runner executes browser synthetic checks for a Traceway instance+// running with SYNTHETICS_BROWSER_MODE=remote. It long-polls the backend over+// HTTPS (outbound only, NAT-friendly), runs claimed @playwright/test specs+// via a local Node + Playwright harness, and posts results back.+//+// Runners are operator infrastructure: they authenticate with the same+// SYNTHETICS_RUNNER_SECRET the server was deployed with and self-register+// under their name on first poll. Nothing is created in the dashboard.+//+// Configuration (environment):+//+// TRACEWAY_URL base URL of the Traceway instance (required)+// TRACEWAY_RUNNER_SECRET the server's SYNTHETICS_RUNNER_SECRET (required)+// TRACEWAY_RUNNER_NAME name this runner registers under (default: hostname)+// TRACEWAY_RUNNER_MONITORING optional Traceway SDK connection string+// (<project_token>@<url>/api/report). When set the+// runner reports its own telemetry: server metrics+// (CPU, memory, goroutines), one task trace per+// executed run (tagged check_id/run_id/status), and+// exceptions for infrastructure failures.+// RUNNER_WORKERS concurrent browser runs (default 2)+// SYNTHETICS_PLAYWRIGHT_DIR harness dir with @playwright/test (default .)+//+// Harness setup (once): npm init -y && npm i @playwright/test && npx playwright install chromium+package main++import (+ "bytes"+ "context"+ "encoding/base64"+ "encoding/json"+ "fmt"+ "io"+ "log"+ "net/http"+ "os"+ "os/signal"+ "strconv"+ "strings"+ "sync"+ "syscall"+ "time"++ "github.com/google/uuid"+ "github.com/tracewayapp/traceway/backend/app/synthetics/browserexec"+ traceway "go.tracewayapp.com"+)++const version = "1.0.0"++type runnerConfig struct {+ baseURL string+ secret string+ name string+ monitoring string+ workers int+ harnessDir string+}++type job struct {+ RunId int `json:"runId"`+ CheckId int `json:"checkId"`+ TimeoutSeconds int `json:"timeoutSeconds"`+ Script string `json:"script"`+ Env map[string]string `json:"env"`+}++func main() {+ cfg := loadConfig()+ if err := browserexec.Validate(cfg.harnessDir); err != nil {+ log.Fatalf("Playwright harness unusable at %s: %v\nSet it up with:\n npm init -y && npm i @playwright/test && npx playwright install chromium\nor point SYNTHETICS_PLAYWRIGHT_DIR at an existing harness.", cfg.harnessDir, err)+ }++ ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)+ defer stop()++ if cfg.monitoring != "" {+ if err := traceway.Init(cfg.monitoring,+ traceway.WithServerName(cfg.name),+ traceway.WithVersion(version),+ ); err != nil {+ log.Printf("self-monitoring disabled: %v", err)+ } else {+ log.Printf("self-monitoring enabled (server name: %s)", cfg.name)+ }+ }++ log.Printf("traceway-runner %s (%s): polling %s (workers: %d, harness: %s)", version, cfg.name, cfg.baseURL, cfg.workers, cfg.harnessDir)++ jobs := make(chan job)+ var wg sync.WaitGroup+ for i := 0; i < cfg.workers; i++ {+ wg.Add(1)+ go func() {+ defer wg.Done()+ for j := range jobs {+ executeGuarded(ctx, cfg, j)+ }+ }()+ }++ pollLoop(ctx, cfg, jobs)+ close(jobs)+ wg.Wait()+ log.Println("traceway-runner stopped")+}++func loadConfig() runnerConfig {+ cfg := runnerConfig{+ baseURL: strings.TrimRight(os.Getenv("TRACEWAY_URL"), "/"),+ secret: os.Getenv("TRACEWAY_RUNNER_SECRET"),+ name: strings.TrimSpace(os.Getenv("TRACEWAY_RUNNER_NAME")),+ monitoring: strings.TrimSpace(os.Getenv("TRACEWAY_RUNNER_MONITORING")),+ workers: 2,+ harnessDir: os.Getenv("SYNTHETICS_PLAYWRIGHT_DIR"),+ }+ if cfg.baseURL == "" || cfg.secret == "" {+ log.Fatal("TRACEWAY_URL and TRACEWAY_RUNNER_SECRET are required (the secret must match the server's SYNTHETICS_RUNNER_SECRET)")+ }+ if cfg.name == "" {+ if hostname, err := os.Hostname(); err == nil {+ cfg.name = hostname+ } else {+ cfg.name = "unnamed"+ }+ }+ if raw := os.Getenv("RUNNER_WORKERS"); raw != "" {+ if parsed, err := strconv.Atoi(raw); err == nil && parsed >= 1 && parsed <= 16 {+ cfg.workers = parsed+ }+ }+ if cfg.harnessDir == "" {+ cfg.harnessDir = "."+ }+ return cfg+}++// pollClient outlives the server's 25s long-poll hold.+var pollClient = &http.Client{Timeout: 40 * time.Second}+var resultClient = &http.Client{Timeout: 30 * time.Second}++func pollLoop(ctx context.Context, cfg runnerConfig, jobs chan<- job) {+ for {+ if ctx.Err() != nil {+ return+ }+ claimed, err := poll(ctx, cfg)+ if err != nil {+ if ctx.Err() != nil {+ return+ }+ log.Printf("poll failed: %v (retrying in 5s)", err)+ select {+ case <-ctx.Done():+ return+ case <-time.After(5 * time.Second):+ }+ continue+ }+ for _, j := range claimed {+ select {+ case <-ctx.Done():+ return+ case jobs <- j:+ }+ }+ }+}++func poll(ctx context.Context, cfg runnerConfig) ([]job, error) {+ body, _ := json.Marshal(map[string]int{"maxJobs": cfg.workers})+ req, err := http.NewRequestWithContext(ctx, http.MethodPost, cfg.baseURL+"/api/runners/poll", bytes.NewReader(body))+ if err != nil {+ return nil, err+ }+ setAuthHeaders(req, cfg)+ resp, err := pollClient.Do(req)+ if err != nil {+ return nil, err+ }+ defer resp.Body.Close()+ if resp.StatusCode == http.StatusUnauthorized {+ data, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))+ log.Fatalf("the runner secret was rejected: %s", strings.TrimSpace(string(data)))+ }+ if resp.StatusCode != http.StatusOK {+ data, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))+ return nil, fmt.Errorf("poll returned %d: %s", resp.StatusCode, strings.TrimSpace(string(data)))+ }+ var parsed struct {+ Jobs []job `json:"jobs"`+ }+ if err := json.NewDecoder(resp.Body).Decode(&parsed); err != nil {+ return nil, err+ }+ return parsed.Jobs, nil+}++// executeGuarded isolates a panicking job: log it, report it, keep the+// worker alive for the next claim.+func executeGuarded(ctx context.Context, cfg runnerConfig, j job) {+ defer func() {+ if r := recover(); r != nil {+ log.Printf("run %d (check %d): panicked: %v", j.RunId, j.CheckId, r)+ traceway.CaptureException(fmt.Errorf("panic executing run %d (check %d): %v", j.RunId, j.CheckId, r))+ }+ }()+ execute(ctx, cfg, j)+}++func execute(ctx context.Context, cfg runnerConfig, j job) {+ timeout := time.Duration(j.TimeoutSeconds) * time.Second+ if timeout < 5*time.Second || timeout > 2*time.Minute {+ timeout = time.Minute+ }+ runCtx, cancel := context.WithTimeout(ctx, timeout)+ defer cancel()++ log.Printf("run %d (check %d): executing", j.RunId, j.CheckId)+ started := time.Now()+ result, err := browserexec.Run(runCtx, browserexec.Options{+ HarnessDir: cfg.harnessDir,+ Script: j.Script,+ Env: j.Env,+ Timeout: timeout,+ })++ payload := map[string]any{"status": "down", "latencyMs": float64(time.Since(started).Microseconds()) / 1000}+ if err != nil {+ payload["errorMessage"] = "browser run failed to start: " + err.Error()+ traceway.CaptureException(fmt.Errorf("browser run %d (check %d) failed to start: %w", j.RunId, j.CheckId, err))+ } else {+ if result.DurationMs > 0 {+ payload["latencyMs"] = result.DurationMs+ }+ if result.Passed {+ payload["status"] = "up"+ } else {+ payload["errorMessage"] = result.ErrorMsg+ if len(result.Screenshot) > 0 {+ payload["screenshotBase64"] = base64.StdEncoding.EncodeToString(result.Screenshot)+ }+ if result.Output != "" {+ payload["outputTail"] = result.Output+ }+ }+ }+ log.Printf("run %d (check %d): %s", j.RunId, j.CheckId, payload["status"])++ // One task trace per executed run; no-op unless self-monitoring is on.+ traceway.CaptureTask(+ &traceway.TraceContext{Id: uuid.NewString(), IsTask: true},+ "browser_run",+ time.Since(started),+ started,+ map[string]string{+ "check_id": strconv.Itoa(j.CheckId),+ "run_id": strconv.Itoa(j.RunId),+ "status": payload["status"].(string),+ },+ )++ if err := postResult(ctx, cfg, j.RunId, payload); err != nil {+ log.Printf("run %d: failed to report result: %v", j.RunId, err)+ traceway.CaptureException(fmt.Errorf("failed to report result for run %d (check %d): %w", j.RunId, j.CheckId, err))+ }+}++func postResult(ctx context.Context, cfg runnerConfig, runId int, payload map[string]any) error {+ body, err := json.Marshal(payload)+ if err != nil {+ return err+ }+ // A couple of quick retries; past that the server reclaims the stale+ // claim and re-runs, so the result would be discarded anyway.+ var lastErr error+ for attempt := 0; attempt < 3; attempt++ {+ if attempt > 0 {+ select {+ case <-ctx.Done():+ return lastErr+ case <-time.After(2 * time.Second):+ }+ }+ req, reqErr := http.NewRequestWithContext(ctx, http.MethodPost, cfg.baseURL+"/api/runners/results/"+strconv.Itoa(runId), bytes.NewReader(body))+ if reqErr != nil {+ return reqErr+ }+ setAuthHeaders(req, cfg)+ resp, doErr := resultClient.Do(req)+ if doErr != nil {+ lastErr = doErr+ continue+ }+ io.Copy(io.Discard, io.LimitReader(resp.Body, 4096))+ resp.Body.Close()+ if resp.StatusCode == http.StatusOK {+ return nil+ }+ lastErr = fmt.Errorf("result returned %d", resp.StatusCode)+ }+ return lastErr+}++func setAuthHeaders(req *http.Request, cfg runnerConfig) {+ req.Header.Set("Authorization", "Bearer "+cfg.secret)+ req.Header.Set("Content-Type", "application/json")+ req.Header.Set("X-Traceway-Runner-Version", version)+ req.Header.Set("X-Traceway-Runner-Name", cfg.name)+}diff --git a/benchmarks/compose/docker-compose.duckdb.yml b/benchmarks/compose/docker-compose.duckdb.ymlindex 8ebea08e..07b83d16 100644--- a/benchmarks/compose/docker-compose.duckdb.yml+++ b/benchmarks/compose/docker-compose.duckdb.yml@@ -7,6 +7,7 @@ services:- "${BENCH_PORT:-8087}:80"environment:JWT_SECRET: "bench-jwt-secret-not-for-production-use-only-32chars+"+ HEALTH_DEEP_TOKEN: "bench-health-token-not-for-production"SQLITE_RETENTION_DAYS: "0"SESSION_RECORDING_RETENTION_DAYS: "0"DUCKDB_CHECKPOINT_THRESHOLD: "${DUCKDB_CHECKPOINT_THRESHOLD:-256MB}"diff --git a/benchmarks/compose/docker-compose.managed-ch.yml b/benchmarks/compose/docker-compose.managed-ch.ymlindex b6caf2c0..c276a9da 100644--- a/benchmarks/compose/docker-compose.managed-ch.yml+++ b/benchmarks/compose/docker-compose.managed-ch.yml@@ -18,6 +18,7 @@ services:POSTGRES_PASSWORD: "traceway"POSTGRES_SSLMODE: "disable"JWT_SECRET: "bench-jwt-secret-not-for-production-use-only-32chars+"+ HEALTH_DEEP_TOKEN: "bench-health-token-not-for-production"GIN_MODE: "release"CH_ASYNC_INSERT: "${CH_ASYNC_INSERT:-0}"depends_on:diff --git a/benchmarks/compose/docker-compose.pgch.yml b/benchmarks/compose/docker-compose.pgch.ymlindex 11357768..bf090609 100644--- a/benchmarks/compose/docker-compose.pgch.yml+++ b/benchmarks/compose/docker-compose.pgch.yml@@ -18,6 +18,7 @@ services:POSTGRES_PASSWORD: "traceway"POSTGRES_SSLMODE: "disable"JWT_SECRET: "bench-jwt-secret-not-for-production-use-only-32chars+"+ HEALTH_DEEP_TOKEN: "bench-health-token-not-for-production"GIN_MODE: "release"CH_ASYNC_INSERT: "${CH_ASYNC_INSERT:-0}"depends_on:diff --git a/benchmarks/compose/docker-compose.sqlite.yml b/benchmarks/compose/docker-compose.sqlite.ymlindex 8a365e89..7048de70 100644--- a/benchmarks/compose/docker-compose.sqlite.yml+++ b/benchmarks/compose/docker-compose.sqlite.yml@@ -7,6 +7,7 @@ services:- "${BENCH_PORT:-8087}:80"environment:JWT_SECRET: "bench-jwt-secret-not-for-production-use-only-32chars+"+ HEALTH_DEEP_TOKEN: "bench-health-token-not-for-production"SQLITE_RETENTION_DAYS: "0"SESSION_RECORDING_RETENTION_DAYS: "0"GIN_MODE: "release"diff --git a/benchmarks/loadgen/ch_snapshot.go b/benchmarks/loadgen/ch_snapshot.goindex 7678bf05..d1fb0c0c 100644--- a/benchmarks/loadgen/ch_snapshot.go+++ b/benchmarks/loadgen/ch_snapshot.go@@ -77,7 +77,7 @@ type healthDeepBody struct {// telemetry configured but unreachable) is still parsed and embedded so the// JSON captures the chReachable=false signal.func fetchDeepHealth(ctx context.Context, cfg config, client *http.Client) (chSnapshot, ingestStatsSnapshot) {- if cfg.jwt == "" {+ if cfg.healthToken == "" {return chSnapshot{}, ingestStatsSnapshot{}}@@ -89,7 +89,7 @@ func fetchDeepHealth(ctx context.Context, cfg config, client *http.Client) (chSnfmt.Fprintf(stderrPrefix(), "fetchDeepHealth: build request failed: %v\n", err)return chSnapshot{}, ingestStatsSnapshot{}}- req.Header.Set("Authorization", "Bearer "+cfg.jwt)+ req.Header.Set("Authorization", "Bearer "+cfg.healthToken)resp, err := client.Do(req)if err != nil {diff --git a/benchmarks/loadgen/main.go b/benchmarks/loadgen/main.goindex 4fd4fdc9..abb13f43 100644--- a/benchmarks/loadgen/main.go+++ b/benchmarks/loadgen/main.go@@ -18,6 +18,7 @@ type config struct {target stringprojectToken stringjwt string+ healthToken stringprojectId stringsignal stringscenario string@@ -60,6 +61,7 @@ func main() {flag.StringVar(&cfg.target, "target", "", "Base URL of the system under test (e.g. http://10.0.0.2 or http://localhost:8087)")flag.StringVar(&cfg.projectToken, "token", "", "Project bearer token for OTLP ingest endpoints")flag.StringVar(&cfg.jwt, "jwt", "", "JWT for read endpoints (required when --scenario=read-probe)")+ flag.StringVar(&cfg.healthToken, "health-token", "", "The SUT's HEALTH_DEEP_TOKEN. /api/health/deep is an operator endpoint (dashboard JWTs are rejected); without this the loadgen skips deep-health snapshots, losing dropped-row/saturation detection, merge-idle waits, and digestion gates.")flag.StringVar(&cfg.projectId, "project-id", "", "Project UUID for read endpoints (required when --scenario=read-probe)")flag.StringVar(&cfg.signal, "signal", "", "Which signal to benchmark: spans | metrics | logs (required)")flag.StringVar(&cfg.scenario, "scenario", "throughput", "Scenario: throughput (default, two-phase ingest ramp) | read-probe (ingest to fill levels and probe a read)")diff --git a/benchmarks/scripts/loadgen-bootstrap.sh b/benchmarks/scripts/loadgen-bootstrap.shindex c4e3cdd3..ce278991 100755--- a/benchmarks/scripts/loadgen-bootstrap.sh+++ b/benchmarks/scripts/loadgen-bootstrap.sh@@ -67,6 +67,7 @@ bench_ssh "${LG_IP}" /root/loadgen/loadgen \--target "http://${SUT_PRIVATE_IP}" \--token "${TOKEN}" \--jwt "${JWT}" \+ --health-token "bench-health-token-not-for-production" \--project-id "${PROJECT_ID}" \--signal "${SIGNAL}" \--duration "${DURATION}" \diff --git a/diagrams/docs/monitors/monitor-run-lifecycle.dot b/diagrams/docs/monitors/monitor-run-lifecycle.dotnew file mode 100644index 00000000..fc51194e--- /dev/null+++ b/diagrams/docs/monitors/monitor-run-lifecycle.dot@@ -0,0 +1,40 @@+// Monitors: scheduler -> durable run queue -> executor -> probe -> telemetry,+// fanning out to status pages and alerting. Render:+// dot -Tsvg monitor-run-lifecycle.dot -o monitor-run-lifecycle.svg+// Output belongs in docs/public/monitors/.+// Palette matches the Traceway dark theme (app/globals.css), same language as+// docs/on-call/how-the-pieces-fit-together.dot.+digraph monitor_run_lifecycle {+ bgcolor="transparent";+ rankdir=TB;+ nodesep=0.32;+ ranksep=0.42;+ pad=0.2;+ fontname="Helvetica";++ node [shape=box, style="rounded,filled", fontname="Helvetica", fontsize=14,+ penwidth=1.3, margin="0.30,0.18",+ color="#283041", fillcolor="#151a24", fontcolor="#f4f6fb"];+ edge [color="#5a6374", penwidth=1.4, arrowsize=0.85,+ fontname="Helvetica", fontsize=10, fontcolor="#8a93a6"];++ scheduler [label=<<b>the scheduler ticks</b><br/><font color="#8a93a6" point-size="12">every few seconds, finds checks whose next run is due</font>>,+ fillcolor="#0f131c"];+ queue [label=<<b>run queue</b><br/><font color="#ffc46b" point-size="12">durable rows in the main DB: claims are guarded, restarts lose nothing</font>>,+ color="#f0a020", fillcolor="#1c1710"];+ executor [label=<<b>an executor claims the run</b><br/><font color="#8a93a6" point-size="12">http and tcp in-process · browser per execution mode</font>>];+ probe [label=<<b>the probe runs</b><br/><font color="#8a93a6" point-size="12">HTTP request · TCP connect · Playwright script in Chromium</font>>];+ result [label=<<b>result lands in telemetry</b><br/><font color="#8a93a6" point-size="12">status, latency, error, failure screenshot + logs</font>>];+ alerts [label=<<b>alerts + on-call</b><br/><font color="#b9a7ff" point-size="12">down after N consecutive failures · recovery notifies or auto-resolves the page</font>>,+ color="#7c5cff", fillcolor="#15121f"];+ status [label=<<b>status pages</b><br/><font color="#7ff0c8" point-size="12">90 days of public per-day uptime, no login required</font>>,+ color="#22e0a8", fillcolor="#0c1714"];++ scheduler -> queue -> executor -> probe -> result;+ result -> alerts;+ result -> status;++ queue -> result [constraint=false, tailport=e, headport=e,+ style=dashed, color="#ff5a5f", fontcolor="#ff8a8d",+ label=" past its window:\l recorded as missed,\l never executed late\l"];+}diff --git a/diagrams/docs/monitors/runner-architecture.dot b/diagrams/docs/monitors/runner-architecture.dotnew file mode 100644index 00000000..80c345d3--- /dev/null+++ b/diagrams/docs/monitors/runner-architecture.dot@@ -0,0 +1,59 @@+// Remote runners: the server only queues browser runs; runners long-poll+// outbound with the shared secret and execute the Playwright spec. Render:+// dot -Tsvg runner-architecture.dot -o runner-architecture.svg+// Output belongs in docs/public/monitors/.+// Palette matches the Traceway dark theme (app/globals.css), same language as+// docs/on-call/how-the-pieces-fit-together.dot.+digraph runner_architecture {+ bgcolor="transparent";+ rankdir=TB;+ nodesep=0.35;+ ranksep=0.5;+ pad=0.2;+ fontname="Helvetica";++ node [shape=box, style="rounded,filled", fontname="Helvetica", fontsize=14,+ penwidth=1.3, margin="0.30,0.18",+ color="#283041", fillcolor="#151a24", fontcolor="#f4f6fb"];+ edge [color="#5a6374", penwidth=1.4, arrowsize=0.85,+ fontname="Helvetica", fontsize=10, fontcolor="#8a93a6"];++ subgraph cluster_instance {+ label=<<font color="#8a93a6" point-size="12">YOUR TRACEWAY INSTANCE</font>>;+ labeljust="l";+ color="#283041";+ style="rounded";+ margin=14;++ backend [label=<<b>Traceway backend</b><br/><font color="#8a93a6" point-size="12">SYNTHETICS_BROWSER_MODE=remote + SYNTHETICS_RUNNER_SECRET</font>>,+ fillcolor="#0f131c"];+ bqueue [label=<<b>browser run queue</b><br/><font color="#8a93a6" point-size="12">queued runs wait here; nothing executes on this host</font>>];++ backend -> bqueue [label=" queues browser runs"];+ }++ subgraph cluster_runner {+ label=<<font color="#8a93a6" point-size="12">RUNNER HOST — NO INBOUND PORTS</font>>;+ labeljust="l";+ color="#283041";+ style="rounded";+ margin=14;++ runner [label=<<b>traceway-runner</b><br/><font color="#ffc46b" point-size="12">Go binary under systemd · RUNNER_WORKERS concurrent runs</font>>,+ color="#f0a020", fillcolor="#1c1710"];+ chromium [label=<<b>Node + Playwright + headless Chromium</b><br/><font color="#8a93a6" point-size="12">allowlisted env: scripts never see server or runner secrets</font>>];++ runner -> chromium [label=" spawns per claimed run"];+ }++ target [label=<<b>your app</b><br/><font color="#7ff0c8" point-size="12">the pages and flows the check spec exercises</font>>,+ color="#22e0a8", fillcolor="#0c1714"];++ bqueue -> runner [color="#f0a020", fontcolor="#ffc46b",+ label=" claimed over the runner's long-poll\l Bearer SYNTHETICS_RUNNER_SECRET, outbound from the runner only\l"];+ chromium -> target [label=" runs the check spec"];++ runner -> backend [constraint=false, tailport=e, headport=e,+ style=dashed, color="#f0a020", fontcolor="#ffc46b",+ label=" posts the result\l + failure screenshot and logs\l"];+}diff --git a/docker-compose.browser.yml b/docker-compose.browser.ymlnew file mode 100644index 00000000..4aab7797--- /dev/null+++ b/docker-compose.browser.yml@@ -0,0 +1,60 @@+services:+ traceway:+ build:+ context: .+ dockerfile: Dockerfile.browser+ ports:+ - "80:80"+ # Chromium maps renderer shared memory into /dev/shm; the Docker default+ # of 64MB crashes tabs on heavier pages. The backend also passes+ # --disable-dev-shm-usage as a fallback, but real shm is faster.+ shm_size: "1gb"+ environment:+ JWT_SECRET: "change-this-to-a-secure-secret-at-least-32-chars"+ # APP_BASE_URL: "https://traceway.example.com"++ # DuckDB sizes its memory budget from host RAM, not the container limit.+ # On any memory-capped deployment set this to roughly half the+ # container's RAM or the backend gets OOM-killed under ingest. Leave+ # extra headroom here: each concurrent browser check runs a Chromium.+ DUCKDB_MEMORY_LIMIT: "2GB"+ # DUCKDB_THREADS: "4"+ # DUCKDB_CHECKPOINT_THRESHOLD: "256MB"++ # Synthetics. Browser checks are enabled in this image+ # (SYNTHETICS_BROWSER_MODE=embedded is baked in); http/tcp checks work+ # in every image. Defaults shown.+ # SYNTHETICS_POLL_SECONDS: "15"+ # SYNTHETICS_HTTP_CONCURRENCY: "8"+ # How many Chromium instances may run at once; each costs ~300-500MB.+ # SYNTHETICS_BROWSER_CONCURRENCY: "2"+ # Set to "false" to refuse checks that target private/LAN addresses.+ # SYNTHETICS_ALLOW_PRIVATE_TARGETS: "true"+ # Failure screenshots under STORAGE_PATH/synthetics/, cleaned after N+ # days ("0" disables the cleanup).+ # SYNTHETICS_SCREENSHOT_RETENTION_DAYS: "30"++ # Optional retention knobs. Defaults are 30 days; set to "0" to disable.+ # SQLITE_RETENTION_DAYS: "30"+ # SESSION_RECORDING_RETENTION_DAYS: "30"++ # Optional: store blobs (source maps, session recordings, screenshots)+ # in S3 instead of the local /data/storage folder.+ # STORAGE_TYPE: "s3"+ # S3_BUCKET: "your-bucket"+ # S3_REGION: "us-east-1"+ # S3_ACCESS_KEY: "your-access-key"+ # S3_SECRET_KEY: "your-secret-key"+ # S3_ENDPOINT: "https://s3.example.com" # for MinIO / R2 / Spaces+ volumes:+ - traceway-data:/data+ restart: unless-stopped+ healthcheck:+ test: ["CMD", "wget", "-qO-", "http://localhost/health"]+ interval: 30s+ timeout: 3s+ start_period: 5s+ retries: 3++volumes:+ traceway-data:diff --git a/docker/playwright/package.json b/docker/playwright/package.jsonnew file mode 100644index 00000000..bf280eb4--- /dev/null+++ b/docker/playwright/package.json@@ -0,0 +1,7 @@+{+ "name": "traceway-playwright-harness",+ "private": true,+ "dependencies": {+ "@playwright/test": "1.62.1"+ }+}diff --git a/docs/components/DeploymentCards.jsx b/docs/components/DeploymentCards.jsxindex ba4e599a..f128df26 100644--- a/docs/components/DeploymentCards.jsx+++ b/docs/components/DeploymentCards.jsx@@ -37,6 +37,13 @@ const DEPLOYMENTS = [description:"Single Debian container with a columnar telemetry store. Same zero-dependency setup as SQLite with far more dashboard headroom.",},+ {+ title: "Browser (Monitors)",+ href: "/server/browser",+ subtitle: "DuckDB + Playwright + Chromium",+ description:+ "The DuckDB container plus headless Chromium, so Playwright browser monitors run in-process. HTTP/TCP monitors work in every image.",+ },{title: "Local Setup",href: "/server/local-setup",diff --git a/docs/pages/learn/_meta.json b/docs/pages/learn/_meta.jsonindex 5f8672a1..5231e9fd 100644--- a/docs/pages/learn/_meta.json+++ b/docs/pages/learn/_meta.json@@ -16,6 +16,7 @@"logs": "Logs","alerts": "Alerts","on-call": "On-Call",+ "monitors": "Monitors","sso": "SSO","cli": "CLI","cli-auth": "CLI Authentication",diff --git a/docs/pages/learn/alerts.mdx b/docs/pages/learn/alerts.mdxindex 0f4e5159..fc288db4 100644--- a/docs/pages/learn/alerts.mdx+++ b/docs/pages/learn/alerts.mdx@@ -143,6 +143,9 @@ Rules belong to a project and only evaluate that project's data. Frontend projec| [Metric Threshold](#metric-threshold) | An aggregated metric violates a comparison | Polled || [No Data](#no-data) | No telemetry received for a configured duration | Polled || [AI Trace Cost](#ai-trace-cost) | A single AI trace exceeds a cost threshold | On ingest |+| [AI Conversation Cost](#ai-conversation-cost) | A conversation's cumulative 24-hour cost exceeds a threshold | On ingest |+| [AI Flagged Content](#ai-flagged-content) | An AI conversation matches a flagged content term | On ingest |+| [Monitor Down](#monitor-down) | A monitor crosses its failure threshold | On state change |### New Issue@@ -287,11 +290,36 @@ Fires when a single [AI trace](/learn/ai-tracing) exceeds a cost threshold, catcThe cooldown applies per trace name, so two different expensive workflows alert independently.+### AI Conversation Cost++Fires when the cumulative cost of a single [AI conversation](/learn/ai-tracing) over the last 24 hours crosses the threshold. Where AI Trace Cost catches one expensive call, this catches sessions that get expensive gradually: a runaway agent loop of cheap calls, or a user hammering an assistant.++| Option | Default | Description |+|--------|---------|-------------|+| Cost Threshold | 5 | Cumulative cost in USD a conversation must reach within 24 hours to trigger the alert |++The cooldown applies per conversation, so one noisy conversation alerts once per cooldown window while a second conversation crossing the threshold still alerts immediately.++### AI Flagged Content++Fires when an [AI conversation](/learn/ai-tracing#content-flagging) matches a flagged content term. Matching happens at ingest against the language packs selected in the project's AI settings plus your custom terms, so the alert carries the matched terms.++| Option | Default | Description |+|--------|---------|-------------|+| Terms | all | Optional comma-separated list to narrow the rule to specific terms; empty fires on any flagged match |++### Monitor Down++Fires when a [monitor](/learn/monitors) transitions to down, which happens only after its configured number of consecutive failures, and sends a recovery notice when it comes back up. One rule covers every monitor in the project; the alert names the monitor and carries the last probe error.++There are no rule-specific options. Pointing the rule at an escalation channel opens an [on-call page](/learn/on-call) instead of sending a message: the page deduplicates per monitor, re-fires never restart its escalation clock, and recovery resolves it automatically.+## Evaluation Model and Cost-Rules are evaluated in one of two ways:+Rules are evaluated in one of three ways:-- **On ingest** (New Issue, Error Regression, AI Trace Cost): evaluated immediately as reports arrive, so alerts fire within seconds of the triggering event.+- **On ingest** (New Issue, Error Regression, AI Trace Cost, AI Conversation Cost, AI Flagged Content): evaluated immediately as reports arrive, so alerts fire within seconds of the triggering event.+- **On state change** (Monitor Down): fires the moment a probe result flips the monitor's up/down state, independent of any poll interval.- **Polled** (everything else): a background loop evaluates all enabled polled rules on an interval. The default is every 60 seconds; self-hosted deployments can tune it with `NOTIFICATION_POLL_SECONDS` (minimum 5). Detection latency for polled rules is at most one poll interval.Each rule type has a different evaluation cost against the telemetry database. This matters mostly for self-hosted deployments with many rules or high data volume:@@ -299,6 +327,9 @@ Each rule type has a different evaluation cost against the telemetry database. T| Rule | Work per evaluation | Relative cost ||------|--------------------|---------------|| AI Trace Cost | In-memory check of the ingested batch, no queries | Minimal |+| AI Flagged Content | In-memory check of flags set at ingest, no queries | Minimal |+| Monitor Down | In-memory on the state transition, no queries | Minimal |+| AI Conversation Cost | One 24-hour cost sum per conversation in the batch | Low || New Issue | 1 to 3 indexed lookups per distinct new error in the batch | Low || Error Regression | 1 indexed lookup per distinct error in the batch | Low || Error Rate | One aggregate over the lookback window | Low |diff --git a/docs/pages/learn/monitors.mdx b/docs/pages/learn/monitors.mdxnew file mode 100644index 00000000..c188193e--- /dev/null+++ b/docs/pages/learn/monitors.mdx@@ -0,0 +1,79 @@+# Monitors++Monitors answer the question your telemetry cannot: is the service actually reachable from the outside? Traces and logs only exist while requests arrive. A monitor keeps probing on a schedule, so you find out your site is down before a user tells you.++They live under **Monitors** in the sidebar, with tabs for the monitors themselves and **Status Pages**. The badge counts the monitors currently down on the current project.++## Check types++- **HTTP** probes a URL like Postman would: method, headers, auth (basic, bearer, or a custom header), request body, and a set of expected results. You can assert on status codes, response body content (substring or regex), a maximum response time, and a minimum number of days before the TLS certificate expires. With no status assertion, anything below 400 counts as up.+- **TCP** connects to a host and port, optionally over TLS, optionally sending a payload and asserting on the response. Useful for databases, SMTP, or anything that is not HTTP.+- **Browser** runs a real [@playwright/test](https://playwright.dev) script in headless Chromium. You write the spec in a code editor right on the check, so a login flow or a checkout journey can be your uptime probe. Failed runs automatically store a screenshot and the Playwright output; both open from the run history (the screenshot and logs links).++Every check has an interval (30 seconds to 24 hours), a timeout, and a failure threshold. The threshold is flap damping: a check only transitions to **down** after that many consecutive failures, so one flaky probe does not page anyone at 3am.++## How runs work++A scheduler enqueues each due check into a durable run queue in the main database, and executors claim runs from it. Results land in the telemetry store, so uptime and latency charts use the same retention and aggregation machinery as everything else.++<img src="/monitors/monitor-run-lifecycle.svg" alt="Monitor run lifecycle: the scheduler enqueues due checks into the run queue, an executor claims and probes, results land in telemetry feeding status pages and alerts, and expired queued runs are recorded as missed" style={{ maxWidth: '100%', height: 'auto', marginTop: '16px' }} />++Two properties matter operationally:++- **A probe never runs late.** A queued run that outlives its window (the check's interval, capped at five minutes) is recorded as `missed`, not executed. A stale "is it up" answer would corrupt the uptime timeline.+- **Downtime of Traceway itself shows as a gap, not as uptime.** If the backend was off, no runs existed, and the charts show unknown rather than a fabricated 100%.++## Alerting++Add a notification rule of type **Monitor Down** on the Alerts page. It fires when any monitor in the project crosses its failure threshold, and sends a recovery notice when the check comes back. Pointing the rule at an escalation channel opens an on-call page instead; the page deduplicates per check, and recovery resolves it automatically, so a blip at night that recovers by itself never needs a human.++## Status pages++A status page publishes the uptime of selected monitors at `/status/<slug>`: a branded light page with 90 days of per-day uptime bars (green operational, amber partial outage, red major outage, gray no data), incident history, and no login required. Create one under the **Status Pages** tab on the Monitors page (organization admins only), pick the monitors, choose a slug, and toggle it public. Branding: a title, an optional description, and an uploaded PNG/JPEG logo. Latency numbers stay internal; the public payload only carries availability.++### Custom domains++Each status page can carry a custom domain (for example `status.acme.com`):++1. Set the domain on the status page.+2. Create a DNS CNAME from that hostname to your Traceway instance's hostname.+3. Terminate TLS for the vanity hostname at your reverse proxy (Caddy and Traefik can issue certificates for it automatically; with nginx use certbot).++Anonymous visitors hitting the instance under that Host are routed to the status page automatically (the backend maps the Host header to the page via `/api/status-domains/resolve`).++## Browser execution modes++Browser checks execute real user-authored JavaScript, so where that code runs is an explicit deployment decision, controlled by `SYNTHETICS_BROWSER_MODE`:++| Mode | What it means |+|------|---------------|+| `off` (default) | HTTP and TCP checks only. Works in every image with no size cost; creating a browser check is rejected with a pointer here. Existing browser checks stay editable and pausable, and simply do not run until a browser mode is enabled. |+| `embedded` | The backend spawns Playwright in-process. Ships ready to go in the [`:browser` image](/server/browser), or [without Docker](/server/browser#without-docker) on any host with Node and a Playwright harness. |+| `remote` | The backend only queues browser runs; one or more [**runners**](/server/runner) claim and execute them. |++Runners are deployment infrastructure, managed by whoever operates the server, not by dashboard users. There is nothing to create in the UI: set a shared secret on the server (`SYNTHETICS_RUNNER_SECRET`, required for `remote` mode) and start the `traceway-runner` binary anywhere with outbound HTTPS. Each runner self-registers under its name on first poll and only makes outbound connections (long-polling), so it works behind NAT with no inbound port. Work distributes itself: an idle runner claims the next queued run, a busy one is not asking, so adding capacity is just starting more runners. Rotate the fleet credential by changing the secret and restarting the runners.++The [Remote Runners guide](/server/runner) walks through the whole setup: getting the binary, preparing the Playwright harness, a systemd unit, verifying the runner is attached, and operations like rotation, scaling, and per-runner self-monitoring via `TRACEWAY_RUNNER_MONITORING`.++Browser check scripts run with an allowlisted environment: they see the variables configured on the check, never the server's own environment. In embedded mode the scripts still execute inside the Traceway container as arbitrary code, which is the trade-off for one-container convenience; use `remote` mode to keep them off the box entirely. Browser checks are disabled in cloud mode.++## Configuration++```bash+SYNTHETICS_POLL_SECONDS=15 # scheduler tick+SYNTHETICS_BROWSER_MODE=off # off | embedded | remote+SYNTHETICS_HTTP_CONCURRENCY=8 # concurrent http/tcp probes+SYNTHETICS_BROWSER_CONCURRENCY=2 # concurrent Chromium instances (embedded)+SYNTHETICS_ALLOW_PRIVATE_TARGETS=true # "false" refuses checks against private/LAN addresses+SYNTHETICS_PLAYWRIGHT_DIR=/opt/traceway-playwright # harness dir (embedded/runner)+SYNTHETICS_SCREENSHOT_RETENTION_DAYS=30 # failure screenshots on local storage; 0 disables cleanup+SYNTHETICS_RUNNER_SECRET= # shared runner credential; required for remote mode+```++When private targets are allowed (the default), HTTP probes honor the standard `HTTP_PROXY`/`HTTPS_PROXY` environment variables, so monitors work on instances that can only reach the internet through an egress proxy. With `SYNTHETICS_ALLOW_PRIVATE_TARGETS=false` the proxy is deliberately ignored: the private-address guard vets the exact address being dialed, and a proxy tunnel would blind it. On Traceway Cloud, checks can only target public addresses; the guard is always on there.++Check results follow the telemetry retention of your deployment (the SQLite/DuckDB retention worker, or a 90-day TTL on ClickHouse).++### Monitoring the monitors++When self-monitoring is on (`MONITORING_TRACEWAY_URL`), the instance emits `traceway.synthetics.*` metrics every 10 seconds: `queued`, `claimed`, `oldest_queued_sec`, `checks_down`, `runners_online`, and `executed.delta` / `missed.delta`. A healthy fleet shows near-zero queue age, throughput on `executed.delta`, and zero `missed.delta`; alert on `runners_online` dropping to 0 in remote mode. `/api/health/deep` exposes the same numbers as a `synthetics` block; it is an operator endpoint gated by the `HEALTH_DEEP_TOKEN` deploy secret (unset disables it).diff --git a/docs/pages/learn/on-call.mdx b/docs/pages/learn/on-call.mdxindex db99da13..2b437ced 100644--- a/docs/pages/learn/on-call.mdx+++ b/docs/pages/learn/on-call.mdx@@ -287,7 +287,7 @@ Because the level advance and the deliveries commit together, a crash mid-incideDeliveries that fail are retried on a backoff of 1, 5, 15, and 60 minutes, up to five attempts, before being recorded as permanently failed and reported as an exception. Acknowledging cancels anything still queued, and a cancelled delivery can never come back to life, though a send already in flight may still land once.-The `outbox` block on `/api/health/deep` exposes queue depth and the oldest pending delivery, so you can alert on your alerting.+The `outbox` block on `/api/health/deep` exposes queue depth and the oldest pending delivery, so you can alert on your alerting. It is an operator endpoint gated by the `HEALTH_DEEP_TOKEN` deploy secret (unset disables it).## Configurationdiff --git a/docs/pages/server/_meta.json b/docs/pages/server/_meta.jsonindex 1517d254..f72ca600 100644--- a/docs/pages/server/_meta.json+++ b/docs/pages/server/_meta.json@@ -5,6 +5,8 @@"minimal": "Minimal Container","sqlite": "SQLite","duckdb": "DuckDB",+ "browser": "Browser (Monitors)",+ "runner": "Remote Runners","local-setup": "Local Setup","storage": "Blob Storage","haloy": "Haloy",diff --git a/docs/pages/server/browser.mdx b/docs/pages/server/browser.mdxnew file mode 100644index 00000000..56d42ec5--- /dev/null+++ b/docs/pages/server/browser.mdx@@ -0,0 +1,79 @@+# Browser (Monitors)++The [DuckDB deployment](/server/duckdb) plus Node, `@playwright/test`, and headless Chromium baked in, so [browser monitors](/learn/monitors) run inside the container with zero extra moving parts (`SYNTHETICS_BROWSER_MODE=embedded` is set by default). HTTP and TCP checks work in every image; this image exists only for the browser ones.++Pick this when you want Playwright uptime checks with one container. If you already run another image (SQLite, DuckDB, minimal, or all-in-one), you do not need to switch: set `SYNTHETICS_BROWSER_MODE=remote` there and execute browser checks with the [`traceway-runner` binary](/server/runner) instead. Running Traceway as a plain binary with no Docker at all? See [Without Docker](#without-docker) below.++Operational notes on top of the DuckDB image:++- **The image is significantly larger** (Chromium and its system libraries add several hundred MB).+- **Chromium needs shared memory.** Docker's default 64MB `/dev/shm` crashes tabs on heavier pages; run with `--shm-size=1g` (the compose file sets it). The backend also passes `--disable-dev-shm-usage` as a fallback.+- **Leave memory headroom.** Each concurrent browser check runs a Chromium instance (roughly 300 to 500MB); `SYNTHETICS_BROWSER_CONCURRENCY` defaults to 2. Budget `DUCKDB_MEMORY_LIMIT` accordingly.+- **Browser checks execute user-authored scripts** inside this container, as root with Chromium's sandbox off (the standard containerized-Playwright trade-off). Anyone with write access to a project can author them; if that trust model does not fit, use `remote` mode instead.++## Quick Start++```bash+docker pull ghcr.io/tracewayapp/traceway:browser++docker run -d --name traceway \+ -p 80:80 \+ --shm-size=1g \+ -v "$(pwd)/traceway-data:/data" \+ -e JWT_SECRET="your-jwt-secret-min-32-characters-long" \+ -e APP_BASE_URL="https://traceway.example.com" \+ -e DUCKDB_MEMORY_LIMIT="2GB" \+ ghcr.io/tracewayapp/traceway:browser+```++Or with compose: `docker compose -f docker-compose.browser.yml up -d`.++After starting, open `http://localhost/register` to create your first account, then create a monitor under **Monitors**.++## Build from Source++```bash+docker build -f Dockerfile.browser -t traceway:browser .+```++The pinned `@playwright/test` version lives in `docker/playwright/package.json`; the matching Chromium build is downloaded at image build time, never at runtime.++## Without Docker++Embedded mode does not actually require this image. The image is packaging; the real requirements are `node` on PATH and a harness directory containing `@playwright/test` plus a downloaded Chromium. If you run the Traceway backend as a plain binary (a single EC2 instance, a bare-metal box), you can enable browser monitors on that same host:++```bash+# One-time harness setup (Node 18+ required)+sudo mkdir -p /opt/traceway-playwright && cd /opt/traceway-playwright+npm init -y && npm i @playwright/test+npx playwright install --with-deps chromium+```++Then add to the backend's environment and restart:++```bash+SYNTHETICS_BROWSER_MODE=embedded+SYNTHETICS_PLAYWRIGHT_DIR=/opt/traceway-playwright+```++The backend validates the harness at startup and fails fast with a pointer here if `node` or the Playwright CLI is missing. `--with-deps` covers apt-based distros; on rpm-based distros (Amazon Linux) install Chromium's shared libraries with your package manager.++Keep in mind what embedded means: browser checks are user-authored scripts executing on the host that runs your backend, and each concurrent Chromium costs roughly 300 to 500MB (`SYNTHETICS_BROWSER_CONCURRENCY`, default 2). If either bothers you, run the checks somewhere else with a [remote runner](/server/runner) instead. Both paths work without Docker.++## Configuration++Everything from the [DuckDB page](/server/duckdb#configuration) applies unchanged. On top of that:++| Variable | Default | Description |+|----------|---------|-------------|+| `SYNTHETICS_BROWSER_MODE` | `embedded` *(in this image)* | `off`, `embedded`, or `remote`. Other images default to `off`. |+| `SYNTHETICS_BROWSER_CONCURRENCY` | `2` | Concurrent Chromium instances. |+| `SYNTHETICS_HTTP_CONCURRENCY` | `8` | Concurrent http/tcp probes. |+| `SYNTHETICS_POLL_SECONDS` | `15` | Scheduler tick for due checks. |+| `SYNTHETICS_ALLOW_PRIVATE_TARGETS` | `true` | Set `false` to refuse checks that resolve to private/LAN addresses (re-checked at connect time). |+| `SYNTHETICS_SCREENSHOT_RETENTION_DAYS` | `30` | Days to keep failure screenshots under `/data/storage/synthetics/`. `0` disables the cleanup. |+| `SYNTHETICS_PLAYWRIGHT_DIR` | `/opt/traceway-playwright` | The baked-in Playwright harness; only override for custom builds. |++## Access Points++Identical to the [DuckDB image](/server/duckdb#access-points). `/api/health/deep` additionally reports a `synthetics` block (queue depth, checks down, connected runners); it is gated by the `HEALTH_DEEP_TOKEN` deploy secret.diff --git a/docs/pages/server/duckdb.mdx b/docs/pages/server/duckdb.mdxindex ef91432a..f4bc283b 100644--- a/docs/pages/server/duckdb.mdx+++ b/docs/pages/server/duckdb.mdx@@ -83,7 +83,7 @@ The two images share the same main database file, so users, projects, tokens, an| `http://localhost/` | Frontend dashboard || `http://localhost/api/*` | Backend API || `http://localhost/health` | Health check |-| `http://localhost/api/health/deep` | Telemetry store introspection (authenticated): dropped rows, insert failures, db/WAL size, engine memory |+| `http://localhost/api/health/deep` | Telemetry store introspection (operator endpoint, requires the `HEALTH_DEEP_TOKEN` bearer secret; unset disables it): dropped rows, insert failures, db/WAL size, engine memory |## Useful Commandsdiff --git a/docs/pages/server/runner.mdx b/docs/pages/server/runner.mdxnew file mode 100644index 00000000..5d3fa473--- /dev/null+++ b/docs/pages/server/runner.mdx@@ -0,0 +1,108 @@+# Remote Runners++`traceway-runner` executes [browser monitors](/learn/monitors) for a Traceway instance running with `SYNTHETICS_BROWSER_MODE=remote`. The server only queues browser runs; runners claim them over an outbound long-poll, execute the Playwright spec in headless Chromium, and post the result back. HTTP and TCP monitors never need a runner, they run inside every image and every plain-binary deployment.++<img src="/monitors/runner-architecture.svg" alt="Remote runner architecture: the runner long-polls the Traceway backend with the shared secret over outbound HTTPS, spawns Node and Playwright per claimed run, and executes the check spec in headless Chromium against your app" style={{ maxWidth: '100%', height: 'auto', marginTop: '16px' }} />++Use a runner when you want browser checks but:++- your Traceway deployment is a plain binary or a non-browser image and you would rather not put Node and Chromium on that host,+- you do not want user-authored check scripts executing on the box that holds your data,+- you want to probe from a different network vantage point, or scale browser capacity horizontally.++If you run a single host and are fine with checks executing there, [embedded mode](/server/browser#without-docker) is simpler: no secret, no extra process.++## How runners authenticate++Runners are deployment infrastructure, not dashboard entities. There is nothing to create in the UI and there are no per-runner tokens:++- The server holds one shared credential, `SYNTHETICS_RUNNER_SECRET`. Every runner presents it as an `Authorization: Bearer` header on `POST /api/runners/poll` and `POST /api/runners/results/:runId`. Treat it like any other deploy secret.+- A runner self-registers a liveness row under its `TRACEWAY_RUNNER_NAME` (defaults to the hostname) on first poll. The name is also its claim identity, so give each runner a unique name.+- Traffic is outbound only. The runner long-polls the server (each poll is held up to 25 seconds), so it works behind NAT with no inbound ports and no firewall changes.+- Rotation: change the secret on the server, restart it, update the runners, restart them. A runner presenting a stale secret exits immediately with a clear error.+- The runner receives only the check script and the env vars configured on that check. Scripts run with an allowlisted environment, so they can never read the server's env or the runner's own secret.+- If a runner dies mid-run, the server reclaims the stale run after 5 minutes. An expired run is recorded as `missed`, never executed late.++## 1. Enable remote mode on the server++Add to the Traceway backend's environment and restart it:++```bash+SYNTHETICS_BROWSER_MODE=remote+SYNTHETICS_RUNNER_SECRET=$(openssl rand -hex 32) # generate once, keep it+```++The backend refuses to start in remote mode without the secret. Two behaviors worth knowing: creating a browser monitor is rejected with a pointer here while the mode is `off`, and the poll endpoint answers `403` unless the mode is actually `remote`, so a runner pointed at a misconfigured server logs explicit errors instead of idling silently.++## 2. Prepare the runner host++Any Linux, macOS, or Windows host with outbound HTTPS works. A small VM (2 vCPU, 2 to 4GB RAM) comfortably runs the default 2 workers; each concurrent Chromium costs roughly 300 to 500MB.++**Get the binary.** Each backend release attaches prebuilt binaries (`traceway-runner_linux_amd64`, `traceway-runner_linux_arm64`, and darwin/windows variants) to the GitHub release. Or build it yourself, it is CGO-free:++```bash+cd backend && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o traceway-runner ./cmd/traceway-runner+```++**Set up the Playwright harness.** The runner never uses npm at runtime; it spawns `node` against a directory that has `@playwright/test` installed. Pinning the browser download inside the harness keeps the service independent of `$HOME`:++```bash+sudo mkdir -p /opt/traceway-runner && cd /opt/traceway-runner+npm init -y && npm i @playwright/test+PLAYWRIGHT_BROWSERS_PATH=/opt/traceway-runner/browsers npx playwright install --with-deps chromium+```++`--with-deps` installs Chromium's system libraries on apt-based distros (Ubuntu, Debian). On Amazon Linux or other rpm-based distros, run `npx playwright install chromium` and install the shared libraries with your package manager instead.++## 3. Run it as a service++Run the binary under a dedicated non-root user: it executes user-authored scripts. A systemd unit:++```ini+[Unit]+Description=Traceway synthetic runner+After=network-online.target+Wants=network-online.target++[Service]+User=traceway-runner+WorkingDirectory=/opt/traceway-runner+Environment=TRACEWAY_URL=https://traceway.example.com+Environment=TRACEWAY_RUNNER_SECRET=<the server's SYNTHETICS_RUNNER_SECRET>+Environment=TRACEWAY_RUNNER_NAME=prod-runner-1+Environment=RUNNER_WORKERS=2+Environment=SYNTHETICS_PLAYWRIGHT_DIR=/opt/traceway-runner+Environment=PLAYWRIGHT_BROWSERS_PATH=/opt/traceway-runner/browsers+Restart=always+RestartSec=5++[Install]+WantedBy=multi-user.target+```++```bash+sudo systemctl enable --now traceway-runner+```++Shutdown is graceful: on SIGTERM the runner stops polling, lets in-flight runs finish or be reclaimed, and exits.++| Variable | Default | Description |+|----------|---------|-------------|+| `TRACEWAY_URL` | required | Base URL of the Traceway instance. |+| `TRACEWAY_RUNNER_SECRET` | required | Must match the server's `SYNTHETICS_RUNNER_SECRET`. |+| `TRACEWAY_RUNNER_NAME` | hostname | Unique name; the runner registers and claims runs under it. |+| `RUNNER_WORKERS` | `2` | Concurrent browser runs (max 16). |+| `SYNTHETICS_PLAYWRIGHT_DIR` | `.` | Harness dir containing `node_modules/@playwright/test`. |+| `TRACEWAY_RUNNER_MONITORING` | unset | Optional `<project_token>@<url>/api/report`. The runner then reports its own CPU/memory metrics, one `browser_run` task per executed check, and exceptions for infra failures. |++## 4. Verify++- The runner log prints `polling https://... (workers: 2, harness: ...)` and then `run N (check M): executing` once browser runs are due.+- `GET /api/health/deep` (with your `HEALTH_DEEP_TOKEN`) shows `synthetics.runnersOnline: 1` and, over time, `executedTotal` climbing with `missedTotal` flat.+- In the dashboard, run history rows for browser monitors show `via <runner name>`, and failed runs carry their screenshot and logs links.++## Scaling and operations++- **More capacity** is just more runners, or a higher `RUNNER_WORKERS`. Work distributes itself: an idle runner claims the next queued run, a busy one is not asking.+- **Upgrades**: replace the binary and restart. The version is reported per runner and visible in its liveness row.+- **Same host as the server?** It works (point `TRACEWAY_URL` at `http://127.0.0.1:8082`), but on a single host [embedded mode](/server/browser#without-docker) does the same job with fewer moving parts. The runner earns its keep once scripts should live off the server box.diff --git a/docs/public/monitors/monitor-run-lifecycle.svg b/docs/public/monitors/monitor-run-lifecycle.svgnew file mode 100644index 00000000..92a703dd--- /dev/null+++ b/docs/public/monitors/monitor-run-lifecycle.svg@@ -0,0 +1,106 @@+<?xml version="1.0" encoding="UTF-8" standalone="no"?>+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">+<!-- Generated by graphviz version 15.1.1 (20260805.0921)+ -->+<!-- Title: monitor_run_lifecycle Pages: 1 -->+<svg width="829pt" height="528pt"+ viewBox="0.00 0.00 829.00 528.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">+<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(14.4 513.67)">+<title>monitor_run_lifecycle</title>+<!-- scheduler -->+<g id="node1" class="node">+<title>scheduler</title>+<path fill="#0f131c" stroke="#283041" stroke-width="1.3" d="M584.45,-499.27C584.45,-499.27 275,-499.27 275,-499.27 269,-499.27 263,-493.27 263,-487.27 263,-487.27 263,-459.35 263,-459.35 263,-453.35 269,-447.35 275,-447.35 275,-447.35 584.45,-447.35 584.45,-447.35 590.45,-447.35 596.45,-453.35 596.45,-459.35 596.45,-459.35 596.45,-487.27 596.45,-487.27 596.45,-493.27 590.45,-499.27 584.45,-499.27"/>+<text xml:space="preserve" text-anchor="start" x="368.6" y="-474.01" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="14.00" fill="#f4f6fb">the scheduler ticks</text>+<text xml:space="preserve" text-anchor="start" x="284.6" y="-461.91" font-family="Helvetica,sans-Serif" font-size="12.00" fill="#8a93a6">every few seconds, finds checks whose next run is due</text>+</g>+<!-- queue -->+<g id="node2" class="node">+<title>queue</title>+<path fill="#1c1710" stroke="#f0a020" stroke-width="1.3" d="M625.33,-416.35C625.33,-416.35 234.13,-416.35 234.13,-416.35 228.12,-416.35 222.13,-410.35 222.13,-404.35 222.13,-404.35 222.13,-376.43 222.13,-376.43 222.13,-370.43 228.13,-364.43 234.13,-364.43 234.13,-364.43 625.33,-364.43 625.33,-364.43 631.33,-364.43 637.33,-370.43 637.33,-376.43 637.33,-376.43 637.33,-404.35 637.33,-404.35 637.33,-410.35 631.33,-416.35 625.33,-416.35"/>+<text xml:space="preserve" text-anchor="start" x="397.1" y="-391.09" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="14.00" fill="#f4f6fb">run queue</text>+<text xml:space="preserve" text-anchor="start" x="243.73" y="-378.99" font-family="Helvetica,sans-Serif" font-size="12.00" fill="#ffc46b">durable rows in the main DB: claims are guarded, restarts lose nothing</text>+</g>+<!-- scheduler->queue -->+<g id="edge1" class="edge">+<title>scheduler->queue</title>+<path fill="none" stroke="#5a6374" stroke-width="1.4" d="M429.73,-446.71C429.73,-440.45 429.73,-433.64 429.73,-427"/>+<polygon fill="#5a6374" stroke="#5a6374" stroke-width="1.4" points="432.7,-427.45 429.73,-418.95 426.75,-427.45 432.7,-427.45"/>+</g>+<!-- executor -->+<g id="node3" class="node">+<title>executor</title>+<path fill="#151a24" stroke="#283041" stroke-width="1.3" d="M579.2,-333.43C579.2,-333.43 280.25,-333.43 280.25,-333.43 274.25,-333.43 268.25,-327.43 268.25,-321.43 268.25,-321.43 268.25,-293.51 268.25,-293.51 268.25,-287.51 274.25,-281.51 280.25,-281.51 280.25,-281.51 579.2,-281.51 579.2,-281.51 585.2,-281.51 591.2,-287.51 591.2,-293.51 591.2,-293.51 591.2,-321.43 591.2,-321.43 591.2,-327.43 585.2,-333.43 579.2,-333.43"/>+<text xml:space="preserve" text-anchor="start" x="343.85" y="-308.17" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="14.00" fill="#f4f6fb">an executor claims the run</text>+<text xml:space="preserve" text-anchor="start" x="289.85" y="-296.07" font-family="Helvetica,sans-Serif" font-size="12.00" fill="#8a93a6">http and tcp in-process · browser per execution mode</text>+</g>+<!-- queue->executor -->+<g id="edge2" class="edge">+<title>queue->executor</title>+<path fill="none" stroke="#5a6374" stroke-width="1.4" d="M429.73,-363.79C429.73,-357.53 429.73,-350.72 429.73,-344.08"/>+<polygon fill="#5a6374" stroke="#5a6374" stroke-width="1.4" points="432.7,-344.53 429.73,-336.03 426.75,-344.53 432.7,-344.53"/>+</g>+<!-- result -->+<g id="node5" class="node">+<title>result</title>+<path fill="#151a24" stroke="#283041" stroke-width="1.3" d="M560.08,-134.84C560.08,-134.84 299.38,-134.84 299.38,-134.84 293.38,-134.84 287.38,-128.84 287.38,-122.84 287.38,-122.84 287.38,-94.92 287.38,-94.92 287.38,-88.92 293.38,-82.92 299.38,-82.92 299.38,-82.92 560.08,-82.92 560.08,-82.92 566.08,-82.92 572.08,-88.92 572.08,-94.92 572.08,-94.92 572.08,-122.84 572.08,-122.84 572.08,-128.84 566.08,-134.84 560.08,-134.84"/>+<text xml:space="preserve" text-anchor="start" x="351.73" y="-109.58" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="14.00" fill="#f4f6fb">result lands in telemetry</text>+<text xml:space="preserve" text-anchor="start" x="308.98" y="-97.48" font-family="Helvetica,sans-Serif" font-size="12.00" fill="#8a93a6">status, latency, error, failure screenshot + logs</text>+</g>+<!-- queue->result -->+<g id="edge7" class="edge">+<title>queue:e->result:e</title>+<path fill="none" stroke="#ff5a5f" stroke-width="1.4" stroke-dasharray="5,2" d="M638.33,-390.39C763.25,-390.39 704.93,-124.06 583.47,-109.5"/>+<polygon fill="#ff5a5f" stroke="#ff5a5f" stroke-width="1.4" points="583.85,-106.54 575.19,-109.01 583.5,-112.48 583.85,-106.54"/>+<text xml:space="preserve" text-anchor="start" x="705.21" y="-257.01" font-family="Helvetica,sans-Serif" font-size="10.00" fill="#ff8a8d">  past its window:</text>+<text xml:space="preserve" text-anchor="start" x="705.21" y="-245.76" font-family="Helvetica,sans-Serif" font-size="10.00" fill="#ff8a8d">  recorded as missed,</text>+<text xml:space="preserve" text-anchor="start" x="705.21" y="-234.51" font-family="Helvetica,sans-Serif" font-size="10.00" fill="#ff8a8d">  never executed late</text>+</g>+<!-- probe -->+<g id="node4" class="node">+<title>probe</title>+<path fill="#151a24" stroke="#283041" stroke-width="1.3" d="M600.2,-217.76C600.2,-217.76 259.25,-217.76 259.25,-217.76 253.25,-217.76 247.25,-211.76 247.25,-205.76 247.25,-205.76 247.25,-177.84 247.25,-177.84 247.25,-171.84 253.25,-165.84 259.25,-165.84 259.25,-165.84 600.2,-165.84 600.2,-165.84 606.2,-165.84 612.2,-171.84 612.2,-177.84 612.2,-177.84 612.2,-205.76 612.2,-205.76 612.2,-211.76 606.2,-217.76 600.2,-217.76"/>+<text xml:space="preserve" text-anchor="start" x="382.48" y="-192.5" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="14.00" fill="#f4f6fb">the probe runs</text>+<text xml:space="preserve" text-anchor="start" x="268.85" y="-180.4" font-family="Helvetica,sans-Serif" font-size="12.00" fill="#8a93a6">HTTP request · TCP connect · Playwright script in Chromium</text>+</g>+<!-- executor->probe -->+<g id="edge3" class="edge">+<title>executor->probe</title>+<path fill="none" stroke="#5a6374" stroke-width="1.4" d="M429.73,-280.96C429.73,-265.46 429.73,-245.43 429.73,-228.39"/>+<polygon fill="#5a6374" stroke="#5a6374" stroke-width="1.4" points="432.7,-228.84 429.73,-220.34 426.75,-228.84 432.7,-228.84"/>+</g>+<!-- probe->result -->+<g id="edge4" class="edge">+<title>probe->result</title>+<path fill="none" stroke="#5a6374" stroke-width="1.4" d="M429.73,-165.2C429.73,-158.94 429.73,-152.13 429.73,-145.49"/>+<polygon fill="#5a6374" stroke="#5a6374" stroke-width="1.4" points="432.7,-145.94 429.73,-137.44 426.75,-145.94 432.7,-145.94"/>+</g>+<!-- alerts -->+<g id="node6" class="node">+<title>alerts</title>+<path fill="#15121f" stroke="#7c5cff" stroke-width="1.3" d="M441.45,-51.92C441.45,-51.92 12,-51.92 12,-51.92 6,-51.92 0,-45.92 0,-39.92 0,-39.92 0,-12 0,-12 0,-6 6,0 12,0 12,0 441.45,0 441.45,0 447.45,0 453.45,-6 453.45,-12 453.45,-12 453.45,-39.92 453.45,-39.92 453.45,-45.92 447.45,-51.92 441.45,-51.92"/>+<text xml:space="preserve" text-anchor="start" x="179.1" y="-26.66" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="14.00" fill="#f4f6fb">alerts + on-call</text>+<text xml:space="preserve" text-anchor="start" x="21.6" y="-14.56" font-family="Helvetica,sans-Serif" font-size="12.00" fill="#b9a7ff">down after N consecutive failures · recovery notifies or auto-resolves the page</text>+</g>+<!-- result->alerts -->+<g id="edge5" class="edge">+<title>result->alerts</title>+<path fill="none" stroke="#5a6374" stroke-width="1.4" d="M365.49,-82.28C344.84,-74.04 321.81,-64.86 300.52,-56.38"/>+<polygon fill="#5a6374" stroke="#5a6374" stroke-width="1.4" points="301.85,-53.7 292.85,-53.32 299.65,-59.23 301.85,-53.7"/>+</g>+<!-- status -->+<g id="node7" class="node">+<title>status</title>+<path fill="#0c1714" stroke="#22e0a8" stroke-width="1.3" d="M776.58,-51.92C776.58,-51.92 488.88,-51.92 488.88,-51.92 482.88,-51.92 476.88,-45.92 476.88,-39.92 476.88,-39.92 476.88,-12 476.88,-12 476.88,-6 482.88,0 488.88,0 488.88,0 776.58,0 776.58,0 782.58,0 788.58,-6 788.58,-12 788.58,-12 788.58,-39.92 788.58,-39.92 788.58,-45.92 782.58,-51.92 776.58,-51.92"/>+<text xml:space="preserve" text-anchor="start" x="591.48" y="-26.66" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="14.00" fill="#f4f6fb">status pages</text>+<text xml:space="preserve" text-anchor="start" x="498.48" y="-14.56" font-family="Helvetica,sans-Serif" font-size="12.00" fill="#7ff0c8">90 days of public per-day uptime, no login required</text>+</g>+<!-- result->status -->+<g id="edge6" class="edge">+<title>result->status</title>+<path fill="none" stroke="#5a6374" stroke-width="1.4" d="M493.96,-82.28C514.61,-74.04 537.64,-64.86 558.93,-56.38"/>+<polygon fill="#5a6374" stroke="#5a6374" stroke-width="1.4" points="559.8,-59.23 566.6,-53.32 557.6,-53.7 559.8,-59.23"/>+</g>+</g>+</svg>diff --git a/docs/public/monitors/runner-architecture.svg b/docs/public/monitors/runner-architecture.svgnew file mode 100644index 00000000..fbc6179a--- /dev/null+++ b/docs/public/monitors/runner-architecture.svg@@ -0,0 +1,94 @@+<?xml version="1.0" encoding="UTF-8" standalone="no"?>+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">+<!-- Generated by graphviz version 15.1.1 (20260805.0921)+ -->+<!-- Title: runner_architecture Pages: 1 -->+<svg width="775pt" height="564pt"+ viewBox="0.00 0.00 775.00 564.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">+<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(14.4 549.75)">+<title>runner_architecture</title>+<g id="clust1" class="cluster">+<title>cluster_instance</title>+<path fill="none" stroke="#283041" d="M20,-327.51C20,-327.51 508,-327.51 508,-327.51 514,-327.51 520,-333.51 520,-339.51 520,-339.51 520,-515.35 520,-515.35 520,-521.35 514,-527.35 508,-527.35 508,-527.35 20,-527.35 20,-527.35 14,-527.35 8,-521.35 8,-515.35 8,-515.35 8,-339.51 8,-339.51 8,-333.51 14,-327.51 20,-327.51"/>+<text xml:space="preserve" text-anchor="start" x="16" y="-513.6" font-family="Helvetica,sans-Serif" font-size="12.00" fill="#8a93a6">YOUR TRACEWAY INSTANCE</text>+</g>+<g id="clust2" class="cluster">+<title>cluster_runner</title>+<path fill="none" stroke="#283041" d="M65,-89.17C65,-89.17 463,-89.17 463,-89.17 469,-89.17 475,-95.17 475,-101.17 475,-101.17 475,-277.01 475,-277.01 475,-283.01 469,-289.01 463,-289.01 463,-289.01 65,-289.01 65,-289.01 59,-289.01 53,-283.01 53,-277.01 53,-277.01 53,-101.17 53,-101.17 53,-95.17 59,-89.17 65,-89.17"/>+<text xml:space="preserve" text-anchor="start" x="61" y="-275.26" font-family="Helvetica,sans-Serif" font-size="12.00" fill="#8a93a6">RUNNER HOST — NO INBOUND PORTS</text>+</g>+<!-- backend -->+<g id="node1" class="node">+<title>backend</title>+<path fill="#0f131c" stroke="#283041" stroke-width="1.3" d="M494.48,-492.6C494.48,-492.6 33.52,-492.6 33.52,-492.6 27.52,-492.6 21.52,-486.6 21.52,-480.6 21.52,-480.6 21.52,-452.68 21.52,-452.68 21.52,-446.68 27.52,-440.68 33.52,-440.68 33.52,-440.68 494.48,-440.68 494.48,-440.68 500.48,-440.68 506.48,-446.68 506.48,-452.68 506.48,-452.68 506.48,-480.6 506.48,-480.6 506.48,-486.6 500.48,-492.6 494.48,-492.6"/>+<text xml:space="preserve" text-anchor="start" x="203.62" y="-467.34" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="14.00" fill="#f4f6fb">Traceway backend</text>+<text xml:space="preserve" text-anchor="start" x="43.12" y="-455.24" font-family="Helvetica,sans-Serif" font-size="12.00" fill="#8a93a6">SYNTHETICS_BROWSER_MODE=remote + SYNTHETICS_RUNNER_SECRET</text>+</g>+<!-- bqueue -->+<g id="node2" class="node">+<title>bqueue</title>+<path fill="#151a24" stroke="#283041" stroke-width="1.3" d="M413.1,-393.43C413.1,-393.43 114.9,-393.43 114.9,-393.43 108.9,-393.43 102.9,-387.43 102.9,-381.43 102.9,-381.43 102.9,-353.51 102.9,-353.51 102.9,-347.51 108.9,-341.51 114.9,-341.51 114.9,-341.51 413.1,-341.51 413.1,-341.51 419.1,-341.51 425.1,-347.51 425.1,-353.51 425.1,-353.51 425.1,-381.43 425.1,-381.43 425.1,-387.43 419.1,-393.43 413.1,-393.43"/>+<text xml:space="preserve" text-anchor="start" x="202.88" y="-368.17" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="14.00" fill="#f4f6fb">browser run queue</text>+<text xml:space="preserve" text-anchor="start" x="124.5" y="-356.07" font-family="Helvetica,sans-Serif" font-size="12.00" fill="#8a93a6">queued runs wait here; nothing executes on this host</text>+</g>+<!-- backend->bqueue -->+<g id="edge1" class="edge">+<title>backend->bqueue</title>+<path fill="none" stroke="#5a6374" stroke-width="1.4" d="M264,-440.11C264,-429.17 264,-416.21 264,-404.34"/>+<polygon fill="#5a6374" stroke="#5a6374" stroke-width="1.4" points="266.98,-404.45 264,-395.95 261.03,-404.45 266.98,-404.45"/>+<text xml:space="preserve" text-anchor="middle" x="312.38" y="-413.18" font-family="Helvetica,sans-Serif" font-size="10.00" fill="#8a93a6">  queues browser runs</text>+</g>+<!-- runner -->+<g id="node3" class="node">+<title>runner</title>+<path fill="#1c1710" stroke="#f0a020" stroke-width="1.3" d="M448.73,-254.26C448.73,-254.26 79.27,-254.26 79.27,-254.26 73.27,-254.26 67.28,-248.26 67.28,-242.26 67.28,-242.26 67.28,-214.34 67.28,-214.34 67.28,-208.34 73.28,-202.34 79.28,-202.34 79.28,-202.34 448.73,-202.34 448.73,-202.34 454.73,-202.34 460.73,-208.34 460.73,-214.34 460.73,-214.34 460.73,-242.26 460.73,-242.26 460.73,-248.26 454.73,-254.26 448.73,-254.26"/>+<text xml:space="preserve" text-anchor="start" x="211.12" y="-229" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="14.00" fill="#f4f6fb">traceway-runner</text>+<text xml:space="preserve" text-anchor="start" x="88.88" y="-216.9" font-family="Helvetica,sans-Serif" font-size="12.00" fill="#ffc46b">Go binary under systemd · RUNNER_WORKERS concurrent runs</text>+</g>+<!-- bqueue->runner -->+<g id="edge3" class="edge">+<title>bqueue->runner</title>+<path fill="none" stroke="#f0a020" stroke-width="1.4" d="M263.2,-341.13C263.02,-334.12 262.84,-326.52 262.75,-319.51 262.51,-301.52 262.74,-281.52 263.06,-264.93"/>+<polygon fill="#f0a020" stroke="#f0a020" stroke-width="1.4" points="266.03,-265.26 263.24,-256.69 260.08,-265.13 266.03,-265.26"/>+<text xml:space="preserve" text-anchor="start" x="262.75" y="-310.01" font-family="Helvetica,sans-Serif" font-size="10.00" fill="#ffc46b">  claimed over the runner's long-poll</text>+<text xml:space="preserve" text-anchor="start" x="262.75" y="-298.76" font-family="Helvetica,sans-Serif" font-size="10.00" fill="#ffc46b">  Bearer SYNTHETICS_RUNNER_SECRET, outbound from the runner only</text>+</g>+<!-- runner->backend -->+<g id="edge5" class="edge">+<title>runner:e->backend:e</title>+<path fill="none" stroke="#f0a020" stroke-width="1.4" stroke-dasharray="5,2" d="M461.73,-228.3C529.16,-228.3 561.73,-239.54 597,-297.01 639.76,-366.69 596.57,-458.73 517.78,-466.16"/>+<polygon fill="#f0a020" stroke="#f0a020" stroke-width="1.4" points="517.94,-463.17 509.59,-466.54 518.22,-469.12 517.94,-463.17"/>+<text xml:space="preserve" text-anchor="start" x="613.83" y="-369.22" font-family="Helvetica,sans-Serif" font-size="10.00" fill="#ffc46b">  posts the result</text>+<text xml:space="preserve" text-anchor="start" x="613.83" y="-357.97" font-family="Helvetica,sans-Serif" font-size="10.00" fill="#ffc46b">  + failure screenshot and logs</text>+</g>+<!-- chromium -->+<g id="node4" class="node">+<title>chromium</title>+<path fill="#151a24" stroke="#283041" stroke-width="1.3" d="M425.48,-155.09C425.48,-155.09 102.52,-155.09 102.52,-155.09 96.52,-155.09 90.53,-149.09 90.53,-143.09 90.53,-143.09 90.53,-115.17 90.53,-115.17 90.53,-109.17 96.53,-103.17 102.53,-103.17 102.53,-103.17 425.48,-103.17 425.48,-103.17 431.48,-103.17 437.48,-109.17 437.48,-115.17 437.48,-115.17 437.48,-143.09 437.48,-143.09 437.48,-149.09 431.48,-155.09 425.48,-155.09"/>+<text xml:space="preserve" text-anchor="start" x="131.62" y="-129.83" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="14.00" fill="#f4f6fb">Node + Playwright + headless Chromium</text>+<text xml:space="preserve" text-anchor="start" x="112.12" y="-117.73" font-family="Helvetica,sans-Serif" font-size="12.00" fill="#8a93a6">allowlisted env: scripts never see server or runner secrets</text>+</g>+<!-- runner->chromium -->+<g id="edge2" class="edge">+<title>runner->chromium</title>+<path fill="none" stroke="#5a6374" stroke-width="1.4" d="M264,-201.77C264,-190.83 264,-177.87 264,-166"/>+<polygon fill="#5a6374" stroke="#5a6374" stroke-width="1.4" points="266.98,-166.11 264,-157.61 261.03,-166.11 266.98,-166.11"/>+<text xml:space="preserve" text-anchor="middle" x="318.75" y="-174.84" font-family="Helvetica,sans-Serif" font-size="10.00" fill="#8a93a6">  spawns per claimed run</text>+</g>+<!-- target -->+<g id="node5" class="node">+<title>target</title>+<path fill="#0c1714" stroke="#22e0a8" stroke-width="1.3" d="M395.1,-51.92C395.1,-51.92 132.9,-51.92 132.9,-51.92 126.9,-51.92 120.9,-45.92 120.9,-39.92 120.9,-39.92 120.9,-12 120.9,-12 120.9,-6 126.9,0 132.9,0 132.9,0 395.1,0 395.1,0 401.1,0 407.1,-6 407.1,-12 407.1,-12 407.1,-39.92 407.1,-39.92 407.1,-45.92 401.1,-51.92 395.1,-51.92"/>+<text xml:space="preserve" text-anchor="start" x="235.5" y="-26.66" font-family="Helvetica,sans-Serif" font-weight="bold" font-size="14.00" fill="#f4f6fb">your app</text>+<text xml:space="preserve" text-anchor="start" x="142.5" y="-14.56" font-family="Helvetica,sans-Serif" font-size="12.00" fill="#7ff0c8">the pages and flows the check spec exercises</text>+</g>+<!-- chromium->target -->+<g id="edge4" class="edge">+<title>chromium->target</title>+<path fill="none" stroke="#5a6374" stroke-width="1.4" d="M264,-102.6C264,-90.62 264,-76.13 264,-63.05"/>+<polygon fill="#5a6374" stroke="#5a6374" stroke-width="1.4" points="266.98,-63.1 264,-54.6 261.03,-63.1 266.98,-63.1"/>+<text xml:space="preserve" text-anchor="middle" x="311.25" y="-71.67" font-family="Helvetica,sans-Serif" font-size="10.00" fill="#8a93a6">  runs the check spec</text>+</g>+</g>+</svg>diff --git a/frontend/package-lock.json b/frontend/package-lock.jsonindex 049c97da..ef65196e 100644--- a/frontend/package-lock.json+++ b/frontend/package-lock.json@@ -8,11 +8,14 @@"name": "frontend","version": "1.9.12","dependencies": {+ "@codemirror/lang-javascript": "^6.2.5",+ "@codemirror/theme-one-dark": "^6.1.3","@fontsource-variable/inter": "^5.2.8","@fontsource/ibm-plex-mono": "^5.2.7","@fontsource/jetbrains-mono": "^5.2.8","@sveltejs/svelte-json-tree": "^2.2.1","@tracewayapp/svelte": "^1.0.2",+ "codemirror": "^6.0.2","d3-flame-graph": "^5.0.0","d3-selection": "^3.0.0","lucide-svelte": "^0.562.0",@@ -163,6 +166,114 @@"specificity": "bin/cli.js"}},+ "node_modules/@codemirror/autocomplete": {+ "version": "6.20.3",+ "resolved": "https://registry.npmjs.org/@codemirror/autocomplete/-/autocomplete-6.20.3.tgz",+ "integrity": "sha512-tlosUqb+3BbxCxZdu4tKeRghPFC+QM7q4X5YhKV2eCmPG+1r2F3f4AaSz5sCrFqUtX4Jh20VFTKecl16MgiV9g==",+ "license": "MIT",+ "dependencies": {+ "@codemirror/language": "^6.0.0",+ "@codemirror/state": "^6.0.0",+ "@codemirror/view": "^6.17.0",+ "@lezer/common": "^1.0.0"+ }+ },+ "node_modules/@codemirror/commands": {+ "version": "6.10.4",+ "resolved": "https://registry.npmjs.org/@codemirror/commands/-/commands-6.10.4.tgz",+ "integrity": "sha512-Ryk9y9T0FFVF0cUGhAknveAyUOl/A1qReTFi+qPKtOh2Z9F4AUBz3XOrYD4ZEgZirdugVzHvd/2/Wcwy5OliTg==",+ "license": "MIT",+ "dependencies": {+ "@codemirror/language": "^6.0.0",+ "@codemirror/state": "^6.7.0",+ "@codemirror/view": "^6.27.0",+ "@lezer/common": "^1.1.0"+ }+ },+ "node_modules/@codemirror/lang-javascript": {+ "version": "6.2.5",+ "resolved": "https://registry.npmjs.org/@codemirror/lang-javascript/-/lang-javascript-6.2.5.tgz",+ "integrity": "sha512-zD4e5mS+50htS7F+TYjBPsiIFGanfVqg4HyUz6WNFikgOPf2BgKlx+TQedI1w6n/IqRBVBbBWmGFdLB/7uxO4A==",+ "license": "MIT",+ "dependencies": {+ "@codemirror/autocomplete": "^6.0.0",+ "@codemirror/language": "^6.6.0",+ "@codemirror/lint": "^6.0.0",+ "@codemirror/state": "^6.0.0",+ "@codemirror/view": "^6.17.0",+ "@lezer/common": "^1.0.0",+ "@lezer/javascript": "^1.0.0"+ }+ },+ "node_modules/@codemirror/language": {+ "version": "6.12.4",+ "resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.12.4.tgz",+ "integrity": "sha512-1q4PaT+o6PbgpkJt4Q8Fv5XJxTy4FUZ4MWETtyiDw3J0Pyr9E2vqcKL+k9wcvjNTIsauxvE7OfmWj3FRPHQ76A==",+ "license": "MIT",+ "dependencies": {+ "@codemirror/state": "^6.0.0",+ "@codemirror/view": "^6.23.0",+ "@lezer/common": "^1.5.0",+ "@lezer/highlight": "^1.0.0",+ "@lezer/lr": "^1.0.0",+ "style-mod": "^4.0.0"+ }+ },+ "node_modules/@codemirror/lint": {+ "version": "6.9.7",+ "resolved": "https://registry.npmjs.org/@codemirror/lint/-/lint-6.9.7.tgz",+ "integrity": "sha512-28/+iWLYxKxsvGYhSYL7zaCZqLz5+FFFDq9tVsvGv9kv8RY4fFAchJ5WX9M3YrrRlTIsECjsXPqeNgnSmNP2dg==",+ "license": "MIT",+ "dependencies": {+ "@codemirror/state": "^6.0.0",+ "@codemirror/view": "^6.42.0",+ "crelt": "^1.0.5"+ }+ },+ "node_modules/@codemirror/search": {+ "version": "6.7.1",+ "resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.7.1.tgz",+ "integrity": "sha512-uMe5UO6PamJtSHrXhhHOzSX3ReWtiJrva6GnPMwSOrZtiExb5X5eExhr2OUZQVvdxPsKpY3Ro2mFbQadpPWmHA==",+ "license": "MIT",+ "dependencies": {+ "@codemirror/state": "^6.0.0",+ "@codemirror/view": "^6.37.0",+ "crelt": "^1.0.5"+ }+ },+ "node_modules/@codemirror/state": {+ "version": "6.7.1",+ "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.7.1.tgz",+ "integrity": "sha512-9QzNDgE4EYDnAHfrTlR2lwiPciiOymLtwKK+8yHQzCc7GXhAP9xdEbEJFy2IWB1j9UGUl9BsgMmTo/ImA02T7A==",+ "license": "MIT",+ "dependencies": {+ "@marijn/find-cluster-break": "^1.0.0"+ }+ },+ "node_modules/@codemirror/theme-one-dark": {+ "version": "6.1.3",+ "resolved": "https://registry.npmjs.org/@codemirror/theme-one-dark/-/theme-one-dark-6.1.3.tgz",+ "integrity": "sha512-NzBdIvEJmx6fjeremiGp3t/okrLPYT0d9orIc7AFun8oZcRk58aejkqhv6spnz4MLAevrKNPMQYXEWMg4s+sKA==",+ "license": "MIT",+ "dependencies": {+ "@codemirror/language": "^6.0.0",+ "@codemirror/state": "^6.0.0",+ "@codemirror/view": "^6.0.0",+ "@lezer/highlight": "^1.0.0"+ }+ },+ "node_modules/@codemirror/view": {+ "version": "6.43.8",+ "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.43.8.tgz",+ "integrity": "sha512-qtItTDssZ/5GFfi94hrILu9j/VUeFPDPkhovEfmWFj2ipTxnzPB8DdHgfbb8HYTzLTYhrndKmyQxXUz/PDLenw==",+ "license": "MIT",+ "dependencies": {+ "@codemirror/state": "^6.7.0",+ "crelt": "^1.0.6",+ "style-mod": "^4.1.0",+ "w3c-keyname": "^2.2.4"+ }+ },"node_modules/@csstools/color-helpers": {"version": "6.0.2","resolved": "https://registry.npmjs.org/@csstools/color-helpers/-/color-helpers-6.0.2.tgz",@@ -1103,6 +1214,41 @@"@jridgewell/sourcemap-codec": "^1.4.14"}},+ "node_modules/@lezer/common": {+ "version": "1.5.2",+ "resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.5.2.tgz",+ "integrity": "sha512-sxQE460fPZyU3sdc8lafxiPwJHBzZRy/udNFynGQky1SePYBdhkBl1kOagA9uT3pxR8K09bOrmTUqA9wb/PjSQ==",+ "license": "MIT"+ },+ "node_modules/@lezer/highlight": {+ "version": "1.2.3",+ "resolved": "https://registry.npmjs.org/@lezer/highlight/-/highlight-1.2.3.tgz",+ "integrity": "sha512-qXdH7UqTvGfdVBINrgKhDsVTJTxactNNxLk7+UMwZhU13lMHaOBlJe9Vqp907ya56Y3+ed2tlqzys7jDkTmW0g==",+ "license": "MIT",+ "dependencies": {+ "@lezer/common": "^1.3.0"+ }+ },+ "node_modules/@lezer/javascript": {+ "version": "1.5.4",+ "resolved": "https://registry.npmjs.org/@lezer/javascript/-/javascript-1.5.4.tgz",+ "integrity": "sha512-vvYx3MhWqeZtGPwDStM2dwgljd5smolYD2lR2UyFcHfxbBQebqx8yjmFmxtJ/E6nN6u1D9srOiVWm3Rb4tmcUA==",+ "license": "MIT",+ "dependencies": {+ "@lezer/common": "^1.2.0",+ "@lezer/highlight": "^1.1.3",+ "@lezer/lr": "^1.3.0"+ }+ },+ "node_modules/@lezer/lr": {+ "version": "1.4.10",+ "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.4.10.tgz",+ "integrity": "sha512-rnCpTIBafOx4mRp43xOxDJbFipJm/c0cia/V5TiGlhmMa+wsSdoGmUN3w5Bqrks/09Q/D4tNAmWaT8p6NRi77A==",+ "license": "MIT",+ "dependencies": {+ "@lezer/common": "^1.0.0"+ }+ },"node_modules/@lucide/svelte": {"version": "0.561.0","resolved": "https://registry.npmjs.org/@lucide/svelte/-/svelte-0.561.0.tgz",@@ -1113,6 +1259,12 @@"svelte": "^5"}},+ "node_modules/@marijn/find-cluster-break": {+ "version": "1.0.3",+ "resolved": "https://registry.npmjs.org/@marijn/find-cluster-break/-/find-cluster-break-1.0.3.tgz",+ "integrity": "sha512-FY+MKLBoTsLNJF/eLWaOsXGdz6uh3Iu1axjPf6TUq92IYumcTcXWHoS747JARLkcdlJ/Waiaxc5wQfFO8jC6NA==",+ "license": "MIT"+ },"node_modules/@polka/url": {"version": "1.0.0-next.29","resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.29.tgz",@@ -2774,6 +2926,21 @@"url": "https://github.com/sponsors/dcastil"}},+ "node_modules/codemirror": {+ "version": "6.0.2",+ "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-6.0.2.tgz",+ "integrity": "sha512-VhydHotNW5w1UGK0Qj96BwSk/Zqbp9WbnyK2W/eVMv4QyF41INRGpjUhFJY7/uDNuudSc33a/PKr4iDqRduvHw==",+ "license": "MIT",+ "dependencies": {+ "@codemirror/autocomplete": "^6.0.0",+ "@codemirror/commands": "^6.0.0",+ "@codemirror/language": "^6.0.0",+ "@codemirror/lint": "^6.0.0",+ "@codemirror/search": "^6.0.0",+ "@codemirror/state": "^6.0.0",+ "@codemirror/view": "^6.0.0"+ }+ },"node_modules/color-convert": {"version": "2.0.1","resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",@@ -2818,6 +2985,12 @@"node": ">= 0.6"}},+ "node_modules/crelt": {+ "version": "1.0.7",+ "resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.7.tgz",+ "integrity": "sha512-aK6BbWfhf4U/wCcLHKPJl/xa6VkVstRaPywWtMKGwuOLc/wZTyQYuoxgvZnNsBvv7Kg3YTBQYYBCggcviQczuA==",+ "license": "MIT"+ },"node_modules/cross-spawn": {"version": "7.0.6","resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",@@ -4994,6 +5167,12 @@"url": "https://github.com/sponsors/sindresorhus"}},+ "node_modules/style-mod": {+ "version": "4.1.3",+ "resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.1.3.tgz",+ "integrity": "sha512-i/n8VsZydrugj3Iuzll8+x/00GH2vnYsk1eomD8QiRrSAeW6ItbCQDtfXCeJHd0iwiNagqjQkvpvREEPtW3IoQ==",+ "license": "MIT"+ },"node_modules/style-to-object": {"version": "1.0.14","resolved": "https://registry.npmjs.org/style-to-object/-/style-to-object-1.0.14.tgz",@@ -5621,6 +5800,12 @@}}},+ "node_modules/w3c-keyname": {+ "version": "2.2.8",+ "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz",+ "integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==",+ "license": "MIT"+ },"node_modules/w3c-xmlserializer": {"version": "5.0.0","resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz",diff --git a/frontend/package.json b/frontend/package.jsonindex 4836438c..689b3d14 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -58,11 +58,14 @@"vitest": "^4.1.9"},"dependencies": {+ "@codemirror/lang-javascript": "^6.2.5",+ "@codemirror/theme-one-dark": "^6.1.3","@fontsource-variable/inter": "^5.2.8","@fontsource/ibm-plex-mono": "^5.2.7","@fontsource/jetbrains-mono": "^5.2.8","@sveltejs/svelte-json-tree": "^2.2.1","@tracewayapp/svelte": "^1.0.2",+ "codemirror": "^6.0.2","d3-flame-graph": "^5.0.0","d3-selection": "^3.0.0","lucide-svelte": "^0.562.0",diff --git a/frontend/src/lib/components/app-sidebar.svelte b/frontend/src/lib/components/app-sidebar.svelteindex 77a1436d..1a17cf6a 100644--- a/frontend/src/lib/components/app-sidebar.svelte+++ b/frontend/src/lib/components/app-sidebar.svelte@@ -2,7 +2,9 @@import * as Sidebar from '$lib/components/ui/sidebar';import { useSidebar } from '$lib/components/ui/sidebar';import { oncallState } from '$lib/state/oncall.svelte';+ import { monitorsState } from '$lib/state/monitors.svelte';import {+ Activity,Bell,Workflow,Bug,@@ -74,6 +76,12 @@title: 'Dashboards',stickyParams: ['preset', 'from', 'to']},+ {+ Icon: Activity,+ href: '/monitors',+ title: 'Monitors',+ stickyParams: ['preset', 'from', 'to']+ },{ Icon: Bell, href: '/notifications', title: 'Alerts', stickyParams: ['preset', 'from', 'to'] },{ Icon: PhoneCall, href: '/on-call', title: 'On-Call', stickyParams: [] },{ Icon: Link2, href: '/connection', title: 'Connection', stickyParams: [] }@@ -113,7 +121,11 @@const projectId = projectsState.currentProjectId;if (!projectId) return;oncallState.refreshOpenCount();- const interval = setInterval(() => oncallState.refreshOpenCount(), 60000);+ monitorsState.refreshDownCount();+ const interval = setInterval(() => {+ oncallState.refreshOpenCount();+ monitorsState.refreshDownCount();+ }, 60000);return () => clearInterval(interval);});@@ -175,6 +187,13 @@<sidebarItem.Icon /><span>{sidebarItem.title}</span></Sidebar.SidebarMenuButton>+ {#if sidebarItem.title === 'Monitors' && monitorsState.downChecksCount > 0}+ <Sidebar.MenuBadge+ class="rounded-full bg-destructive text-[10px] text-white peer-hover/menu-button:text-white peer-data-[active=true]/menu-button:text-white"+ >+ {monitorsState.downChecksCount}+ </Sidebar.MenuBadge>+ {/if}{#if sidebarItem.title === 'On-Call' && oncallState.openPagesCount > 0}<Sidebar.MenuBadgeclass="rounded-full bg-destructive text-[10px] text-white peer-hover/menu-button:text-white peer-data-[active=true]/menu-button:text-white"diff --git a/frontend/src/lib/components/synthetics/check-status-badge.svelte b/frontend/src/lib/components/synthetics/check-status-badge.sveltenew file mode 100644index 00000000..22cb832b--- /dev/null+++ b/frontend/src/lib/components/synthetics/check-status-badge.svelte@@ -0,0 +1,34 @@+<script lang="ts">+ import type { CheckStatus } from '$lib/state/monitors.svelte';++ interface Props {+ status: CheckStatus;+ enabled?: boolean;+ }++ let { status, enabled = true }: Props = $props();++ const pillBase = 'inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-xs font-medium';+</script>++{#if !enabled}+ <span class="{pillBase} bg-muted text-muted-foreground">+ <span class="h-1.5 w-1.5 rounded-full bg-muted-foreground/60"></span>+ Paused+ </span>+{:else if status === 'up'}+ <span class="{pillBase} bg-green-500/15 text-green-600 dark:text-green-400">+ <span class="h-1.5 w-1.5 rounded-full bg-green-500"></span>+ Up+ </span>+{:else if status === 'down'}+ <span class="{pillBase} bg-red-500/15 text-red-600 dark:text-red-400">+ <span class="h-1.5 w-1.5 rounded-full bg-red-500"></span>+ Down+ </span>+{:else}+ <span class="{pillBase} bg-muted text-muted-foreground">+ <span class="h-1.5 w-1.5 rounded-full bg-muted-foreground/60"></span>+ Pending+ </span>+{/if}diff --git a/frontend/src/lib/components/synthetics/key-value-rows.svelte b/frontend/src/lib/components/synthetics/key-value-rows.sveltenew file mode 100644index 00000000..a3741e91--- /dev/null+++ b/frontend/src/lib/components/synthetics/key-value-rows.svelte@@ -0,0 +1,50 @@+<script lang="ts">+ import { Button } from '$lib/components/ui/button';+ import { Input } from '$lib/components/ui/input';+ import { Plus, Trash2 } from '@lucide/svelte';++ interface Props {+ rows: { key: string; value: string }[];+ keyPlaceholder?: string;+ valuePlaceholder?: string;+ addLabel?: string;+ disabled?: boolean;+ }++ let {+ rows = $bindable(),+ keyPlaceholder = 'Name',+ valuePlaceholder = 'Value',+ addLabel = 'Add',+ disabled = false+ }: Props = $props();++ function addRow() {+ rows = [...rows, { key: '', value: '' }];+ }++ function removeRow(index: number) {+ rows = rows.filter((_, i) => i !== index);+ }+</script>++<div class="space-y-2">+ {#each rows as _, index}+ <div class="flex gap-2">+ <Input bind:value={rows[index].key} placeholder={keyPlaceholder} class="flex-1" {disabled} />+ <Input+ bind:value={rows[index].value}+ placeholder={valuePlaceholder}+ class="flex-1"+ {disabled}+ />+ <Button variant="ghost" size="icon" type="button" onclick={() => removeRow(index)} {disabled}>+ <Trash2 class="h-4 w-4" />+ </Button>+ </div>+ {/each}+ <Button variant="outline" size="sm" type="button" onclick={addRow} {disabled}>+ <Plus class="mr-1 h-3 w-3" />+ {addLabel}+ </Button>+</div>diff --git a/frontend/src/lib/components/synthetics/monitor-type-badge.svelte b/frontend/src/lib/components/synthetics/monitor-type-badge.sveltenew file mode 100644index 00000000..cb9781cf--- /dev/null+++ b/frontend/src/lib/components/synthetics/monitor-type-badge.svelte@@ -0,0 +1,23 @@+<script lang="ts">+ import type { CheckType } from '$lib/state/monitors.svelte';++ interface Props {+ type: CheckType;+ }++ let { type }: Props = $props();++ const typeClasses: Record<CheckType, string> = {+ http: 'bg-blue-500/15 text-blue-600 dark:text-blue-400',+ tcp: 'bg-violet-500/15 text-violet-600 dark:text-violet-400',+ browser: 'bg-amber-500/15 text-amber-700 dark:text-amber-400'+ };+</script>++<span+ class="inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium tracking-wide uppercase {typeClasses[+ type+ ] ?? 'bg-muted text-muted-foreground'}"+>+ {type}+</span>diff --git a/frontend/src/lib/components/ui/button/button.svelte b/frontend/src/lib/components/ui/button/button.svelteindex 609abfa9..44683aa2 100644--- a/frontend/src/lib/components/ui/button/button.svelte+++ b/frontend/src/lib/components/ui/button/button.svelte@@ -13,7 +13,7 @@destructiveOutline:'border border-destructive text-destructive hover:bg-destructive/10 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:border-destructive/60 dark:text-destructive/90 dark:hover:bg-destructive/20 shadow-xs',success:- 'bg-emerald-600 hover:bg-emerald-600/90 focus-visible:ring-emerald-600/20 dark:focus-visible:ring-emerald-600/40 dark:bg-emerald-600/60 text-white shadow-xs',+ 'bg-green-600 hover:bg-green-600/90 focus-visible:ring-green-600/20 dark:focus-visible:ring-green-600/40 dark:bg-green-600/60 text-white shadow-xs',outline:'bg-background hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50 border shadow-xs',secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80 shadow-xs',diff --git a/frontend/src/lib/components/ui/code-editor/code-editor.svelte b/frontend/src/lib/components/ui/code-editor/code-editor.sveltenew file mode 100644index 00000000..cb63397d--- /dev/null+++ b/frontend/src/lib/components/ui/code-editor/code-editor.svelte@@ -0,0 +1,90 @@+<script lang="ts">+ import { onMount } from 'svelte';+ import { EditorView, basicSetup } from 'codemirror';+ import { EditorState, Compartment } from '@codemirror/state';+ import { javascript } from '@codemirror/lang-javascript';+ import { oneDark } from '@codemirror/theme-one-dark';+ import { themeState } from '$lib/state/theme.svelte';+ import { cn } from '$lib/utils';++ interface Props {+ value: string;+ readOnly?: boolean;+ minHeight?: string;+ class?: string;+ }++ let {+ value = $bindable(),+ readOnly = false,+ minHeight = '280px',+ class: className = ''+ }: Props = $props();++ let container: HTMLDivElement;+ let view: EditorView | null = null;++ const themeCompartment = new Compartment();+ const readOnlyCompartment = new Compartment();++ const baseTheme = EditorView.theme({+ '&': { fontSize: '12px' },+ // minHeight lives on the scroller: it is the flex row holding gutters ++ // content, so both stretch to fill the box instead of stopping at the+ // last line.+ '.cm-scroller': { minHeight },+ '.cm-content': { fontFamily: 'var(--font-mono, monospace)' },+ '.cm-gutters': { fontFamily: 'var(--font-mono, monospace)' },+ '&.cm-focused': { outline: 'none' }+ });++ const lightTheme = EditorView.theme({}, { dark: false });++ onMount(() => {+ view = new EditorView({+ parent: container,+ state: EditorState.create({+ doc: value,+ extensions: [+ basicSetup,+ javascript({ typescript: true }),+ baseTheme,+ themeCompartment.of(themeState.isDark ? oneDark : lightTheme),+ readOnlyCompartment.of(EditorState.readOnly.of(readOnly)),+ EditorView.updateListener.of((update) => {+ if (update.docChanged) {+ value = update.state.doc.toString();+ }+ })+ ]+ })+ });+ return () => {+ view?.destroy();+ view = null;+ };+ });++ // External value changes (populating the form for editing).+ $effect(() => {+ const next = value;+ if (view && next !== view.state.doc.toString()) {+ view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: next } });+ }+ });++ $effect(() => {+ const dark = themeState.isDark;+ view?.dispatch({ effects: themeCompartment.reconfigure(dark ? oneDark : lightTheme) });+ });++ $effect(() => {+ const ro = readOnly;+ view?.dispatch({ effects: readOnlyCompartment.reconfigure(EditorState.readOnly.of(ro)) });+ });+</script>++<div+ bind:this={container}+ class={cn('overflow-hidden rounded-md border border-input text-left shadow-xs', className)}+></div>diff --git a/frontend/src/lib/components/ui/code-editor/index.ts b/frontend/src/lib/components/ui/code-editor/index.tsnew file mode 100644index 00000000..675d1ad1--- /dev/null+++ b/frontend/src/lib/components/ui/code-editor/index.ts@@ -0,0 +1,3 @@+import CodeEditor from './code-editor.svelte';++export { CodeEditor };diff --git a/frontend/src/lib/state/monitors.svelte.ts b/frontend/src/lib/state/monitors.svelte.tsnew file mode 100644index 00000000..27357e9d--- /dev/null+++ b/frontend/src/lib/state/monitors.svelte.ts@@ -0,0 +1,122 @@+import { api } from '$lib/api';+import { projectsState } from '$lib/state/projects.svelte';++export type CheckType = 'http' | 'tcp' | 'browser';+export type CheckStatus = 'up' | 'down' | 'unknown';++export interface SyntheticCheck {+ id: number;+ projectId: string;+ name: string;+ checkType: CheckType;+ enabled: boolean;+ intervalSeconds: number;+ timeoutSeconds: number;+ config: CheckConfig;+ failureThreshold: number;+ currentStatus: CheckStatus;+ consecutiveFailures: number;+ lastRunAt: string | null;+ lastStateChangeAt: string | null;+ nextRunAt: string;+ createdAt: string;+ updatedAt: string;+}++export interface CheckConfig {+ // http+ url?: string;+ method?: string;+ headers?: Record<string, string>;+ auth?: {+ type?: 'none' | 'basic' | 'bearer' | 'header';+ username?: string;+ password?: string;+ token?: string;+ headerName?: string;+ headerValue?: string;+ };+ body?: string;+ bodyContentType?: string;+ followRedirects?: boolean;+ skipTlsVerify?: boolean;+ assertions?: {+ statusCodes?: number[];+ bodyContains?: string;+ bodyRegex?: string;+ maxResponseTimeMs?: number;+ tlsMinDaysRemaining?: number;+ };+ // tcp+ host?: string;+ port?: number;+ useTls?: boolean;+ sendPayload?: string;+ expectContains?: string;+ tlsMinDaysRemaining?: number;+ // browser+ script?: string;+ env?: Record<string, string>;+}++export interface CheckAggregates {+ total: number;+ up: number;+ down: number;+ missed: number;+ avgLatencyMs: number;+}++export interface CheckOverview extends SyntheticCheck {+ aggregates: CheckAggregates | null;+}++export interface CheckIncident {+ id: number;+ checkId: number;+ projectId: string;+ startedAt: string;+ resolvedAt: string | null;+ errorMessage: string;+}++export interface CheckResultEntry {+ runId: number;+ checkType: CheckType;+ recordedAt: string;+ executedAt: string;+ status: 'up' | 'down' | 'missed';+ latencyMs: number;+ statusCode: number;+ errorMessage: string;+ executedBy: string;+ screenshotKey: string;+ outputKey: string;+ tlsDaysRemaining: number;+}++export interface CheckSeriesPoint {+ bucket: string;+ total: number;+ up: number;+ missed: number;+ avgLatencyMs: number;+ maxLatencyMs: number;+}++class MonitorsState {+ downChecksCount = $state(0);++ async refreshDownCount() {+ try {+ const res = await api.get('/synthetics/open-count', {+ projectId: projectsState.currentProjectId ?? undefined+ });+ this.downChecksCount = res.count ?? 0;+ } catch {+ // badge stays at its last value+ }+ }+}++export const monitorsState = new MonitorsState();diff --git a/frontend/src/routes/+layout.svelte b/frontend/src/routes/+layout.svelteindex c3084b65..e6068d98 100644--- a/frontend/src/routes/+layout.svelte+++ b/frontend/src/routes/+layout.svelte@@ -90,7 +90,8 @@return (PUBLIC_PATHS.has(pathname) ||pathname.startsWith('/accept-invitation') ||- pathname.startsWith('/ack/')+ pathname.startsWith('/ack/') ||+ pathname.startsWith('/status/'));}@@ -100,6 +101,27 @@$effect(() => {if (!authState.isAuthenticated && !isPublicPath(page.url.pathname)) {const returnTo = page.url.pathname + page.url.search;+ if (page.url.pathname === '/') {+ // A CNAMEd status-page vanity domain lands here anonymously; ask+ // the backend whether this Host maps to a status page before+ // falling back to the login redirect.+ fetch('/api/status-domains/resolve')+ .then((response) => (response.ok ? response.json() : null))+ .then((resolved) => {+ if (resolved?.slug) {+ // eslint-disable-next-line svelte/no-navigation-without-resolve+ goto(`/status/${resolved.slug}`, { replaceState: true });+ } else {+ // eslint-disable-next-line svelte/no-navigation-without-resolve+ goto(`/login?returnTo=${encodeURIComponent(returnTo)}`, { replaceState: true });+ }+ })+ .catch(() => {+ // eslint-disable-next-line svelte/no-navigation-without-resolve+ goto(`/login?returnTo=${encodeURIComponent(returnTo)}`, { replaceState: true });+ });+ return;+ }// eslint-disable-next-line svelte/no-navigation-without-resolvegoto(`/login?returnTo=${encodeURIComponent(returnTo)}`, { replaceState: true });}diff --git a/frontend/src/routes/layout.css b/frontend/src/routes/layout.cssindex 0c0508ba..0764c286 100644--- a/frontend/src/routes/layout.css+++ b/frontend/src/routes/layout.css@@ -291,9 +291,9 @@blue info, red error, amber warning. Same in both modes. */[data-sonner-toaster] [data-sonner-toast][data-type='success'],.dark [data-sonner-toaster] [data-sonner-toast][data-type='success'] {- background: #00a73d;+ background: #16a34a;color: white;- border-color: #008f34;+ border-color: #15803d;}[data-sonner-toaster] [data-sonner-toast][data-type='info'],diff --git a/frontend/src/routes/monitors/+page.svelte b/frontend/src/routes/monitors/+page.sveltenew file mode 100644index 00000000..2239b437--- /dev/null+++ b/frontend/src/routes/monitors/+page.svelte@@ -0,0 +1,502 @@+<script lang="ts">+ import { onMount, onDestroy } from 'svelte';+ import { api } from '$lib/api';+ import { toUTCISO, calendarDateTimeToLuxon, formatDurationMs } from '$lib/utils/formatters';+ import { getTimezone } from '$lib/state/timezone.svelte';+ import * as Table from '$lib/components/ui/table';+ import { LoadingCircle } from '$lib/components/ui/loading-circle';+ import { TracewayTableHeader } from '$lib/components/ui/traceway-table-header';+ import { TableEmptyState } from '$lib/components/ui/table-empty-state';+ import { TimeRangePicker } from '$lib/components/ui/time-range-picker';+ import { SearchBar } from '$lib/components/ui/search-bar';+ import InfoCallout from '$lib/components/traceway/info-callout.svelte';+ import TabsRow from '$lib/components/traceway/tabs-row.svelte';+ import EmptyState from '$lib/components/traceway/empty-state.svelte';+ import CheckStatusBadge from '$lib/components/synthetics/check-status-badge.svelte';+ import MonitorTypeBadge from '$lib/components/synthetics/monitor-type-badge.svelte';+ import MonitorSheet from './monitor-sheet.svelte';+ import StatusPagesTab from './status-pages-tab.svelte';+ import { browser } from '$app/environment';+ import { page } from '$app/state';+ import { goto } from '$app/navigation';+ import { CalendarDate } from '@internationalized/date';+ import { projectsState } from '$lib/state/projects.svelte';+ import { monitorsState, type CheckOverview } from '$lib/state/monitors.svelte';+ import { createRowClickHandler } from '$lib/utils/navigation';+ import { resolve } from '$app/paths';+ import PageHeader from '$lib/components/issues/page-header.svelte';+ import {+ getTimeRangeFromPreset,+ dateToCalendarDate,+ dateToTimeString,+ parseTimeRangeFromUrl,+ getResolvedTimeRange,+ updateUrl+ } from '$lib/utils/url-params';+ import {+ getSortState,+ setSortState,+ handleSortClick,+ type SortDirection+ } from '$lib/utils/sort-storage';++ const timezone = $derived(getTimezone());+ const initialTimezone = getTimezone();++ type SortField = 'name' | 'check_type' | 'status' | 'uptime' | 'latency' | 'last_run';++ let checks = $state<CheckOverview[]>([]);+ let loading = $state(true);+ let error = $state('');++ let dialogOpen = $state(false);++ let statusPagesTab = $state<{ openCreate: () => void } | null>(null);++ const TABS = $derived([+ { value: 'monitors', label: 'Monitors' },+ ...(projectsState.canManageCurrentProject+ ? [{ value: 'status-pages', label: 'Status Pages' }]+ : [])+ ]);++ const tabDescriptions: Record<string, string> = {+ monitors:+ 'Monitors probe your services from the outside on a schedule: an HTTP request, a TCP connect, or a full browser flow. A monitor goes down only after the configured number of consecutive failures.',+ 'status-pages':+ 'A status page publishes the uptime of selected monitors at /status/<slug> with no login required. Brand it with your title and logo, and optionally serve it from your own domain via a CNAME.'+ };++ const activeTab = $derived.by(() => {+ const tab = page.url.searchParams.get('tab') || 'monitors';+ return TABS.some((t) => t.value === tab) ? tab : 'monitors';+ });++ function setTab(tab: string) {+ const url = new URL(window.location.href);+ if (tab === 'monitors') {+ url.searchParams.delete('tab');+ } else {+ url.searchParams.set('tab', tab);+ url.searchParams.delete('preset');+ url.searchParams.delete('from');+ url.searchParams.delete('to');+ url.searchParams.delete('search');+ }+ goto(url.toString(), { replaceState: true, noScroll: true });+ if (tab === 'monitors') {+ loadData(false);+ }+ }++ const newAction = $derived.by(() => {+ if (activeTab === 'monitors') {+ return projectsState.canWriteCurrentProject+ ? { label: 'New Monitor', onclick: () => (dialogOpen = true) }+ : null;+ }+ if (activeTab === 'status-pages') {+ return { label: 'New Status Page', onclick: () => statusPagesTab?.openCreate() };+ }+ return null;+ });++ const typeOptions = [+ { value: '', label: 'All types' },+ { value: 'http', label: 'HTTP' },+ { value: 'tcp', label: 'TCP' },+ { value: 'browser', label: 'Browser' }+ ];+ let typeFilter = $state('');++ function parseMonitorsUrlParams() {+ if (!browser) return { preset: '24h', from: null, to: null, search: '' };+ const params = new URLSearchParams(window.location.search);+ const timeParams = parseTimeRangeFromUrl(timezone, '24h');+ return { ...timeParams, search: params.get('search') || '' };+ }++ const initialUrlParams = parseMonitorsUrlParams();+ const initialRange = getResolvedTimeRange(initialUrlParams, initialTimezone);++ let searchQuery = $state(initialUrlParams.search);++ let selectedPreset = $state<string | null>(initialUrlParams.preset);+ let fromDate = $state<CalendarDate>(dateToCalendarDate(initialRange.from, initialTimezone));+ let toDate = $state<CalendarDate>(dateToCalendarDate(initialRange.to, initialTimezone));+ let fromTime = $state(dateToTimeString(initialRange.from, initialTimezone));+ let toTime = $state(dateToTimeString(initialRange.to, initialTimezone));++ function updateTimeRangeUrl(pushToHistory = true) {+ const params: Record<string, string | null | undefined> = {};+ if (selectedPreset) {+ params.preset = selectedPreset;+ } else {+ params.from = getFromDateTimeUTC();+ params.to = getToDateTimeUTC();+ }+ if (searchQuery.trim()) {+ params.search = searchQuery.trim();+ }+ updateUrl(params, { pushToHistory });+ }++ function handlePopState() {+ const tab = new URLSearchParams(window.location.search).get('tab') || 'monitors';+ if (tab !== 'monitors') return;+ const urlParams = parseMonitorsUrlParams();+ const range = getResolvedTimeRange(urlParams, timezone);++ selectedPreset = urlParams.preset;+ fromDate = dateToCalendarDate(range.from, timezone);+ fromTime = dateToTimeString(range.from, timezone);+ toDate = dateToCalendarDate(range.to, timezone);+ toTime = dateToTimeString(range.to, timezone);+ searchQuery = urlParams.search;++ loadData(false);+ }++ const SORT_STORAGE_KEY = 'monitors';+ const initialSort = getSortState(SORT_STORAGE_KEY, { field: 'name', direction: 'asc' });+ let orderBy = $state<SortField>(initialSort.field as SortField);+ let sortDirection = $state<SortDirection>(initialSort.direction);++ function getFromDateTimeUTC(): string {+ const [hour, minute] = (fromTime || '00:00').split(':').map(Number);+ const dt = calendarDateTimeToLuxon(+ { year: fromDate.year, month: fromDate.month, day: fromDate.day, hour, minute },+ timezone+ );+ return toUTCISO(dt);+ }++ function getToDateTimeUTC(): string {+ const [hour, minute] = (toTime || '23:59').split(':').map(Number);+ const dt = calendarDateTimeToLuxon(+ { year: toDate.year, month: toDate.month, day: toDate.day, hour, minute },+ timezone+ ).endOf('minute');+ return toUTCISO(dt);+ }++ function handleTimeRangeChange(+ from: { date: CalendarDate; time: string },+ to: { date: CalendarDate; time: string },+ preset: string | null+ ) {+ fromDate = from.date;+ fromTime = from.time;+ toDate = to.date;+ toTime = to.time;+ selectedPreset = preset;+ loadData(false);+ }++ async function loadData(pushToHistory = true) {+ loading = true;+ error = '';++ if (selectedPreset) {+ const range = getTimeRangeFromPreset(selectedPreset, timezone);+ fromDate = dateToCalendarDate(range.from, timezone);+ toDate = dateToCalendarDate(range.to, timezone);+ fromTime = dateToTimeString(range.from, timezone);+ toTime = dateToTimeString(range.to, timezone);+ }++ updateTimeRangeUrl(pushToHistory);++ try {+ const response = await api.post(+ '/synthetics/overview',+ { fromDate: getFromDateTimeUTC(), toDate: getToDateTimeUTC() },+ { projectId: projectsState.currentProjectId ?? undefined }+ );+ checks = response.checks || [];+ monitorsState.refreshDownCount();+ } catch (e: any) {+ console.error(e);+ error = e.message || 'Failed to load data';+ } finally {+ loading = false;+ }+ }++ function handleSort(field: SortField) {+ const newSort = handleSortClick(field, orderBy, sortDirection);+ orderBy = newSort.field as SortField;+ sortDirection = newSort.direction;+ setSortState(SORT_STORAGE_KEY, newSort);+ }++ function handleSearch() {+ updateTimeRangeUrl(true);+ }++ function uptimePct(check: CheckOverview): number | null {+ const agg = check.aggregates;+ if (!agg || agg.total === 0) return null;+ const measured = agg.total - agg.missed;+ if (measured === 0) return null;+ return (agg.up / measured) * 100;+ }++ const statusRank: Record<string, number> = { down: 0, unknown: 1, up: 2 };++ const visibleChecks = $derived.by(() => {+ const query = searchQuery.trim().toLowerCase();+ let filtered = typeFilter ? checks.filter((c) => c.checkType === typeFilter) : checks;+ if (query) {+ filtered = filtered.filter(+ (c) => c.name.toLowerCase().includes(query) || c.checkType.includes(query)+ );+ }+ const direction = sortDirection === 'asc' ? 1 : -1;+ return [...filtered].sort((a, b) => {+ switch (orderBy) {+ case 'check_type':+ return direction * a.checkType.localeCompare(b.checkType);+ case 'status': {+ const rankA = a.enabled ? statusRank[a.currentStatus] : 3;+ const rankB = b.enabled ? statusRank[b.currentStatus] : 3;+ return direction * (rankA - rankB);+ }+ case 'uptime':+ return direction * ((uptimePct(a) ?? -1) - (uptimePct(b) ?? -1));+ case 'latency':+ return (+ direction * ((a.aggregates?.avgLatencyMs ?? -1) - (b.aggregates?.avgLatencyMs ?? -1))+ );+ case 'last_run': {+ const timeA = a.lastRunAt ? new Date(a.lastRunAt).getTime() : 0;+ const timeB = b.lastRunAt ? new Date(b.lastRunAt).getTime() : 0;+ return direction * (timeA - timeB);+ }+ default:+ return direction * a.name.localeCompare(b.name);+ }+ });+ });++ function formatRelative(iso: string | null): string {+ if (!iso) return 'never';+ const diffMs = Date.now() - new Date(iso).getTime();+ const diffSec = Math.floor(diffMs / 1000);+ if (diffSec < 60) return `${diffSec}s ago`;+ const diffMin = Math.floor(diffSec / 60);+ if (diffMin < 60) return `${diffMin}m ago`;+ const diffHours = Math.floor(diffMin / 60);+ if (diffHours < 24) return `${diffHours}h ago`;+ return `${Math.floor(diffHours / 24)}d ago`;+ }++ function uptimeClass(uptime: number): string {+ if (uptime >= 99.9) return 'text-green-600 dark:text-green-400';+ if (uptime >= 99) return '';+ return 'text-red-600 dark:text-red-400';+ }++ onMount(() => {+ window.addEventListener('popstate', handlePopState);+ if (activeTab === 'monitors') {+ loadData(false);+ }+ });++ onDestroy(() => {+ if (typeof window !== 'undefined') {+ window.removeEventListener('popstate', handlePopState);+ }+ });+</script>++<div class="space-y-4">+ <PageHeader title="Monitors" />++ <TabsRow+ tabs={TABS}+ {activeTab}+ onTabChange={setTab}+ actionLabel={newAction?.label}+ onAction={newAction?.onclick}+ />++ <InfoCallout>{tabDescriptions[activeTab]}</InfoCallout>++ {#if activeTab === 'monitors'}+ <div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">+ <SearchBar+ placeholder="Search monitors..."+ bind:value={searchQuery}+ bind:typeValue={typeFilter}+ {typeOptions}+ onSearch={handleSearch}+ disabled={loading}+ />+ <div class="w-full sm:w-auto">+ <TimeRangePicker+ bind:fromDate+ bind:toDate+ bind:fromTime+ bind:toTime+ bind:preset={selectedPreset}+ onApply={handleTimeRangeChange}+ />+ </div>+ </div>++ {#if loading}+ <div class="flex h-48 items-center justify-center">+ <LoadingCircle size="xlg" />+ </div>+ {:else if error}+ <div class="rounded-md border py-16 text-center text-red-500">{error}</div>+ {:else if checks.length === 0}+ {#if projectsState.canWriteCurrentProject}+ <EmptyState+ message="No monitors yet. Create your first Monitor to start tracking uptime."+ actionLabel="Create your first Monitor"+ onAction={() => (dialogOpen = true)}+ />+ {:else}+ <EmptyState message="No monitors yet." />+ {/if}+ {:else}+ <div class="overflow-hidden rounded-md border">+ <Table.Root>+ {#if visibleChecks.length === 0}+ <Table.Body>+ <TableEmptyState colspan={6} message="No monitors match your search." />+ </Table.Body>+ {:else}+ <Table.Header>+ <Table.Row>+ <TracewayTableHeader+ label="Name"+ sortField="name"+ currentSortField={orderBy}+ {sortDirection}+ onSort={(field) => handleSort(field as SortField)}+ />+ <TracewayTableHeader+ label="Type"+ sortField="check_type"+ currentSortField={orderBy}+ {sortDirection}+ onSort={(field) => handleSort(field as SortField)}+ class="w-[100px]"+ />+ <TracewayTableHeader+ label="Status"+ tooltip="Current state from the most recent probes"+ sortField="status"+ currentSortField={orderBy}+ {sortDirection}+ onSort={(field) => handleSort(field as SortField)}+ class="w-[110px]"+ />+ <TracewayTableHeader+ label="Uptime"+ tooltip="Share of successful probes in the selected time range (missed probes excluded)"+ sortField="uptime"+ currentSortField={orderBy}+ {sortDirection}+ onSort={(field) => handleSort(field as SortField)}+ class="w-[160px]"+ />+ <TracewayTableHeader+ label="Avg latency"+ tooltip="Average probe latency in the selected time range"+ sortField="latency"+ currentSortField={orderBy}+ {sortDirection}+ onSort={(field) => handleSort(field as SortField)}+ class="w-[120px]"+ />+ <TracewayTableHeader+ label="Last run"+ sortField="last_run"+ currentSortField={orderBy}+ {sortDirection}+ onSort={(field) => handleSort(field as SortField)}+ align="right"+ class="w-[110px]"+ />+ </Table.Row>+ </Table.Header>+ <Table.Body>+ {#each visibleChecks as check}+ {@const uptime = uptimePct(check)}+ <Table.Row+ class="cursor-pointer hover:bg-muted/50"+ onclick={createRowClickHandler(+ resolve(`/monitors/${check.id}`),+ 'preset',+ 'from',+ 'to'+ )}+ >+ <Table.Cell class="max-w-[40%] font-medium break-all whitespace-normal">+ {check.name}+ <div class="mt-0.5 font-mono text-xs font-normal text-muted-foreground">+ {#if check.checkType === 'http'}+ {check.config?.method || 'GET'}+ {check.config?.url}+ {:else if check.checkType === 'tcp'}+ {check.config?.host}:{check.config?.port}+ {:else}+ Playwright script+ {/if}+ </div>+ </Table.Cell>+ <Table.Cell>+ <MonitorTypeBadge type={check.checkType} />+ </Table.Cell>+ <Table.Cell>+ <CheckStatusBadge status={check.currentStatus} enabled={check.enabled} />+ </Table.Cell>+ <Table.Cell>+ {#if uptime === null}+ <span class="text-muted-foreground">—</span>+ {:else}+ <div class="flex items-center gap-2">+ <span+ class="w-16 shrink-0 font-mono text-sm tabular-nums {uptimeClass(uptime)}"+ >+ {uptime.toFixed(uptime === 100 ? 0 : 2)}%+ </span>+ <div class="h-1.5 w-14 shrink-0 overflow-hidden rounded-full bg-muted">+ <div+ class="h-full rounded-full {uptime >= 99.9+ ? 'bg-green-500'+ : uptime >= 99+ ? 'bg-amber-500'+ : 'bg-red-500'}"+ style="width: {Math.max(uptime, 4)}%"+ ></div>+ </div>+ </div>+ {/if}+ </Table.Cell>+ <Table.Cell class="font-mono text-sm text-muted-foreground tabular-nums">+ {check.aggregates && check.aggregates.total - check.aggregates.missed > 0+ ? formatDurationMs(check.aggregates.avgLatencyMs)+ : '—'}+ </Table.Cell>+ <Table.Cell class="text-right text-sm text-muted-foreground">+ {formatRelative(check.lastRunAt)}+ </Table.Cell>+ </Table.Row>+ {/each}+ </Table.Body>+ {/if}+ </Table.Root>+ </div>+ {/if}+ {:else if activeTab === 'status-pages'}+ <StatusPagesTab bind:this={statusPagesTab} />+ {/if}+</div>++<MonitorSheet bind:open={dialogOpen} check={null} onSaved={() => loadData(false)} />diff --git a/frontend/src/routes/monitors/+page.ts b/frontend/src/routes/monitors/+page.tsnew file mode 100644index 00000000..5b66ce85--- /dev/null+++ b/frontend/src/routes/monitors/+page.ts@@ -0,0 +1,7 @@+import { redirect } from '@sveltejs/kit';+import { authState } from '$lib/state/auth.svelte';+import type { PageLoad } from './$types';++export const load: PageLoad = () => {+ if (!authState.isAuthenticated) throw redirect(302, '/login');+};diff --git a/frontend/src/routes/monitors/[checkId]/+page.svelte b/frontend/src/routes/monitors/[checkId]/+page.sveltenew file mode 100644index 00000000..f3ab48d1--- /dev/null+++ b/frontend/src/routes/monitors/[checkId]/+page.svelte@@ -0,0 +1,850 @@+<script lang="ts">+ import { onMount, onDestroy } from 'svelte';+ import { api } from '$lib/api';+ import { toUTCISO, calendarDateTimeToLuxon, formatDurationMs } from '$lib/utils/formatters';+ import { getTimezone } from '$lib/state/timezone.svelte';+ import * as Table from '$lib/components/ui/table';+ import * as Card from '$lib/components/ui/card';+ import * as AlertDialog from '$lib/components/ui/alert-dialog';+ import * as Select from '$lib/components/ui/select';+ import { Button } from '$lib/components/ui/button';+ import { Badge } from '$lib/components/ui/badge';+ import { LoadingCircle } from '$lib/components/ui/loading-circle';+ import { ErrorDisplay } from '$lib/components/ui/error-display';+ import { TableEmptyState } from '$lib/components/ui/table-empty-state';+ import { PaginationFooter } from '$lib/components/ui/pagination-footer';+ import { TimeRangePicker } from '$lib/components/ui/time-range-picker';+ import CheckStatusBadge from '$lib/components/synthetics/check-status-badge.svelte';+ import MonitorTypeBadge from '$lib/components/synthetics/monitor-type-badge.svelte';+ import MonitorSheet from '../monitor-sheet.svelte';+ import D3LineChart from '$lib/components/dashboard/d3-line-chart.svelte';+ import PageHeader from '$lib/components/issues/page-header.svelte';+ import { browser } from '$app/environment';+ import { CalendarDate } from '@internationalized/date';+ import { goto } from '$app/navigation';+ import { resolve } from '$app/paths';+ import { projectsState } from '$lib/state/projects.svelte';+ import {+ monitorsState,+ type SyntheticCheck,+ type CheckIncident,+ type CheckResultEntry,+ type CheckSeriesPoint+ } from '$lib/state/monitors.svelte';+ import { createSmartBackHandler } from '$lib/utils/back-navigation';+ import { authState } from '$lib/state/auth.svelte';+ import {+ getTimeRangeFromPreset,+ dateToCalendarDate,+ dateToTimeString,+ parseTimeRangeFromUrl,+ getResolvedTimeRange,+ updateUrl+ } from '$lib/utils/url-params';+ import { Activity, ChartLine, Check as CheckIcon, History, Pause, Pencil, Play, Trash2, TriangleAlert } from '@lucide/svelte';+ import { toast } from 'svelte-sonner';++ let { data } = $props();++ const timezone = $derived(getTimezone());+ const initialTimezone = getTimezone();+ const checkId = data.checkId;++ let check = $state<SyntheticCheck | null>(null);+ let incidents = $state<CheckIncident[]>([]);+ let loading = $state(true);+ let error = $state('');+ let notFound = $state(false);++ let series = $state<CheckSeriesPoint[]>([]);+ let seriesLoading = $state(true);++ let results = $state<CheckResultEntry[]>([]);+ let resultsLoading = $state(true);+ let page = $state(1);+ let pageSize = $state(20);+ let total = $state(0);+ let totalPages = $state(0);++ // Result filter for the runs table; the date range comes from the page's+ // TimeRangePicker.+ let resultFilter = $state('all');+ const resultFilterOptions = [+ { value: 'all', label: 'All results' },+ { value: 'up', label: 'Up' },+ { value: 'down', label: 'Down' },+ { value: 'missed', label: 'Missed' }+ ];+ const resultFilterLabel = $derived(+ resultFilterOptions.find((o) => o.value === resultFilter)?.label || 'All results'+ );++ function onResultFilterChange() {+ page = 1;+ loadResults();+ }++ let editOpen = $state(false);+ let deleteOpen = $state(false);+ let deleting = $state(false);+ let runningNow = $state(false);+ let togglingPause = $state(false);++ const initialUrlParams = browser+ ? parseTimeRangeFromUrl(timezone, '24h')+ : { preset: '24h' as string | null, from: null, to: null };+ const initialRange = getResolvedTimeRange(initialUrlParams, initialTimezone);++ let selectedPreset = $state<string | null>(initialUrlParams.preset);+ let fromDate = $state<CalendarDate>(dateToCalendarDate(initialRange.from, initialTimezone));+ let toDate = $state<CalendarDate>(dateToCalendarDate(initialRange.to, initialTimezone));+ let fromTime = $state(dateToTimeString(initialRange.from, initialTimezone));+ let toTime = $state(dateToTimeString(initialRange.to, initialTimezone));++ function getFromDateTimeUTC(): string {+ const [hour, minute] = (fromTime || '00:00').split(':').map(Number);+ return toUTCISO(+ calendarDateTimeToLuxon(+ { year: fromDate.year, month: fromDate.month, day: fromDate.day, hour, minute },+ timezone+ )+ );+ }++ function getToDateTimeUTC(): string {+ const [hour, minute] = (toTime || '23:59').split(':').map(Number);+ return toUTCISO(+ calendarDateTimeToLuxon(+ { year: toDate.year, month: toDate.month, day: toDate.day, hour, minute },+ timezone+ ).endOf('minute')+ );+ }++ function updateTimeRangeUrl(pushToHistory = true) {+ const params: Record<string, string | null | undefined> = {};+ if (selectedPreset) {+ params.preset = selectedPreset;+ } else {+ params.from = getFromDateTimeUTC();+ params.to = getToDateTimeUTC();+ }+ updateUrl(params, { pushToHistory });+ }++ // Snap to a step that yields ~96 buckets at most, so the availability+ // strip stays readable for every range (a 3M range at 240m would be 540+ // cells and overflow the row). The small tolerance keeps a range that is+ // one endOf-minute epsilon over a boundary on the finer step.+ const intervalSteps = [1, 5, 15, 30, 60, 120, 240, 480, 720, 1440];++ function calculateInterval(from: Date, to: Date): number {+ const raw = (to.getTime() - from.getTime()) / 60000 / 96;+ for (const step of intervalSteps) {+ if (step >= raw - 0.05) return step;+ }+ return 1440;+ }++ async function loadCheck() {+ try {+ const response = await api.get(`/synthetics/checks/${checkId}`, {+ projectId: projectsState.currentProjectId ?? undefined+ });+ check = response.check;+ incidents = response.incidents || [];+ } catch (e: any) {+ if (e.status === 404) {+ notFound = true;+ } else {+ error = e.message || 'Failed to load the monitor';+ }+ }+ }++ async function loadSeries() {+ seriesLoading = true;+ try {+ const fromStr = getFromDateTimeUTC();+ const toStr = getToDateTimeUTC();+ const response = await api.post(+ `/synthetics/checks/${checkId}/series`,+ {+ fromDate: fromStr,+ toDate: toStr,+ intervalMinutes: calculateInterval(new Date(fromStr), new Date(toStr))+ },+ { projectId: projectsState.currentProjectId ?? undefined }+ );+ series = response.series || [];+ } catch (e) {+ console.error('Failed to load check series:', e);+ series = [];+ } finally {+ seriesLoading = false;+ }+ }++ async function loadResults() {+ resultsLoading = true;+ try {+ const response = await api.post(+ `/synthetics/checks/${checkId}/results`,+ {+ fromDate: getFromDateTimeUTC(),+ toDate: getToDateTimeUTC(),+ status: resultFilter === 'all' ? '' : resultFilter,+ pagination: { page, pageSize }+ },+ { projectId: projectsState.currentProjectId ?? undefined }+ );+ results = response.data || [];+ total = response.pagination.total;+ totalPages = response.pagination.totalPages;+ } catch (e) {+ console.error('Failed to load check results:', e);+ results = [];+ } finally {+ resultsLoading = false;+ }+ }++ async function loadAll(pushToHistory = true) {+ loading = true;+ error = '';+ notFound = false;++ if (selectedPreset) {+ const range = getTimeRangeFromPreset(selectedPreset, timezone);+ fromDate = dateToCalendarDate(range.from, timezone);+ toDate = dateToCalendarDate(range.to, timezone);+ fromTime = dateToTimeString(range.from, timezone);+ toTime = dateToTimeString(range.to, timezone);+ }+ updateTimeRangeUrl(pushToHistory);++ await loadCheck();+ loading = false;+ if (!notFound && !error) {+ loadSeries();+ loadResults();+ }+ }++ function handlePopState() {+ const urlParams = parseTimeRangeFromUrl(timezone, '24h');+ const range = getResolvedTimeRange(urlParams, timezone);+ selectedPreset = urlParams.preset;+ fromDate = dateToCalendarDate(range.from, timezone);+ fromTime = dateToTimeString(range.from, timezone);+ toDate = dateToCalendarDate(range.to, timezone);+ toTime = dateToTimeString(range.to, timezone);+ page = 1;+ loadAll(false);+ }++ function handleTimeRangeChange(+ from: { date: CalendarDate; time: string },+ to: { date: CalendarDate; time: string },+ preset: string | null+ ) {+ fromDate = from.date;+ fromTime = from.time;+ toDate = to.date;+ toTime = to.time;+ selectedPreset = preset;+ page = 1;+ loadAll(false);+ }++ async function runNow() {+ runningNow = true;+ try {+ await api.post(+ `/synthetics/checks/${checkId}/run`,+ {},+ { projectId: projectsState.currentProjectId ?? undefined }+ );+ toast.success('Run queued', { position: 'top-center' });+ setTimeout(() => {+ loadCheck();+ loadResults();+ }, 3000);+ } catch (e: any) {+ if (e?.status !== 403) {+ toast.error(e.message || 'Failed to queue the run', { position: 'top-center' });+ }+ } finally {+ runningNow = false;+ }+ }++ async function togglePause() {+ if (!check) return;+ togglingPause = true;+ try {+ const response = await api.put(+ `/synthetics/checks/${checkId}`,+ {+ name: check.name,+ checkType: check.checkType,+ enabled: !check.enabled,+ intervalSeconds: check.intervalSeconds,+ timeoutSeconds: check.timeoutSeconds,+ failureThreshold: check.failureThreshold,+ config: check.config+ },+ { projectId: projectsState.currentProjectId ?? undefined }+ );+ check = response;+ toast.success('Successfully updated the Monitor', { position: 'top-center' });+ } catch (e: any) {+ if (e?.status !== 403) {+ toast.error(e.message || 'Failed to update the monitor', { position: 'top-center' });+ }+ } finally {+ togglingPause = false;+ }+ }++ async function deleteCheck() {+ deleting = true;+ try {+ await api.delete(`/synthetics/checks/${checkId}`, {+ projectId: projectsState.currentProjectId ?? undefined+ });+ toast.success('Successfully deleted the Monitor', { position: 'top-center' });+ monitorsState.refreshDownCount();+ goto(resolve('/monitors'));+ } catch (e: any) {+ if (e?.status !== 403) {+ toast.error(e.message || 'Failed to delete the monitor', { position: 'top-center' });+ }+ deleting = false;+ deleteOpen = false;+ }+ }++ const rangeAggregates = $derived.by(() => {+ let up = 0;+ let measured = 0;+ let latencySum = 0;+ for (const point of series) {+ up += point.up;+ measured += point.total - point.missed;+ latencySum += point.avgLatencyMs * (point.total - point.missed);+ }+ return {+ uptime: measured > 0 ? (up / measured) * 100 : null,+ avgLatency: measured > 0 ? latencySum / measured : null+ };+ });++ const latencySeries = $derived.by(() => [+ {+ key: 'Avg latency',+ color: 'var(--chart-1)',+ data: series+ .filter((p) => p.total - p.missed > 0)+ .map((p) => ({ timestamp: new Date(p.bucket), value: p.avgLatencyMs }))+ }+ ]);++ // The backend only returns buckets that have rows; rebuild the full+ // epoch-floored grid over the selected range so sparse data renders as+ // explicit no-data cells instead of a few bars stretched across the strip.+ const paddedSeries = $derived.by(() => {+ if (series.length === 0) return [] as CheckSeriesPoint[];+ const fromMs = Date.parse(getFromDateTimeUTC());+ const toMs = Date.parse(getToDateTimeUTC());+ const stepMs = calculateInterval(new Date(fromMs), new Date(toMs)) * 60000;+ const byBucket = new Map(series.map((p) => [new Date(p.bucket).getTime(), p]));+ const cells: CheckSeriesPoint[] = [];+ for (let t = Math.floor(fromMs / stepMs) * stepMs; t <= toMs && cells.length < 400; t += stepMs) {+ cells.push(+ byBucket.get(t) ?? {+ bucket: new Date(t).toISOString(),+ total: 0,+ up: 0,+ missed: 0,+ avgLatencyMs: 0,+ maxLatencyMs: 0+ }+ );+ }+ return cells;+ });++ function bucketClass(point: CheckSeriesPoint): string {+ const measured = point.total - point.missed;+ if (measured === 0) return 'bg-muted';+ if (point.up === measured) return 'bg-green-500';+ if (point.up === 0) return 'bg-red-500';+ return 'bg-amber-500';+ }++ function bucketTitle(point: CheckSeriesPoint): string {+ const measured = point.total - point.missed;+ const when = new Date(point.bucket).toLocaleString();+ if (measured === 0) return `${when}: no data`;+ return `${when}: ${point.up}/${measured} up${point.missed > 0 ? `, ${point.missed} missed` : ''}`;+ }++ function formatTime(iso: string): string {+ return new Date(iso).toLocaleString();+ }++ async function viewScreenshot(key: string) {+ try {+ const params = new URLSearchParams({ key });+ if (projectsState.currentProjectId) {+ params.set('projectId', projectsState.currentProjectId);+ }+ const response = await fetch(`/api/synthetics/screenshot?${params}`, {+ headers: { Authorization: `Bearer ${authState.token}` }+ });+ if (!response.ok) throw new Error('Screenshot not found');+ const blob = await response.blob();+ window.open(URL.createObjectURL(blob), '_blank', 'noopener');+ } catch {+ toast.error('Failed to load the screenshot', { position: 'top-center' });+ }+ }++ let outputOpen = $state(false);+ let outputText = $state('');+ let outputLoading = $state(false);++ async function viewOutput(key: string) {+ outputOpen = true;+ outputLoading = true;+ outputText = '';+ try {+ const params = new URLSearchParams({ key });+ if (projectsState.currentProjectId) {+ params.set('projectId', projectsState.currentProjectId);+ }+ const response = await fetch(`/api/synthetics/output?${params}`, {+ headers: { Authorization: `Bearer ${authState.token}` }+ });+ if (!response.ok) throw new Error('Output not found');+ outputText = await response.text();+ } catch {+ outputOpen = false;+ toast.error('Failed to load the run output', { position: 'top-center' });+ } finally {+ outputLoading = false;+ }+ }++ function handlePageChange(newPage: number) {+ if (newPage >= 1 && newPage <= totalPages) {+ page = newPage;+ loadResults();+ }+ }++ function handlePageSizeChange(newPageSize: number) {+ pageSize = newPageSize;+ page = 1;+ loadResults();+ }++ onMount(() => {+ window.addEventListener('popstate', handlePopState);+ loadAll(false);+ });++ onDestroy(() => {+ if (typeof window !== 'undefined') {+ window.removeEventListener('popstate', handlePopState);+ }+ });+</script>++{#if loading}+ <div class="flex h-64 items-center justify-center">+ <LoadingCircle size="xlg" />+ </div>+{:else if notFound}+ <ErrorDisplay+ status={404}+ title="Monitor not found"+ description="This monitor does not exist or belongs to a different project."+ onBack={createSmartBackHandler({ fallbackPath: '/monitors' })}+ backLabel="Back to Monitors"+ />+{:else if error}+ <ErrorDisplay+ status={400}+ title="Error"+ description={error}+ onRetry={() => loadAll(false)}+ onBack={createSmartBackHandler({ fallbackPath: '/monitors' })}+ backLabel="Back to Monitors"+ />+{:else if check}+ <div class="space-y-4">+ <div class="flex flex-col gap-4 sm:flex-row sm:justify-between">+ <PageHeader+ title={check.name}+ onBack={createSmartBackHandler({ fallbackPath: '/monitors' })}+ />+ <div class="flex flex-col">+ <TimeRangePicker+ bind:fromDate+ bind:toDate+ bind:fromTime+ bind:toTime+ bind:preset={selectedPreset}+ onApply={handleTimeRangeChange}+ />+ </div>+ </div>++ <div class="flex flex-wrap items-center gap-3">+ <CheckStatusBadge status={check.currentStatus} enabled={check.enabled} />+ <MonitorTypeBadge type={check.checkType} />+ <span class="font-mono text-sm text-muted-foreground">+ {#if check.checkType === 'http'}+ {check.config?.method || 'GET'} {check.config?.url}+ {:else if check.checkType === 'tcp'}+ {check.config?.host}:{check.config?.port}+ {/if}+ </span>+ <div class="flex-1"></div>+ {#if projectsState.canWriteCurrentProject}+ <Button variant="outline" size="sm" onclick={runNow} disabled={runningNow || !check.enabled}>+ <Play class="mr-1.5 h-4 w-4" />+ {runningNow ? 'Queueing...' : 'Run now'}+ </Button>+ <Button variant="outline" size="sm" onclick={togglePause} disabled={togglingPause}>+ {#if check.enabled}+ <Pause class="mr-1.5 h-4 w-4" />+ Pause+ {:else}+ <Play class="mr-1.5 h-4 w-4" />+ Resume+ {/if}+ </Button>+ <Button variant="outline" size="sm" onclick={() => (editOpen = true)}>+ <Pencil class="mr-1.5 h-4 w-4" />+ Edit+ </Button>+ <Button variant="destructiveOutline" size="sm" onclick={() => (deleteOpen = true)}>+ <Trash2 class="mr-1.5 h-4 w-4" />+ Delete+ </Button>+ {/if}+ </div>++ <Card.Root class="py-0">+ <div class="grid grid-cols-2 divide-y divide-border sm:grid-cols-4 sm:divide-x sm:divide-y-0">+ <div class="px-6 py-4">+ <div class="text-xs font-medium text-muted-foreground">Uptime</div>+ <div+ class="mt-1 text-2xl font-semibold tabular-nums {rangeAggregates.uptime === null+ ? 'text-muted-foreground'+ : rangeAggregates.uptime >= 99.9+ ? 'text-green-600 dark:text-green-400'+ : rangeAggregates.uptime >= 99+ ? ''+ : 'text-red-600 dark:text-red-400'}"+ >+ {rangeAggregates.uptime === null+ ? '—'+ : `${rangeAggregates.uptime.toFixed(rangeAggregates.uptime === 100 ? 0 : 2)}%`}+ </div>+ </div>+ <div class="px-6 py-4">+ <div class="text-xs font-medium text-muted-foreground">Avg latency</div>+ <div class="mt-1 text-2xl font-semibold tabular-nums">+ {rangeAggregates.avgLatency === null ? '—' : formatDurationMs(rangeAggregates.avgLatency)}+ </div>+ </div>+ <div class="px-6 py-4">+ <div class="text-xs font-medium text-muted-foreground">Interval</div>+ <div class="mt-1 text-2xl font-semibold tabular-nums">+ {check.intervalSeconds >= 3600+ ? `${check.intervalSeconds / 3600}h`+ : check.intervalSeconds >= 60+ ? `${check.intervalSeconds / 60}m`+ : `${check.intervalSeconds}s`}+ </div>+ </div>+ <div class="px-6 py-4">+ <div class="text-xs font-medium text-muted-foreground">Incidents (recent)</div>+ <div+ class="mt-1 text-2xl font-semibold tabular-nums {incidents.some((i) => !i.resolvedAt)+ ? 'text-red-600 dark:text-red-400'+ : ''}"+ >+ {incidents.length}+ </div>+ </div>+ </div>+ </Card.Root>++ <Card.Root class="pt-2 gap-3">+ <Card.Header class="border-b [.border-b]:pb-2 pl-3">+ <Card.Title class="flex items-center gap-2 text-base font-medium">+ <Activity class="h-3.5 w-3.5 text-muted-foreground" />+ <span class="text-sm font-[400] text-muted-foreground">Availability</span>+ </Card.Title>+ </Card.Header>+ <Card.Content class="pb-4">+ {#if seriesLoading}+ <div class="flex h-16 items-center justify-center">+ <LoadingCircle />+ </div>+ {:else if series.length === 0}+ <div class="flex h-16 items-center justify-center text-sm text-muted-foreground">+ No probe data in this period+ </div>+ {:else}+ <div class="flex h-9 items-stretch gap-[3px]">+ {#each paddedSeries as point}+ <div+ class="min-w-[4px] flex-1 rounded-[3px] transition-transform hover:scale-y-110 {bucketClass(+ point+ )}"+ title={bucketTitle(point)}+ ></div>+ {/each}+ </div>+ <div class="mt-1.5 flex justify-between text-xs text-muted-foreground">+ <span>{new Date(paddedSeries[0].bucket).toLocaleString()}</span>+ <span>Now</span>+ </div>+ {/if}+ </Card.Content>+ </Card.Root>++ <Card.Root class="pt-2 gap-3">+ <Card.Header class="border-b [.border-b]:pb-2 pl-3">+ <Card.Title class="flex items-center gap-2 text-base font-medium">+ <ChartLine class="h-3.5 w-3.5 text-muted-foreground" />+ <span class="text-sm font-[400] text-muted-foreground">Latency</span>+ </Card.Title>+ </Card.Header>+ <Card.Content>+ {#if seriesLoading}+ <div class="flex h-[220px] items-center justify-center">+ <LoadingCircle size="xlg" />+ </div>+ {:else if latencySeries[0].data.length === 0}+ <div class="flex h-[220px] items-center justify-center text-sm text-muted-foreground">+ No latency data in this period+ </div>+ {:else}+ <D3LineChart series={latencySeries} formatValue={formatDurationMs} unit="ms" />+ {/if}+ </Card.Content>+ </Card.Root>++ <Card.Root class="gap-0 pt-2 pb-0">+ <Card.Header+ class="flex flex-row flex-wrap items-center justify-between gap-3 space-y-0 border-b [.border-b]:pb-2 pl-3"+ >+ <Card.Title class="flex items-center gap-2 text-base font-medium">+ <History class="h-3.5 w-3.5 text-muted-foreground" />+ <span class="text-sm font-[400] text-muted-foreground">Run history</span>+ </Card.Title>+ <Select.Root type="single" bind:value={resultFilter} onValueChange={onResultFilterChange}>+ <Select.Trigger class="h-8 w-[130px] text-xs">{resultFilterLabel}</Select.Trigger>+ <Select.Content>+ {#each resultFilterOptions as option}+ <Select.Item value={option.value}>{option.label}</Select.Item>+ {/each}+ </Select.Content>+ </Select.Root>+ </Card.Header>+ <Card.Content class="overflow-hidden rounded-b-xl p-0">+ <Table.Root>+ {#if resultsLoading}+ <Table.Body>+ <Table.Row>+ <Table.Cell colspan={5} class="h-32">+ <div class="flex h-full items-center justify-center">+ <LoadingCircle size="xlg" />+ </div>+ </Table.Cell>+ </Table.Row>+ </Table.Body>+ {:else if results.length === 0}+ <Table.Body>+ <TableEmptyState colspan={5} message="No runs in this period" />+ </Table.Body>+ {:else}+ <Table.Header>+ <Table.Row>+ <Table.Head>Time</Table.Head>+ <Table.Head class="w-[100px]">Result</Table.Head>+ <Table.Head class="w-[110px]">Latency</Table.Head>+ <Table.Head class="w-[90px]">Status code</Table.Head>+ <Table.Head>Error</Table.Head>+ </Table.Row>+ </Table.Header>+ <Table.Body>+ {#each results as result}+ <Table.Row>+ <Table.Cell class="text-sm whitespace-nowrap">+ {formatTime(result.recordedAt)}+ <span class="ml-1 text-xs text-muted-foreground">via {result.executedBy}</span>+ </Table.Cell>+ <Table.Cell>+ {#if result.status === 'up'}+ <span+ class="inline-flex items-center gap-1 rounded-full bg-green-500/15 px-2 py-0.5 text-xs font-medium text-green-600 dark:text-green-400"+ >+ <CheckIcon class="h-3 w-3" />+ Up+ </span>+ {:else if result.status === 'down'}+ <span+ class="inline-flex items-center rounded-full bg-red-500/15 px-2 py-0.5 text-xs font-medium text-red-600 dark:text-red-400"+ >+ Down+ </span>+ {:else}+ <span+ class="inline-flex items-center rounded-full bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground"+ >+ Missed+ </span>+ {/if}+ </Table.Cell>+ <Table.Cell class="font-mono text-sm tabular-nums text-muted-foreground">+ {result.status === 'missed' ? '—' : formatDurationMs(result.latencyMs)}+ </Table.Cell>+ <Table.Cell class="font-mono text-sm tabular-nums text-muted-foreground">+ {result.statusCode > 0 ? result.statusCode : '—'}+ </Table.Cell>+ <Table.Cell class="max-w-[300px] text-xs break-all whitespace-normal text-muted-foreground">+ {result.errorMessage || ''}+ {#if result.screenshotKey}+ <button+ type="button"+ class="ml-1 cursor-pointer text-primary underline underline-offset-2"+ onclick={() => viewScreenshot(result.screenshotKey)}+ >+ screenshot+ </button>+ {/if}+ {#if result.outputKey}+ <button+ type="button"+ class="ml-1 cursor-pointer text-primary underline underline-offset-2"+ onclick={() => viewOutput(result.outputKey)}+ >+ logs+ </button>+ {/if}+ </Table.Cell>+ </Table.Row>+ {/each}+ </Table.Body>+ {/if}+ </Table.Root>+ </Card.Content>+ </Card.Root>++ <PaginationFooter+ currentPage={page}+ {totalPages}+ {pageSize}+ totalItems={total}+ onPageChange={handlePageChange}+ onPageSizeChange={handlePageSizeChange}+ loading={resultsLoading}+ itemLabel="run"+ />++ {#if incidents.length > 0}+ <Card.Root class="pt-2 gap-3">+ <Card.Header class="border-b [.border-b]:pb-2 pl-3">+ <Card.Title class="flex items-center gap-2 text-base font-medium">+ <TriangleAlert class="h-3.5 w-3.5 text-muted-foreground" />+ <span class="text-sm font-[400] text-muted-foreground">Incidents</span>+ </Card.Title>+ </Card.Header>+ <Card.Content class="pb-4">+ <div class="space-y-2">+ {#each incidents as incident}+ <div class="flex items-start justify-between gap-4 rounded-md border p-3 text-sm">+ <div class="min-w-0">+ <div class="font-medium">+ {formatTime(incident.startedAt)}+ {#if incident.resolvedAt}+ <span class="text-muted-foreground">→ {formatTime(incident.resolvedAt)}</span>+ {/if}+ </div>+ {#if incident.errorMessage}+ <div class="mt-1 text-xs break-all text-muted-foreground">+ {incident.errorMessage}+ </div>+ {/if}+ </div>+ {#if incident.resolvedAt}+ <span+ class="inline-flex shrink-0 items-center rounded-full bg-green-500/15 px-2 py-0.5 text-xs font-medium text-green-600 dark:text-green-400"+ >+ Resolved+ </span>+ {:else}+ <span+ class="inline-flex shrink-0 items-center rounded-full bg-red-500/15 px-2 py-0.5 text-xs font-medium text-red-600 dark:text-red-400"+ >+ Ongoing+ </span>+ {/if}+ </div>+ {/each}+ </div>+ </Card.Content>+ </Card.Root>+ {/if}+ </div>++ <MonitorSheet bind:open={editOpen} {check} onSaved={() => loadAll(false)} />++ <AlertDialog.Root bind:open={deleteOpen}>+ <AlertDialog.Content interactOutsideBehavior={deleting ? 'ignore' : 'close'}>+ <AlertDialog.Header>+ <AlertDialog.Title>Delete Monitor</AlertDialog.Title>+ <AlertDialog.Description>+ This permanently deletes "{check.name}" along with its run history and incidents.+ </AlertDialog.Description>+ </AlertDialog.Header>+ <AlertDialog.Footer>+ <AlertDialog.Cancel disabled={deleting}>Cancel</AlertDialog.Cancel>+ <Button variant="destructive" onclick={deleteCheck} disabled={deleting}>+ <Trash2 class="mr-2 h-4 w-4" />+ {deleting ? 'Deleting...' : 'Delete Monitor'}+ </Button>+ </AlertDialog.Footer>+ </AlertDialog.Content>+ </AlertDialog.Root>++ <AlertDialog.Root bind:open={outputOpen}>+ <AlertDialog.Content class="sm:max-w-3xl">+ <AlertDialog.Header>+ <AlertDialog.Title>Run output</AlertDialog.Title>+ <AlertDialog.Description>+ Playwright output captured from the failed run.+ </AlertDialog.Description>+ </AlertDialog.Header>+ {#if outputLoading}+ <div class="flex h-40 items-center justify-center">+ <LoadingCircle size="lg" />+ </div>+ {:else}+ <pre+ class="max-h-[60vh] overflow-auto rounded-md border bg-muted/50 p-3 font-mono text-xs whitespace-pre-wrap">{outputText}</pre>+ {/if}+ <AlertDialog.Footer>+ <AlertDialog.Cancel>Close</AlertDialog.Cancel>+ </AlertDialog.Footer>+ </AlertDialog.Content>+ </AlertDialog.Root>+{/if}diff --git a/frontend/src/routes/monitors/[checkId]/+page.ts b/frontend/src/routes/monitors/[checkId]/+page.tsnew file mode 100644index 00000000..17cc01a0--- /dev/null+++ b/frontend/src/routes/monitors/[checkId]/+page.ts@@ -0,0 +1,23 @@+import { redirect } from '@sveltejs/kit';+import { authState } from '$lib/state/auth.svelte';+import type { PageLoad } from './$types';++export const prerender = false;++export const load: PageLoad = ({ params, url }) => {+ // Old sub-page URLs; without this they'd match [checkId]. Status pages are+ // now a tab; the runners page was removed (runners are operator infra).+ if (params.checkId === 'status-pages') {+ throw redirect(301, '/monitors?tab=status-pages');+ }+ if (params.checkId === 'runners') {+ throw redirect(301, '/monitors');+ }+ if (!authState.isAuthenticated) throw redirect(302, '/login');+ return {+ checkId: params.checkId,+ preset: url.searchParams.get('preset'),+ from: url.searchParams.get('from'),+ to: url.searchParams.get('to')+ };+};diff --git a/frontend/src/routes/monitors/monitor-sheet.svelte b/frontend/src/routes/monitors/monitor-sheet.sveltenew file mode 100644index 00000000..c22402c0--- /dev/null+++ b/frontend/src/routes/monitors/monitor-sheet.svelte@@ -0,0 +1,685 @@+<script lang="ts">+ import { api } from '$lib/api';+ import * as Sheet from '$lib/components/ui/sheet';+ import * as Select from '$lib/components/ui/select';+ import * as Tabs from '$lib/components/ui/tabs';+ import { Button } from '$lib/components/ui/button';+ import { Input } from '$lib/components/ui/input';+ import { Label } from '$lib/components/ui/label';+ import { Checkbox } from '$lib/components/ui/checkbox';+ import { ErrorAlert } from '$lib/components/ui/error-alert';+ import { CodeEditor } from '$lib/components/ui/code-editor';+ import KeyValueRows from '$lib/components/synthetics/key-value-rows.svelte';+ import { projectsState } from '$lib/state/projects.svelte';+ import type { SyntheticCheck, CheckConfig, CheckType } from '$lib/state/monitors.svelte';+ import { Check, Globe, Plus } from '@lucide/svelte';+ import { toast } from 'svelte-sonner';++ interface Props {+ open: boolean;+ check: SyntheticCheck | null;+ onSaved: () => void;+ }++ let { open = $bindable(), check, onSaved }: Props = $props();++ const isEditing = $derived(check !== null);+ let loading = $state(false);+ let error = $state('');++ const tabTriggerClass =+ '-mb-px shrink-0 rounded-none border-b-2 border-transparent bg-transparent px-0 pb-2.5 pt-0 text-sm font-medium text-muted-foreground shadow-none transition-none data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:text-foreground data-[state=active]:shadow-none';++ // Common fields+ let name = $state('');+ let checkType = $state<CheckType>('http');+ let intervalSeconds = $state('60');+ let timeoutSeconds = $state('30');+ let failureThreshold = $state('2');++ // HTTP fields+ let requestTab = $state('headers');+ let httpUrl = $state('');+ let httpMethod = $state('GET');+ let headerRows = $state<{ key: string; value: string }[]>([]);+ let authType = $state('none');+ let authUsername = $state('');+ let authPassword = $state('');+ let authToken = $state('');+ let authHeaderName = $state('');+ let authHeaderValue = $state('');+ let httpBody = $state('');+ let httpBodyContentType = $state('application/json');+ let followRedirects = $state(true);+ let skipTlsVerify = $state(false);+ let expectedStatusCodes = $state('');+ let bodyContains = $state('');+ let bodyRegex = $state('');+ let maxResponseTimeMs = $state('');+ let tlsMinDaysRemaining = $state('');++ // TCP fields+ let tcpHost = $state('');+ let tcpPort = $state('');+ let tcpUseTls = $state(false);+ let tcpSendPayload = $state('');+ let tcpExpectContains = $state('');+ let tcpTlsMinDaysRemaining = $state('');++ // Browser fields+ let browserScript = $state('');+ let envRows = $state<{ key: string; value: string }[]>([]);++ // Browser checks execute user scripts server-side and are hard-blocked in+ // cloud mode, so the cloud build does not offer the type at all.+ const checkTypeOptions = [+ { value: 'http', label: 'HTTP' },+ { value: 'tcp', label: 'TCP' },+ ...(__CLOUD_MODE__ ? [] : [{ value: 'browser', label: 'Browser (Playwright)' }])+ ];++ const intervalOptions = [+ { value: '30', label: 'Every 30 seconds' },+ { value: '60', label: 'Every minute' },+ { value: '120', label: 'Every 2 minutes' },+ { value: '300', label: 'Every 5 minutes' },+ { value: '600', label: 'Every 10 minutes' },+ { value: '900', label: 'Every 15 minutes' },+ { value: '1800', label: 'Every 30 minutes' },+ { value: '3600', label: 'Every hour' },+ { value: '21600', label: 'Every 6 hours' },+ { value: '86400', label: 'Every 24 hours' }+ ];++ const methodOptions = ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'];++ const authOptions = [+ { value: 'none', label: 'No auth' },+ { value: 'basic', label: 'Basic auth' },+ { value: 'bearer', label: 'Bearer token' },+ { value: 'header', label: 'Custom header' }+ ];++ const methodHasBody = $derived(['POST', 'PUT', 'PATCH', 'DELETE'].includes(httpMethod));++ const defaultBrowserScript = `import { test, expect } from '@playwright/test';++test('page loads', async ({ page }) => {+ await page.goto('https://example.com');+ await expect(page).toHaveTitle(/Example/);+});+`;++ function resetForm() {+ name = '';+ checkType = 'http';+ intervalSeconds = '60';+ timeoutSeconds = '30';+ failureThreshold = '2';+ requestTab = 'headers';+ httpUrl = '';+ httpMethod = 'GET';+ headerRows = [];+ authType = 'none';+ authUsername = '';+ authPassword = '';+ authToken = '';+ authHeaderName = '';+ authHeaderValue = '';+ httpBody = '';+ httpBodyContentType = 'application/json';+ followRedirects = true;+ skipTlsVerify = false;+ expectedStatusCodes = '';+ bodyContains = '';+ bodyRegex = '';+ maxResponseTimeMs = '';+ tlsMinDaysRemaining = '';+ tcpHost = '';+ tcpPort = '';+ tcpUseTls = false;+ tcpSendPayload = '';+ tcpExpectContains = '';+ tcpTlsMinDaysRemaining = '';+ browserScript = defaultBrowserScript;+ envRows = [];+ error = '';+ }++ function populateFromCheck(c: SyntheticCheck) {+ resetForm();+ name = c.name;+ checkType = c.checkType;+ intervalSeconds = String(c.intervalSeconds);+ timeoutSeconds = String(c.timeoutSeconds);+ failureThreshold = String(c.failureThreshold);+ const cfg = c.config ?? {};+ if (c.checkType === 'http') {+ httpUrl = cfg.url ?? '';+ httpMethod = (cfg.method || 'GET').toUpperCase();+ headerRows = Object.entries(cfg.headers ?? {}).map(([key, value]) => ({ key, value }));+ authType = cfg.auth?.type || 'none';+ authUsername = cfg.auth?.username ?? '';+ authPassword = cfg.auth?.password ?? '';+ authToken = cfg.auth?.token ?? '';+ authHeaderName = cfg.auth?.headerName ?? '';+ authHeaderValue = cfg.auth?.headerValue ?? '';+ httpBody = cfg.body ?? '';+ httpBodyContentType = cfg.bodyContentType || 'application/json';+ followRedirects = cfg.followRedirects ?? true;+ skipTlsVerify = cfg.skipTlsVerify ?? false;+ expectedStatusCodes = (cfg.assertions?.statusCodes ?? []).join(', ');+ bodyContains = cfg.assertions?.bodyContains ?? '';+ bodyRegex = cfg.assertions?.bodyRegex ?? '';+ maxResponseTimeMs = cfg.assertions?.maxResponseTimeMs+ ? String(cfg.assertions.maxResponseTimeMs)+ : '';+ tlsMinDaysRemaining = cfg.assertions?.tlsMinDaysRemaining+ ? String(cfg.assertions.tlsMinDaysRemaining)+ : '';+ } else if (c.checkType === 'tcp') {+ tcpHost = cfg.host ?? '';+ tcpPort = cfg.port ? String(cfg.port) : '';+ tcpUseTls = cfg.useTls ?? false;+ tcpSendPayload = cfg.sendPayload ?? '';+ tcpExpectContains = cfg.expectContains ?? '';+ tcpTlsMinDaysRemaining = cfg.tlsMinDaysRemaining ? String(cfg.tlsMinDaysRemaining) : '';+ } else if (c.checkType === 'browser') {+ browserScript = cfg.script ?? '';+ envRows = Object.entries(cfg.env ?? {}).map(([key, value]) => ({ key, value }));+ }+ }++ $effect(() => {+ if (open && check) {+ populateFromCheck(check);+ } else if (open && !check) {+ resetForm();+ }+ });++ function handleOpenChange(value: boolean) {+ open = value;+ if (!value) {+ error = '';+ }+ }++ function rowsToMap(rows: { key: string; value: string }[]): Record<string, string> {+ const map: Record<string, string> = {};+ for (const row of rows) {+ if (row.key.trim()) {+ map[row.key.trim()] = row.value;+ }+ }+ return map;+ }++ function buildConfig(): CheckConfig {+ if (checkType === 'http') {+ const statusCodes = expectedStatusCodes+ .split(',')+ .map((s) => parseInt(s.trim(), 10))+ .filter((n) => !isNaN(n));+ return {+ url: httpUrl.trim(),+ method: httpMethod,+ headers: rowsToMap(headerRows),+ auth: {+ type: authType as 'none' | 'basic' | 'bearer' | 'header',+ username: authUsername,+ password: authPassword,+ token: authToken,+ headerName: authHeaderName,+ headerValue: authHeaderValue+ },+ body: methodHasBody ? httpBody : '',+ bodyContentType: methodHasBody ? httpBodyContentType : '',+ followRedirects,+ skipTlsVerify,+ assertions: {+ statusCodes,+ bodyContains,+ bodyRegex,+ maxResponseTimeMs: parseInt(maxResponseTimeMs, 10) || 0,+ tlsMinDaysRemaining: parseInt(tlsMinDaysRemaining, 10) || 0+ }+ };+ }+ if (checkType === 'tcp') {+ return {+ host: tcpHost.trim(),+ port: parseInt(tcpPort, 10) || 0,+ useTls: tcpUseTls,+ sendPayload: tcpSendPayload,+ expectContains: tcpExpectContains,+ tlsMinDaysRemaining: parseInt(tcpTlsMinDaysRemaining, 10) || 0+ };+ }+ return {+ script: browserScript,+ env: rowsToMap(envRows)+ };+ }++ async function handleSubmit() {+ loading = true;+ error = '';+ try {+ const payload = {+ name: name.trim(),+ checkType,+ enabled: check?.enabled ?? true,+ intervalSeconds: parseInt(intervalSeconds, 10) || 60,+ timeoutSeconds: parseInt(timeoutSeconds, 10) || 30,+ failureThreshold: parseInt(failureThreshold, 10) || 2,+ config: buildConfig()+ };+ if (isEditing && check) {+ await api.put(`/synthetics/checks/${check.id}`, payload, {+ projectId: projectsState.currentProjectId ?? undefined+ });+ toast.success('Successfully updated the Monitor', { position: 'top-center' });+ } else {+ await api.post('/synthetics/checks', payload, {+ projectId: projectsState.currentProjectId ?? undefined+ });+ toast.success('Successfully created the Monitor', { position: 'top-center' });+ }+ open = false;+ onSaved();+ } catch (e) {+ error = e instanceof Error ? e.message : 'Failed to save the monitor';+ } finally {+ loading = false;+ }+ }++ const checkTypeLabel = $derived(+ checkTypeOptions.find((o) => o.value === checkType)?.label || 'Select type'+ );+ const intervalLabel = $derived(+ intervalOptions.find((o) => o.value === intervalSeconds)?.label ||+ `Every ${intervalSeconds} seconds`+ );+ const authLabel = $derived(authOptions.find((o) => o.value === authType)?.label || 'No auth');+ const headerCount = $derived(headerRows.filter((r) => r.key.trim()).length);+</script>++<Sheet.Root {open} onOpenChange={handleOpenChange}>+ <Sheet.Content+ side="right"+ class="flex w-full flex-col gap-0 overflow-y-auto sm:w-[760px] sm:max-w-[760px]"+ >+ <Sheet.Header class="border-b px-6 pb-4">+ <Sheet.Title>{isEditing ? 'Edit Monitor' : 'New Monitor'}</Sheet.Title>+ <Sheet.Description>+ {isEditing+ ? 'Update how this monitor probes your service.'+ : 'Probe a URL, port, or browser flow on a schedule and track its uptime.'}+ </Sheet.Description>+ </Sheet.Header>++ <form+ onsubmit={(e) => {+ e.preventDefault();+ handleSubmit();+ }}+ class="flex-1 space-y-5 px-6 py-5"+ >+ <ErrorAlert {error} />++ <div class="grid grid-cols-2 gap-4">+ <div class="space-y-2">+ <Label for="monitor-name">Name</Label>+ <Input+ id="monitor-name"+ bind:value={name}+ placeholder="Marketing site"+ disabled={loading}+ />+ </div>+ <div class="space-y-2">+ <Label>Type</Label>+ <Select.Root type="single" bind:value={checkType} disabled={loading || isEditing}>+ <Select.Trigger class="w-full">{checkTypeLabel}</Select.Trigger>+ <Select.Content>+ {#each checkTypeOptions as option}+ <Select.Item value={option.value}>{option.label}</Select.Item>+ {/each}+ </Select.Content>+ </Select.Root>+ </div>+ </div>++ <div class="grid grid-cols-3 gap-4">+ <div class="space-y-2">+ <Label>Interval</Label>+ <Select.Root type="single" bind:value={intervalSeconds} disabled={loading}>+ <Select.Trigger class="w-full">{intervalLabel}</Select.Trigger>+ <Select.Content class="max-h-64 overflow-y-auto">+ {#each intervalOptions as option}+ <Select.Item value={option.value}>{option.label}</Select.Item>+ {/each}+ </Select.Content>+ </Select.Root>+ </div>+ <div class="space-y-2">+ <Label for="monitor-timeout">Timeout (seconds)</Label>+ <Input+ id="monitor-timeout"+ type="number"+ min="1"+ max="120"+ bind:value={timeoutSeconds}+ disabled={loading}+ />+ </div>+ <div class="space-y-2">+ <Label for="monitor-threshold">Failures before down</Label>+ <Input+ id="monitor-threshold"+ type="number"+ min="1"+ max="10"+ bind:value={failureThreshold}+ disabled={loading}+ />+ </div>+ </div>++ {#if checkType === 'http'}+ <!-- Postman-style request bar: method and URL joined -->+ <div class="space-y-2">+ <Label>Request</Label>+ <div class="flex">+ <Select.Root type="single" bind:value={httpMethod} disabled={loading}>+ <Select.Trigger+ class="w-[110px] rounded-r-none border-r-0 font-mono text-xs font-semibold"+ >+ {httpMethod}+ </Select.Trigger>+ <Select.Content>+ {#each methodOptions as method}+ <Select.Item value={method}>{method}</Select.Item>+ {/each}+ </Select.Content>+ </Select.Root>+ <Input+ bind:value={httpUrl}+ placeholder="https://example.com/health"+ class="flex-1 rounded-l-none font-mono text-sm"+ disabled={loading}+ />+ </div>+ </div>++ <Tabs.Root bind:value={requestTab}>+ <Tabs.List+ class="flex h-auto w-full items-center justify-start gap-5 rounded-none border-b bg-transparent p-0"+ >+ <Tabs.Trigger value="headers" class={tabTriggerClass}>+ Headers{headerCount > 0 ? ` (${headerCount})` : ''}+ </Tabs.Trigger>+ <Tabs.Trigger value="auth" class={tabTriggerClass}>+ Auth{authType !== 'none' ? ' •' : ''}+ </Tabs.Trigger>+ <Tabs.Trigger value="body" class={tabTriggerClass}>Body</Tabs.Trigger>+ <Tabs.Trigger value="expected" class={tabTriggerClass}>Expected results</Tabs.Trigger>+ </Tabs.List>+ </Tabs.Root>++ {#if requestTab === 'headers'}+ <KeyValueRows+ bind:rows={headerRows}+ keyPlaceholder="Header name"+ valuePlaceholder="Value"+ addLabel="Add Header"+ disabled={loading}+ />+ {:else if requestTab === 'auth'}+ <div class="space-y-3">+ <Select.Root type="single" bind:value={authType} disabled={loading}>+ <Select.Trigger class="w-[220px]">{authLabel}</Select.Trigger>+ <Select.Content>+ {#each authOptions as option}+ <Select.Item value={option.value}>{option.label}</Select.Item>+ {/each}+ </Select.Content>+ </Select.Root>+ {#if authType === 'basic'}+ <div class="grid grid-cols-2 gap-2">+ <Input bind:value={authUsername} placeholder="Username" disabled={loading} />+ <Input+ bind:value={authPassword}+ type="password"+ placeholder="Password"+ disabled={loading}+ />+ </div>+ {:else if authType === 'bearer'}+ <Input+ bind:value={authToken}+ type="password"+ placeholder="Token"+ disabled={loading}+ />+ {:else if authType === 'header'}+ <div class="grid grid-cols-2 gap-2">+ <Input bind:value={authHeaderName} placeholder="X-Api-Key" disabled={loading} />+ <Input+ bind:value={authHeaderValue}+ type="password"+ placeholder="Value"+ disabled={loading}+ />+ </div>+ {:else}+ <p class="text-sm text-muted-foreground">+ The request is sent without authentication.+ </p>+ {/if}+ </div>+ {:else if requestTab === 'body'}+ {#if methodHasBody}+ <div class="space-y-2">+ <textarea+ bind:value={httpBody}+ spellcheck="false"+ rows="6"+ placeholder={'{\n "example": true\n}'}+ class="w-full resize-y rounded-md border border-input bg-transparent p-3 font-mono text-xs shadow-xs focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none"+ disabled={loading}+ ></textarea>+ <div class="flex items-center gap-2">+ <Label for="monitor-content-type" class="text-xs text-muted-foreground"+ >Content-Type</Label+ >+ <Input+ id="monitor-content-type"+ bind:value={httpBodyContentType}+ class="w-[260px] font-mono text-xs"+ disabled={loading}+ />+ </div>+ </div>+ {:else}+ <p class="text-sm text-muted-foreground">+ {httpMethod} requests are sent without a body. Switch the method to POST, PUT, PATCH,+ or DELETE to add one.+ </p>+ {/if}+ {:else}+ <div class="space-y-4">+ <div class="grid grid-cols-2 gap-3">+ <div class="space-y-1">+ <Label for="monitor-status-codes" class="text-xs text-muted-foreground"+ >Status codes (default: any < 400)</Label+ >+ <Input+ id="monitor-status-codes"+ bind:value={expectedStatusCodes}+ placeholder="200, 204"+ disabled={loading}+ />+ </div>+ <div class="space-y-1">+ <Label for="monitor-max-time" class="text-xs text-muted-foreground"+ >Max response time (ms)</Label+ >+ <Input+ id="monitor-max-time"+ type="number"+ min="0"+ bind:value={maxResponseTimeMs}+ placeholder="No limit"+ disabled={loading}+ />+ </div>+ <div class="space-y-1">+ <Label for="monitor-body-contains" class="text-xs text-muted-foreground"+ >Body contains</Label+ >+ <Input id="monitor-body-contains" bind:value={bodyContains} disabled={loading} />+ </div>+ <div class="space-y-1">+ <Label for="monitor-body-regex" class="text-xs text-muted-foreground"+ >Body matches regex</Label+ >+ <Input id="monitor-body-regex" bind:value={bodyRegex} disabled={loading} />+ </div>+ <div class="space-y-1">+ <Label for="monitor-tls-days" class="text-xs text-muted-foreground"+ >Min TLS days remaining</Label+ >+ <Input+ id="monitor-tls-days"+ type="number"+ min="0"+ bind:value={tlsMinDaysRemaining}+ placeholder="Off"+ disabled={loading}+ />+ </div>+ </div>+ <div class="flex flex-wrap gap-6">+ <label class="flex cursor-pointer items-center gap-2 text-sm">+ <Checkbox+ checked={followRedirects}+ onCheckedChange={(checked) => (followRedirects = checked === true)}+ disabled={loading}+ />+ Follow redirects+ </label>+ <label class="flex cursor-pointer items-center gap-2 text-sm">+ <Checkbox+ checked={skipTlsVerify}+ onCheckedChange={(checked) => (skipTlsVerify = checked === true)}+ disabled={loading}+ />+ Skip TLS verification+ </label>+ </div>+ </div>+ {/if}+ {:else if checkType === 'tcp'}+ <div class="space-y-2">+ <Label>Target</Label>+ <div class="flex">+ <span+ class="inline-flex items-center rounded-l-md border border-r-0 border-input px-3 font-mono text-xs font-semibold text-muted-foreground"+ >+ TCP+ </span>+ <Input+ id="monitor-host"+ bind:value={tcpHost}+ placeholder="db.example.com"+ class="flex-1 rounded-none font-mono text-sm"+ disabled={loading}+ />+ <Input+ id="monitor-port"+ type="number"+ min="1"+ max="65535"+ bind:value={tcpPort}+ placeholder="5432"+ class="w-[110px] rounded-l-none border-l-0 font-mono text-sm"+ disabled={loading}+ />+ </div>+ </div>+ <div class="grid grid-cols-2 gap-3">+ <div class="space-y-1">+ <Label for="monitor-send" class="text-xs text-muted-foreground"+ >Send payload (optional)</Label+ >+ <Input id="monitor-send" bind:value={tcpSendPayload} disabled={loading} />+ </div>+ <div class="space-y-1">+ <Label for="monitor-expect" class="text-xs text-muted-foreground"+ >Expect response containing</Label+ >+ <Input id="monitor-expect" bind:value={tcpExpectContains} disabled={loading} />+ </div>+ <div class="space-y-1">+ <Label for="monitor-tcp-tls-days" class="text-xs text-muted-foreground"+ >Min TLS days remaining</Label+ >+ <Input+ id="monitor-tcp-tls-days"+ type="number"+ min="0"+ bind:value={tcpTlsMinDaysRemaining}+ placeholder="Off"+ disabled={loading}+ />+ </div>+ </div>+ <label class="flex cursor-pointer items-center gap-2 text-sm">+ <Checkbox+ checked={tcpUseTls}+ onCheckedChange={(checked) => (tcpUseTls = checked === true)}+ disabled={loading}+ />+ Use TLS+ </label>+ {:else}+ <div class="space-y-2">+ <Label>Playwright test script</Label>+ <CodeEditor bind:value={browserScript} readOnly={loading} minHeight="300px" />+ <p class="text-xs text-muted-foreground">+ A full @playwright/test spec. It runs in headless Chromium on the server (the :browser+ image) or on a connected runner.+ </p>+ </div>+ <div class="space-y-2">+ <Label>Environment variables (optional)</Label>+ <KeyValueRows+ bind:rows={envRows}+ keyPlaceholder="NAME"+ valuePlaceholder="Value"+ addLabel="Add Variable"+ disabled={loading}+ />+ </div>+ {/if}+ </form>++ <div class="flex justify-end gap-2 border-t px-6 py-4">+ <Button variant="outline" onclick={() => handleOpenChange(false)} disabled={loading}>+ Cancel+ </Button>+ <Button variant={isEditing ? 'default' : 'success'} onclick={handleSubmit} disabled={loading}>+ {#if isEditing}+ <Check class="mr-2 h-4 w-4" />+ {loading ? 'Updating...' : 'Update Monitor'}+ {:else}+ <Plus class="mr-2 h-4 w-4" />+ {loading ? 'Creating...' : 'New Monitor'}+ {/if}+ </Button>+ </div>+ </Sheet.Content>+</Sheet.Root>diff --git a/frontend/src/routes/monitors/status-pages-tab.svelte b/frontend/src/routes/monitors/status-pages-tab.sveltenew file mode 100644index 00000000..103bdeed--- /dev/null+++ b/frontend/src/routes/monitors/status-pages-tab.svelte@@ -0,0 +1,447 @@+<script lang="ts">+ import { api } from '$lib/api';+ import * as AlertDialog from '$lib/components/ui/alert-dialog';+ import * as Table from '$lib/components/ui/table';+ import { TracewayTableHeader } from '$lib/components/ui/traceway-table-header';+ import EmptyState from '$lib/components/traceway/empty-state.svelte';+ import { Button } from '$lib/components/ui/button';+ import { Input } from '$lib/components/ui/input';+ import { Label } from '$lib/components/ui/label';+ import { Checkbox } from '$lib/components/ui/checkbox';+ import { ErrorAlert } from '$lib/components/ui/error-alert';+ import { LoadingCircle } from '$lib/components/ui/loading-circle';+ import { projectsState } from '$lib/state/projects.svelte';+ import { authState } from '$lib/state/auth.svelte';+ import type { SyntheticCheck } from '$lib/state/monitors.svelte';+ import { Check, ExternalLink, Globe, ImageUp, Pencil, Plus, Trash2 } from '@lucide/svelte';+ import { toast } from 'svelte-sonner';++ interface StatusPage {+ id: number;+ organizationId: number;+ slug: string;+ name: string;+ isPublic: boolean;+ checkIds: number[];+ description: string;+ logoKey: string;+ customDomain: string;+ }++ const organizationId = $derived(projectsState.currentProject?.organizationId ?? null);++ let pages = $state<StatusPage[]>([]);+ let checks = $state<SyntheticCheck[]>([]);+ let loading = $state(true);++ let dialogOpen = $state(false);+ let editing = $state<StatusPage | null>(null);+ let saving = $state(false);+ let dialogError = $state('');+ let pageName = $state('');+ let pageSlug = $state('');+ let pagePublic = $state(true);+ let pageDescription = $state('');+ let pageCustomDomain = $state('');+ let selectedCheckIds = $state<number[]>([]);+ let logoFile = $state<File | null>(null);+ let logoInput = $state<HTMLInputElement | null>(null);++ let deleteTarget = $state<StatusPage | null>(null);+ let deleting = $state(false);++ async function loadAll() {+ if (!organizationId) return;+ loading = true;+ try {+ const [pagesResponse, checksResponse] = await Promise.all([+ api.get(`/organizations/${organizationId}/status-pages`, { skipProjectId: true }),+ api.get('/synthetics/checks', { projectId: projectsState.currentProjectId ?? undefined })+ ]);+ pages = pagesResponse.statusPages || [];+ checks = checksResponse.checks || [];+ } catch (e) {+ console.error('Failed to load status pages:', e);+ } finally {+ loading = false;+ }+ }++ $effect(() => {+ if (organizationId) {+ loadAll();+ }+ });++ export function openCreate() {+ editing = null;+ pageName = '';+ pageSlug = '';+ pagePublic = true;+ pageDescription = '';+ pageCustomDomain = '';+ selectedCheckIds = [];+ logoFile = null;+ dialogError = '';+ dialogOpen = true;+ }++ function openEdit(page: StatusPage) {+ editing = page;+ pageName = page.name;+ pageSlug = page.slug;+ pagePublic = page.isPublic;+ pageDescription = page.description || '';+ pageCustomDomain = page.customDomain || '';+ selectedCheckIds = [...(page.checkIds || [])];+ logoFile = null;+ dialogError = '';+ dialogOpen = true;+ }++ function toggleCheck(checkId: number, checked: boolean) {+ if (checked) {+ selectedCheckIds = [...selectedCheckIds, checkId];+ } else {+ selectedCheckIds = selectedCheckIds.filter((id) => id !== checkId);+ }+ }++ async function uploadLogo(pageId: number) {+ if (!logoFile) return;+ const body = await logoFile.arrayBuffer();+ const response = await fetch(+ `/api/organizations/${organizationId}/status-pages/${pageId}/logo`,+ {+ method: 'POST',+ headers: { Authorization: `Bearer ${authState.token}` },+ body+ }+ );+ if (!response.ok) {+ const data = await response.json().catch(() => ({}));+ throw new Error(data.error || 'Failed to upload the logo');+ }+ }++ async function savePage() {+ saving = true;+ dialogError = '';+ try {+ const payload = {+ name: pageName.trim(),+ slug: pageSlug.trim().toLowerCase(),+ isPublic: pagePublic,+ checkIds: selectedCheckIds,+ description: pageDescription.trim(),+ customDomain: pageCustomDomain.trim().toLowerCase()+ };+ let savedId: number;+ if (editing) {+ const response = await api.put(+ `/organizations/${organizationId}/status-pages/${editing.id}`,+ payload,+ { skipProjectId: true }+ );+ savedId = response.id;+ } else {+ const response = await api.post(`/organizations/${organizationId}/status-pages`, payload, {+ skipProjectId: true+ });+ savedId = response.id;+ }+ if (logoFile) {+ await uploadLogo(savedId);+ }+ toast.success(+ editing ? 'Successfully updated the Status Page' : 'Successfully created the Status Page',+ { position: 'top-center' }+ );+ dialogOpen = false;+ loadAll();+ } catch (e) {+ dialogError = e instanceof Error ? e.message : 'Failed to save the status page';+ } finally {+ saving = false;+ }+ }++ async function deletePage() {+ if (!deleteTarget) return;+ deleting = true;+ try {+ await api.delete(`/organizations/${organizationId}/status-pages/${deleteTarget.id}`, {+ skipProjectId: true+ });+ toast.success('Successfully deleted the Status Page', { position: 'top-center' });+ deleteTarget = null;+ loadAll();+ } catch (e: any) {+ if (e?.status !== 403) {+ toast.error(e.message || 'Failed to delete the status page', { position: 'top-center' });+ }+ } finally {+ deleting = false;+ }+ }+</script>++{#if loading}+ <div class="flex h-48 items-center justify-center">+ <LoadingCircle size="xlg" />+ </div>+{:else if pages.length === 0}+ <EmptyState+ message="No status pages yet. Publish the uptime of your monitors on a public page."+ actionLabel="Create your first Status Page"+ onAction={openCreate}+ />+{:else}+ <div class="overflow-hidden rounded-md border">+ <Table.Root>+ <Table.Header>+ <Table.Row>+ <TracewayTableHeader label="Name" />+ <TracewayTableHeader label="Public URL" class="w-[220px]" />+ <TracewayTableHeader label="Custom domain" class="w-[200px]" />+ <TracewayTableHeader label="Monitors" class="w-[100px]" />+ <TracewayTableHeader label="Visibility" class="w-[110px]" />+ <TracewayTableHeader label="" align="right" class="w-[90px]" />+ </Table.Row>+ </Table.Header>+ <Table.Body>+ {#each pages as page}+ <Table.Row class="group hover:bg-muted/50">+ <Table.Cell class="font-medium">+ {page.name}+ {#if page.description}+ <div class="mt-0.5 text-xs font-normal text-muted-foreground">+ {page.description}+ </div>+ {/if}+ </Table.Cell>+ <Table.Cell>+ <a+ class="inline-flex items-center gap-1 font-mono text-xs text-primary underline-offset-2 hover:underline"+ href={`/status/${page.slug}`}+ target="_blank"+ rel="noopener"+ >+ /status/{page.slug}+ <ExternalLink class="h-3 w-3" />+ </a>+ </Table.Cell>+ <Table.Cell class="font-mono text-xs text-muted-foreground">+ {page.customDomain || '—'}+ </Table.Cell>+ <Table.Cell class="text-sm text-muted-foreground tabular-nums">+ {(page.checkIds || []).length}+ </Table.Cell>+ <Table.Cell>+ {#if page.isPublic}+ <span+ class="inline-flex items-center gap-1 rounded-full bg-green-500/15 px-2 py-0.5 text-xs font-medium text-green-600 dark:text-green-400"+ >+ <Globe class="h-3 w-3" />+ Public+ </span>+ {:else}+ <span+ class="inline-flex items-center rounded-full bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground"+ >+ Private+ </span>+ {/if}+ </Table.Cell>+ <Table.Cell class="text-right">+ <div class="flex justify-end gap-1">+ <Button variant="ghost" size="icon-sm" onclick={() => openEdit(page)} title="Edit">+ <Pencil class="h-4 w-4" />+ </Button>+ <Button+ variant="ghost"+ size="icon-sm"+ onclick={() => (deleteTarget = page)}+ title="Delete"+ >+ <Trash2 class="h-4 w-4" />+ </Button>+ </div>+ </Table.Cell>+ </Table.Row>+ {/each}+ </Table.Body>+ </Table.Root>+ </div>+{/if}++<AlertDialog.Root open={dialogOpen} onOpenChange={(v) => (dialogOpen = v)}>+ <AlertDialog.Content+ class="max-h-[90vh] overflow-y-auto sm:max-w-xl"+ interactOutsideBehavior={saving ? 'ignore' : 'close'}+ >+ <AlertDialog.Header>+ <AlertDialog.Title>{editing ? 'Edit Status Page' : 'New Status Page'}</AlertDialog.Title>+ <AlertDialog.Description>+ Pick the monitors to show, the public URL, and the branding.+ </AlertDialog.Description>+ </AlertDialog.Header>++ <form+ onsubmit={(e) => {+ e.preventDefault();+ savePage();+ }}+ class="space-y-4"+ >+ <ErrorAlert error={dialogError} />+ <div class="grid grid-cols-2 gap-4">+ <div class="space-y-2">+ <Label for="status-page-name">Title</Label>+ <Input+ id="status-page-name"+ bind:value={pageName}+ placeholder="Acme Status"+ disabled={saving}+ />+ </div>+ <div class="space-y-2">+ <Label for="status-page-slug">Slug</Label>+ <div class="flex items-center gap-2">+ <span class="text-sm text-muted-foreground">/status/</span>+ <Input+ id="status-page-slug"+ bind:value={pageSlug}+ placeholder="acme"+ class="flex-1"+ disabled={saving}+ />+ </div>+ </div>+ </div>+ <div class="space-y-2">+ <Label for="status-page-description">Description (optional)</Label>+ <Input+ id="status-page-description"+ bind:value={pageDescription}+ placeholder="Live availability of Acme services"+ disabled={saving}+ />+ </div>+ <div class="space-y-2">+ <Label>Logo (optional, PNG or JPEG)</Label>+ <div class="flex items-center gap-3">+ {#if editing?.logoKey && !logoFile && editing.isPublic}+ <!-- The preview uses the public logo route, which 404s for+ private pages, so it only renders for public ones. -->+ <img+ src={`/api/status/${editing.slug}/logo`}+ alt="Current logo"+ class="h-9 w-9 rounded border object-contain"+ />+ {/if}+ <input+ bind:this={logoInput}+ type="file"+ accept="image/png,image/jpeg"+ class="hidden"+ onchange={(e) => (logoFile = (e.currentTarget as HTMLInputElement).files?.[0] ?? null)}+ />+ <Button+ variant="outline"+ size="sm"+ type="button"+ onclick={() => logoInput?.click()}+ disabled={saving}+ >+ <ImageUp class="mr-1.5 h-4 w-4" />+ {logoFile ? logoFile.name : editing?.logoKey ? 'Replace logo' : 'Upload logo'}+ </Button>+ </div>+ </div>+ <div class="space-y-2">+ <Label for="status-page-domain">Custom domain (optional)</Label>+ <Input+ id="status-page-domain"+ bind:value={pageCustomDomain}+ placeholder="status.acme.com"+ class="font-mono text-sm"+ disabled={saving}+ />+ <p class="text-xs text-muted-foreground">+ Point a CNAME at this Traceway instance and terminate TLS for it at your reverse proxy.+ Visitors landing on that host are routed to this status page.+ </p>+ </div>+ <label class="flex cursor-pointer items-center gap-2 text-sm">+ <Checkbox+ checked={pagePublic}+ onCheckedChange={(checked) => (pagePublic = checked === true)}+ disabled={saving}+ />+ Publicly accessible+ </label>+ <div class="space-y-2">+ <Label>Monitors (from this project)</Label>+ {#if checks.length === 0}+ <p class="text-sm text-muted-foreground">Create a monitor first.</p>+ {:else}+ <div class="max-h-48 space-y-1 overflow-y-auto rounded-md border p-2">+ {#each checks as check}+ <label+ class="flex cursor-pointer items-center gap-2 rounded p-1.5 text-sm hover:bg-muted/50"+ >+ <Checkbox+ checked={selectedCheckIds.includes(check.id)}+ onCheckedChange={(checked) => toggleCheck(check.id, checked === true)}+ disabled={saving}+ />+ {check.name}+ <span class="font-mono text-xs text-muted-foreground uppercase"+ >{check.checkType}</span+ >+ </label>+ {/each}+ </div>+ {#if editing}+ <p class="text-xs text-muted-foreground">+ Monitors from other projects stay selected even though only this project's monitors+ are listed here.+ </p>+ {/if}+ {/if}+ </div>+ </form>++ <AlertDialog.Footer>+ <AlertDialog.Cancel disabled={saving}>Cancel</AlertDialog.Cancel>+ <Button variant={editing ? 'default' : 'success'} onclick={savePage} disabled={saving}>+ {#if editing}+ <Check class="mr-2 h-4 w-4" />+ {saving ? 'Updating...' : 'Update Status Page'}+ {:else}+ <Plus class="mr-2 h-4 w-4" />+ {saving ? 'Creating...' : 'New Status Page'}+ {/if}+ </Button>+ </AlertDialog.Footer>+ </AlertDialog.Content>+</AlertDialog.Root>++<AlertDialog.Root open={deleteTarget !== null} onOpenChange={(v) => !v && (deleteTarget = null)}>+ <AlertDialog.Content interactOutsideBehavior={deleting ? 'ignore' : 'close'}>+ <AlertDialog.Header>+ <AlertDialog.Title>Delete Status Page</AlertDialog.Title>+ <AlertDialog.Description>+ "{deleteTarget?.name}" at /status/{deleteTarget?.slug} will stop working immediately.+ </AlertDialog.Description>+ </AlertDialog.Header>+ <AlertDialog.Footer>+ <AlertDialog.Cancel disabled={deleting}>Cancel</AlertDialog.Cancel>+ <Button variant="destructive" onclick={deletePage} disabled={deleting}>+ <Trash2 class="mr-2 h-4 w-4" />+ {deleting ? 'Deleting...' : 'Delete Status Page'}+ </Button>+ </AlertDialog.Footer>+ </AlertDialog.Content>+</AlertDialog.Root>diff --git a/frontend/src/routes/notifications/rule-dialog.svelte b/frontend/src/routes/notifications/rule-dialog.svelteindex 89faf553..9f1a1325 100644--- a/frontend/src/routes/notifications/rule-dialog.svelte+++ b/frontend/src/routes/notifications/rule-dialog.svelte@@ -119,6 +119,8 @@'Fires when an AI conversation matches a flagged content term. Uses the built-in profanity list plus custom terms from the project’s AI settings; optionally narrow to specific terms below.',error_regression:'Fires when an error that was previously archived (resolved) occurs again.',+ check_down:+ 'Fires when a monitor transitions to down (after its failure threshold), and sends a recovery notice when it comes back up. Applies to every monitor in this project.',error_rate_threshold:'Fires when the percentage of requests returning 5xx across all endpoints exceeds the threshold within the lookback window.',error_count_threshold:diff --git a/frontend/src/routes/notifications/rule-types.ts b/frontend/src/routes/notifications/rule-types.tsindex 936a6a45..ef17417b 100644--- a/frontend/src/routes/notifications/rule-types.ts+++ b/frontend/src/routes/notifications/rule-types.ts@@ -17,7 +17,8 @@ export const ruleTypeOptions = [{ value: 'throughput_drop', label: 'Throughput Drop' },{ value: 'ai_trace_cost', label: 'AI Trace Cost' },{ value: 'ai_conversation_cost', label: 'AI Conversation Cost' },- { value: 'ai_flagged_content', label: 'AI Flagged Content' }+ { value: 'ai_flagged_content', label: 'AI Flagged Content' },+ { value: 'check_down', label: 'Monitor Down' }];export const ruleTypeLabels: Record<string, string> = Object.fromEntries(diff --git a/frontend/src/routes/status/[slug]/+page.svelte b/frontend/src/routes/status/[slug]/+page.sveltenew file mode 100644index 00000000..b1889664--- /dev/null+++ b/frontend/src/routes/status/[slug]/+page.svelte@@ -0,0 +1,545 @@+<script lang="ts">+ import { onMount, onDestroy } from 'svelte';++ interface StatusDay {+ bucket: string;+ total: number;+ up: number;+ missed: number;+ }++ interface StatusIncident {+ startedAt: string;+ resolvedAt: string | null;+ }++ interface StatusCheck {+ name: string;+ checkType: string;+ status: 'up' | 'down' | 'unknown';+ uptimePct: number | null;+ days: StatusDay[];+ incidents: StatusIncident[];+ }++ interface StatusView {+ name: string;+ description: string;+ hasLogo: boolean;+ checks: StatusCheck[];+ generatedAt: string;+ }++ let { data }: { data: { slug: string } } = $props();++ type LoadState = 'loading' | 'ready' | 'notFound' | 'error';+ let loadState = $state<LoadState>('loading');+ let view = $state<StatusView | null>(null);+ let refreshTimer: ReturnType<typeof setInterval> | null = null;++ const DAYS = 90;++ type DayCell = {+ date: Date;+ state: 'operational' | 'degraded' | 'down' | 'empty';+ uptimePct: number | null;+ };++ // Deliberately a raw fetch: the api client's 401 handling would bounce+ // anonymous visitors to /login, and this page must work logged out.+ async function loadStatus() {+ try {+ const response = await fetch(`/api/status/${encodeURIComponent(data.slug)}`);+ if (response.status === 404) {+ loadState = 'notFound';+ return;+ }+ if (!response.ok) {+ throw new Error(`status ${response.status}`);+ }+ view = await response.json();+ loadState = 'ready';+ } catch {+ if (loadState !== 'ready') {+ loadState = 'error';+ }+ }+ }++ const allUp = $derived(view !== null && view.checks.every((c) => c.status !== 'down'));++ function dayKey(date: Date): string {+ return `${date.getUTCFullYear()}-${date.getUTCMonth()}-${date.getUTCDate()}`;+ }++ // A fixed 90-cell grid: days without data render as empty cells instead of+ // the bar silently shrinking.+ function buildCells(check: StatusCheck): DayCell[] {+ const byDay = new Map<string, StatusDay>();+ for (const day of check.days) {+ byDay.set(dayKey(new Date(day.bucket)), day);+ }+ const cells: DayCell[] = [];+ const now = new Date();+ for (let i = DAYS - 1; i >= 0; i--) {+ const date = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));+ date.setUTCDate(date.getUTCDate() - i);+ const day = byDay.get(dayKey(date));+ const measured = day ? day.total - day.missed : 0;+ if (!day || measured === 0) {+ cells.push({ date, state: 'empty', uptimePct: null });+ continue;+ }+ const pct = (day.up / measured) * 100;+ cells.push({+ date,+ state: pct >= 99.5 ? 'operational' : day.up === 0 ? 'down' : 'degraded',+ uptimePct: pct+ });+ }+ return cells;+ }++ const cellColors: Record<DayCell['state'], string> = {+ operational: '#22c55e',+ degraded: '#f5a623',+ down: '#e5484d',+ empty: '#e4e7ec'+ };++ const stateDescriptions: Record<DayCell['state'], string> = {+ operational: 'Operational',+ degraded: 'Partial outage',+ down: 'Major outage',+ empty: 'No data'+ };++ function cellTitle(cell: DayCell): string {+ const date = cell.date.toLocaleDateString(undefined, {+ month: 'short',+ day: 'numeric',+ year: 'numeric'+ });+ if (cell.state === 'empty') return `${date} — no data`;+ return `${date} — ${stateDescriptions[cell.state]} (${cell.uptimePct?.toFixed(2)}% uptime)`;+ }++ function checkStatusLabel(check: StatusCheck): { label: string; color: string } {+ if (check.status === 'up') return { label: 'Operational', color: '#16a34a' };+ if (check.status === 'down') return { label: 'Major outage', color: '#e5484d' };+ return { label: 'No recent data', color: '#98a2b3' };+ }++ function formatIncident(incident: StatusIncident): string {+ const started = new Date(incident.startedAt).toLocaleString(undefined, {+ month: 'short',+ day: 'numeric',+ hour: '2-digit',+ minute: '2-digit'+ });+ if (!incident.resolvedAt) return `${started} — ongoing`;+ const minutes = Math.max(+ 1,+ Math.round(+ (new Date(incident.resolvedAt).getTime() - new Date(incident.startedAt).getTime()) / 60000+ )+ );+ return `${started} — resolved after ${minutes} min`;+ }++ // The status page is a standalone light design; anonymous visitors default+ // to the app's dark theme class, which would restyle headings underneath+ // the scoped styles. Force light here and restore on leave.+ let hadDarkClass = false;+ onMount(() => {+ hadDarkClass = document.documentElement.classList.contains('dark');+ document.documentElement.classList.remove('dark');+ document.documentElement.style.colorScheme = 'light';+ loadStatus();+ refreshTimer = setInterval(loadStatus, 60000);+ });++ onDestroy(() => {+ if (refreshTimer) clearInterval(refreshTimer);+ if (hadDarkClass) {+ document.documentElement.classList.add('dark');+ document.documentElement.style.colorScheme = 'dark';+ }+ });+</script>++<svelte:head>+ <title>{view ? `${view.name} status` : 'Status'}</title>+</svelte:head>++<!-- Deliberately a standalone light design, independent of the app theme. -->+<div class="status-page">+ <div class="status-container">+ {#if loadState === 'loading'}+ <div class="status-center">+ <div class="status-spinner"></div>+ </div>+ {:else if loadState === 'notFound'}+ <div class="status-center">+ <h1>Status page not found</h1>+ <p>This status page does not exist or is not public.</p>+ </div>+ {:else if loadState === 'error'}+ <div class="status-center">+ <h1>Something went wrong</h1>+ <p>Could not load the status page. Try again shortly.</p>+ </div>+ {:else if view}+ <header class="status-header">+ <div class="status-brand">+ {#if view.hasLogo}+ <img src={`/api/status/${encodeURIComponent(data.slug)}/logo`} alt="" />+ {/if}+ <div>+ <h1>{view.name}</h1>+ {#if view.description}+ <p>{view.description}</p>+ {/if}+ </div>+ </div>+ </header>++ <div class="status-banner" class:degraded={!allUp}>+ {allUp ? 'All systems operational' : 'Some systems are experiencing issues'}+ </div>++ <div class="status-cards">+ {#each view.checks as check}+ {@const cells = buildCells(check)}+ {@const chip = checkStatusLabel(check)}+ <section class="status-card">+ <div class="status-card-head">+ <span class="status-card-name">{check.name}</span>+ <span class="status-chip" style="color: {chip.color}">+ <span class="status-dot" style="background: {chip.color}"></span>+ {chip.label}+ </span>+ </div>+ <div class="status-uptime-row">+ <span+ >{check.uptimePct === null+ ? 'No data yet'+ : `${check.uptimePct.toFixed(2)}% uptime in the last 90 days`}</span+ >+ </div>+ <div class="status-bars">+ {#each cells as cell, i}+ <span+ class="status-bar {i < 30 ? 'band-oldest' : i < 60 ? 'band-mid' : ''}"+ style="background: {cellColors[cell.state]}"+ title={cellTitle(cell)}+ ></span>+ {/each}+ </div>+ <div class="status-bar-labels">+ <span class="label-90">90 days ago</span>+ <span class="label-60">60 days ago</span>+ <span class="label-30">30 days ago</span>+ <span>Today</span>+ </div>+ {#if check.incidents.length > 0}+ <details class="status-incidents">+ <summary>+ {check.incidents.length} incident{check.incidents.length === 1 ? '' : 's'} in the last+ 90 days+ </summary>+ <ul>+ {#each check.incidents as incident}+ <li>{formatIncident(incident)}</li>+ {/each}+ </ul>+ </details>+ {/if}+ </section>+ {/each}+ </div>++ <div class="status-legend">+ <span><i style="background: #22c55e"></i> Operational</span>+ <span><i style="background: #f5a623"></i> Partial outage</span>+ <span><i style="background: #e5484d"></i> Major outage</span>+ <span><i style="background: #e4e7ec"></i> No data</span>+ </div>++ <footer class="status-footer">+ Updated {new Date(view.generatedAt).toLocaleTimeString()} · Powered by Traceway+ </footer>+ {/if}+ </div>+</div>++<style>+ .status-page {+ min-height: 100vh;+ background: #f7f8fa;+ color: #101828;+ font-family:+ -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;+ }++ .status-container {+ max-width: 880px;+ margin: 0 auto;+ padding: 56px 24px 40px;+ }++ .status-center {+ padding: 120px 0;+ text-align: center;+ }++ .status-center h1 {+ font-size: 24px;+ font-weight: 600;+ margin: 0 0 8px;+ color: #101828;+ }++ .status-center p {+ color: #667085;+ margin: 0;+ }++ .status-spinner {+ width: 28px;+ height: 28px;+ margin: 0 auto;+ border: 3px solid #e4e7ec;+ border-top-color: #16a34a;+ border-radius: 50%;+ animation: spin 0.8s linear infinite;+ }++ @keyframes spin {+ to {+ transform: rotate(360deg);+ }+ }++ .status-header {+ margin-bottom: 20px;+ }++ .status-brand {+ display: flex;+ align-items: center;+ gap: 16px;+ }++ .status-brand img {+ width: 48px;+ height: 48px;+ border-radius: 10px;+ object-fit: contain;+ background: #fff;+ border: 1px solid #e4e7ec;+ padding: 4px;+ }++ .status-brand h1 {+ font-size: 26px;+ font-weight: 700;+ margin: 0;+ letter-spacing: -0.02em;+ color: #101828;+ }++ .status-brand p {+ margin: 2px 0 0;+ color: #667085;+ font-size: 14px;+ }++ .status-banner {+ background: #16a34a;+ color: #fff;+ font-size: 16px;+ font-weight: 600;+ padding: 16px 20px;+ border-radius: 10px;+ margin-bottom: 24px;+ }++ .status-banner.degraded {+ background: #e5484d;+ }++ .status-cards {+ display: flex;+ flex-direction: column;+ gap: 16px;+ }++ .status-card {+ background: #fff;+ border: 1px solid #e4e7ec;+ border-radius: 12px;+ padding: 20px;+ box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);+ }++ .status-card-head {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 12px;+ }++ .status-card-name {+ font-size: 15px;+ font-weight: 600;+ }++ .status-chip {+ display: inline-flex;+ align-items: center;+ gap: 6px;+ font-size: 13px;+ font-weight: 600;+ }++ .status-dot {+ width: 8px;+ height: 8px;+ border-radius: 50%;+ }++ .status-uptime-row {+ margin-top: 2px;+ font-size: 12px;+ color: #667085;+ }++ .status-bars {+ display: flex;+ gap: 3px;+ margin-top: 12px;+ }++ .status-bar {+ flex: 1;+ height: 34px;+ min-width: 3px;+ border-radius: 3px;+ transition: transform 0.1s ease;+ }++ .status-bar:hover {+ transform: scaleY(1.15);+ }++ .status-bar-labels {+ display: flex;+ justify-content: space-between;+ margin-top: 6px;+ font-size: 11px;+ color: #98a2b3;+ }++ .label-60,+ .label-30 {+ display: none;+ }++ /* Narrow screens can't fit 90 bars (3px bar + 3px gap each), so show a+ shorter recent window instead of overflowing the viewport. */+ @media (max-width: 760px) {+ .status-bar.band-oldest {+ display: none;+ }++ .label-90 {+ display: none;+ }++ .label-60 {+ display: inline;+ }+ }++ @media (max-width: 520px) {+ .status-bar.band-mid {+ display: none;+ }++ .label-60 {+ display: none;+ }++ .label-30 {+ display: inline;+ }+ }++ @media (max-width: 640px) {+ .status-container {+ padding: 32px 16px 32px;+ }++ .status-brand h1 {+ font-size: 22px;+ }++ .status-banner {+ font-size: 14px;+ padding: 14px 16px;+ }++ .status-card {+ padding: 16px;+ }++ .status-card-head {+ flex-wrap: wrap;+ }+ }++ .status-incidents {+ margin-top: 12px;+ font-size: 12px;+ color: #667085;+ }++ .status-incidents summary {+ cursor: pointer;+ }++ .status-incidents ul {+ margin: 8px 0 0;+ padding-left: 18px;+ }++ .status-incidents li {+ margin-top: 4px;+ }++ .status-legend {+ display: flex;+ flex-wrap: wrap;+ gap: 16px;+ justify-content: center;+ margin-top: 28px;+ font-size: 12px;+ color: #667085;+ }++ .status-legend i {+ display: inline-block;+ width: 10px;+ height: 10px;+ border-radius: 2px;+ margin-right: 5px;+ }++ .status-footer {+ margin-top: 28px;+ text-align: center;+ font-size: 12px;+ color: #98a2b3;+ }+</style>diff --git a/frontend/src/routes/status/[slug]/+page.ts b/frontend/src/routes/status/[slug]/+page.tsnew file mode 100644index 00000000..10ab108d--- /dev/null+++ b/frontend/src/routes/status/[slug]/+page.ts@@ -0,0 +1,7 @@+import type { PageLoad } from './$types';++export const prerender = false;++export const load: PageLoad = ({ params }) => {+ return { slug: params.slug };+};diff --git a/website/app/cloud/page.tsx b/website/app/cloud/page.tsxindex 2436dbcc..96c63762 100644--- a/website/app/cloud/page.tsx+++ b/website/app/cloud/page.tsx@@ -6,7 +6,6 @@ import { SectionHead } from "@/components/section-head";import { FaqList } from "@/components/faq-list";import { FinalCTA } from "@/components/final-cta";import { AuroraBackground } from "@/components/aurora-background";-import { PricingPlans, PlanComparison } from "@/components/pricing-plans";import { ComplianceStrip } from "@/components/compliance-strip";import { getCalendlyUrl } from "@/lib/calendly";@@ -40,15 +39,30 @@ export default function CloudPage() {</section>{/* Pricing */}- {/* WHITE BAND: pricing + cost comparison render on white */}+ {/* WHITE BAND: pricing + compliance render on white */}<div className="band-light"><section className="wrap md:py-20! py-10!">- <SectionHead align="center" title="Pricing that scales with you" />- <PricingPlans />- </section>-- <section className="wrap pb-20">- <PlanComparison />+ <SectionHead+ align="center"+ eyebrow="Pricing"+ title={+ <>+ Pricing that fits <em>your team.</em>+ </>+ }+ description="We price Traceway Cloud per customer, sized to your actual volume and needs. Start free, and when you're ready, we'll put together a plan with no per-host or per-seat fees."+ />+ <div className="mt-2 flex flex-wrap justify-center gap-3">+ <Link href={getCalendlyUrl()} className="btn btn-accent">+ Talk to us about pricing <ArrowRight className="h-4 w-4" />+ </Link>+ <Link+ href="https://cloud.tracewayapp.com/register"+ className="btn btn-ghost"+ >+ Start Free+ </Link>+ </div></section>{/* Security & compliance */}@@ -89,31 +103,28 @@ export default function CloudPage() {{/* FAQ, includes absorbed from home */}<section className="wrap pt-10 pb-24"><div className="max-w-3xl mx-auto">- <SectionHead- align="center"- eyebrow="FAQ"- title="Cloud & pricing FAQ"- />+ <SectionHead align="center" eyebrow="FAQ" title="Cloud FAQ" /><div className="mt-4"><FaqListitems={[+ {+ q: "How does pricing work?",+ a: "We price per customer. Every plan starts from two simple meters, a monthly allowance for exceptions and one for ingested data (logs, traces, spans, metrics, session replay), and we size both to your workload. Book a call, tell us your volume, and we'll put together a plan. HTTP requests and background task runs are never metered, and there are no per-host or per-seat fees.",+ },{q: "Why is Traceway so cost-effective?",a: (<><p>- Pricing comes down to two simple meters: a fixed monthly- tier for exceptions, and data (logs, traces, spans,- metrics, replay) at a flat $0.25/GB after a generous- included allowance. There are no per-host or per-seat- fees layered on top, and self-hosted Traceway has zero- licensing cost.+ There are no per-host or per-seat fees layered on top of+ your plan, and self-hosted Traceway has zero licensing+ cost.</p><p>Architecturally, Traceway uses ClickHouse columnarstorage that compresses 1 million daily events into ~2-3- GB per month, keeping the per-GB rate low even at high- volume. Everything is in one tool: endpoint performance+ GB per month, keeping costs low even at high volume.+ Everything is in one tool: endpoint performanceanalytics, exception tracking with automatic groupingand ranking, session replay, distributed tracing,metrics, logs, and AI observability, with a single bill@@ -138,23 +149,11 @@ export default function CloudPage() {},{q: "Will my bill ever increase unexpectedly?",- a: "No. Your plan price is fixed, and data is billed at a flat, published per-GB rate with a generous allowance included on every tier. If you approach your data allowance, we notify you in advance so you can decide whether to upgrade or keep going. There are no per-host or per-seat surprises, and we never apply a new rate without telling you first.",+ a: "No. Your pricing is agreed with you up front. If your usage approaches what we agreed, we reach out in advance so you can decide how to proceed. There are no per-host or per-seat surprises, and we never apply a new rate without telling you first.",},{q: "What support do Cloud customers get?",- a: "All Cloud customers on a paid plan can open GitHub issues that are triaged with highest priority by our engineering team. You talk directly to the people who build Traceway, with no help desk routing. Enterprise+ customers also receive a shared Slack channel with direct access to the team. Self-hosted users are welcome to open GitHub issues and participate in community discussions. We actively monitor and respond.",- },- {- q: "How does data billing work?",- a: "Each plan includes an allowance for data ingested, covering your logs, traces, spans, metrics, and session replay (for example, 150 GB on Premium). If you stay within it, you only pay the fixed plan price. Beyond the allowance, ingested data is billed at a flat, published per-GB rate ($0.25/GB, dropping to $0.20/GB on Enterprise) with no per-host or per-seat add-ons. We meter the volume you send us, not your compressed storage, so the rate is predictable, and we warn you before you exceed your allowance.",- },- {- q: "How does pricing work at scale?",- a: "Data is where observability bills usually grow, so that is where Traceway stays lean: a flat $0.25/GB, dropping to $0.20/GB on Enterprise, with no per-host or per-seat fees on top. Your exception plan stays a fixed monthly price. Enterprise+ adds the best volume rate plus a dedicated SRE and a shared Slack channel.",- },- {- q: "What do you charge for, and what is free?",- a: "Two things. First, exceptions, billed as a fixed monthly tier (10k free on Starter, up to 200M on Enterprise). Second, data, meaning your logs, distributed trace spans, custom metrics, and session replay, billed by the gigabyte ingested after a generous per-plan allowance. HTTP requests and background task runs are not metered. For example, on Premium you get 1M exceptions and 150 GB of ingested data included for $24.99/mo, then $0.25 for each additional GB.",+ a: "All Cloud customers on a paid plan can open GitHub issues that are triaged with highest priority by our engineering team. You talk directly to the people who build Traceway, with no help desk routing. Larger plans also include a shared Slack channel with direct access to the team. Self-hosted users are welcome to open GitHub issues and participate in community discussions. We actively monitor and respond.",},{q: "Can I migrate from Cloud to Self-Hosted later?",diff --git a/website/app/page.tsx b/website/app/page.tsxindex bb238adf..969f6047 100644--- a/website/app/page.tsx+++ b/website/app/page.tsx@@ -335,11 +335,12 @@ export default function Home() {</h2><p className="muted mt-4 max-w-[460px] text-pretty">ClickHouse columnar storage compresses 1M daily events to ~2- GB/month. Fixed monthly tiers, no per-event gouging.+ GB/month. Pricing sized to your workload, no per-event gouging,+ no per-seat fees.</p><div className="mt-6 flex flex-wrap gap-3">- <Link href="/cloud" className="btn btn-accent">- See pricing+ <Link href={getCalendlyUrl()} className="btn btn-accent">+ Talk to us about pricing<ArrowRight className="h-4 w-4" /></Link><Linkdiff --git a/website/app/product/flutter-session-replay/page.tsx b/website/app/product/flutter-session-replay/page.tsxindex 19662ed1..e10e337f 100644--- a/website/app/product/flutter-session-replay/page.tsx+++ b/website/app/product/flutter-session-replay/page.tsx@@ -109,7 +109,7 @@ export default function FlutterSessionReplayPage() {className="mt-6 inline-flex items-center gap-1.5 text-[13px] hover:text-[color:var(--a2)]"style={{ color: "var(--fg-1)", fontFamily: "var(--font-mono)" }}>- See pricing →+ Explore Traceway Cloud →</Link></div></div>diff --git a/website/app/product/logs/page.tsx b/website/app/product/logs/page.tsxindex b44dcf8d..20de4a09 100644--- a/website/app/product/logs/page.tsx+++ b/website/app/product/logs/page.tsx@@ -297,7 +297,7 @@ export default function LogsPage() {},{q: "Do logs count toward my event limit?",- a: "Logs have their own ingestion tier that scales with your plan. See the Cloud pricing page for current limits. Self-hosting is unlimited.",+ a: "On Traceway Cloud, logs count toward your plan's data allowance, which we size per customer. Reach out and we'll put together a plan for your volume. Self-hosting is unlimited.",},]}/>diff --git a/website/app/product/monitors/page.tsx b/website/app/product/monitors/page.tsxnew file mode 100644index 00000000..222efd8f--- /dev/null+++ b/website/app/product/monitors/page.tsx@@ -0,0 +1,252 @@+import Link from "next/link";+import type { Metadata } from "next";+import { ArrowRight, Radar } from "lucide-react";++import { Chip } from "@/components/chip";+import { SectionHead } from "@/components/section-head";+import { FeatureRow } from "@/components/feature-row";+import { FaqList } from "@/components/faq-list";+import { FinalCTA } from "@/components/final-cta";+import { AuroraBackground } from "@/components/aurora-background";++export const metadata: Metadata = {+ title: "Monitors · Traceway",+ description:+ "Synthetic uptime monitoring built into your observability stack. HTTP, TCP, and real-browser Playwright checks, flap damping, failure screenshots, public status pages, and paging that resolves itself on recovery.",+};++export default function MonitorsPage() {+ return (+ <main className="relative">+ <section className="hero hero-product relative">+ <AuroraBackground variant="hero" />+ <div className="wrap relative z-10">+ <Chip variant="ok">+ <Radar className="h-3 w-3 inline mr-1" />+ Uptime Monitors & Status Pages+ </Chip>+ <h1 className="mt-6">+ Telemetry sees inside. <em>Monitors check from outside.</em>+ </h1>+ <p className="hero-sub">+ Traces and logs only exist while requests arrive. A monitor keeps+ probing on a schedule, an HTTP request, a TCP connect, or a full+ Playwright browser flow, so you find out your site is down before a+ user tells you. In the same tool that already holds the stack+ trace.+ </p>+ <div className="hero-cta-row">+ <Link+ href="https://docs.tracewayapp.com/learn/monitors"+ className="btn btn-accent"+ >+ Read the Docs <ArrowRight className="h-4 w-4" />+ </Link>+ <Link+ href="https://cloud.tracewayapp.com/register"+ className="btn btn-ghost"+ >+ Try Traceway Cloud+ </Link>+ </div>+ </div>+ </section>++ {/* WHITE BAND: feature sections render on white */}+ <div className="band-light">+ <section className="wrap">+ <FeatureRow+ eyebrow="Three kinds of probe"+ title={+ <>+ An HTTP request, a TCP connect, <em>or a real browser</em>+ </>+ }+ description="HTTP checks probe like Postman: method, headers, auth, body, and assertions on status codes, response content, response time, and days left on the TLS certificate. TCP checks cover databases, SMTP, and anything that is not HTTP. Every monitor has an interval down to 30 seconds, a timeout, and a failure threshold, so one flaky probe never wakes anyone at 3am."+ bullets={[+ "Assert on status, body substring or regex, latency, and TLS expiry",+ "TCP with optional TLS, send payload, and expected response",+ "Down only after N consecutive failures, flap damping built in",+ "Uptime and average latency per monitor, at a glance",+ ]}+ image={{+ src: "/images/monitors-list.png",+ alt: "The Traceway monitors list with HTTP, TCP, and browser checks and their uptime",+ }}+ />+ </section>++ <section className="wrap">+ <FeatureRow+ reverse+ eyebrow="Browser checks"+ title={+ <>+ Your uptime probe is <em>a Playwright test</em>+ </>+ }+ description="Write a full @playwright/test spec in the editor on the monitor itself, and it runs in headless Chromium on a schedule. A login flow or a checkout journey becomes your availability check, so 'up' means the thing your users actually do still works, not just that the load balancer answers 200."+ bullets={[+ "Real @playwright/test specs, syntax highlighted in the dialog",+ "Per-check environment variables; scripts never see server secrets",+ "Runs embedded in the :browser image, or on remote runner machines",+ "Runners connect outbound-only, no inbound ports to open",+ ]}+ image={{+ src: "/images/monitors-editor.png",+ alt: "Editing a Playwright browser check in Traceway",+ }}+ />+ </section>++ <section className="wrap">+ <FeatureRow+ eyebrow="When it breaks"+ title={+ <>+ Down comes with <em>evidence</em>+ </>+ }+ description="A failed browser run automatically stores the failure screenshot and the Playwright output, both one click from the run history. The monitor page shows availability, a latency chart, every probe with its error, and the incident timeline, so the person who responds starts with the answer instead of a blank terminal."+ bullets={[+ "Failure screenshot and full Playwright logs per failed run",+ "Per-probe latency, status code, and error message",+ "Incidents open and resolve themselves from state transitions",+ "A probe past its window is recorded as missed, never run late",+ ]}+ image={{+ src: "/images/monitors-detail.png",+ alt: "A monitor detail page with availability, latency chart, and failed runs with screenshots and logs",+ }}+ />+ </section>++ <section className="wrap">+ <FeatureRow+ reverse+ eyebrow="Status pages"+ title={+ <>+ Tell your users <em>before they ask</em>+ </>+ }+ description="Publish the uptime of selected monitors on a public status page: 90 days of per-day availability, incident history, your name, your logo, no login required. Serve it from your own domain with a CNAME. Latency numbers stay internal; the public page only shows availability."+ bullets={[+ "Public at /status/your-slug, or on your own custom domain",+ "90 days of per-day uptime bars with incident history",+ "Branding: title, description, and an uploaded logo",+ "Refreshes itself while your users watch",+ ]}+ image={{+ src: "/images/monitors-status-page.png",+ alt: "A public Traceway status page with 90 days of uptime bars and an active incident",+ }}+ />+ </section>++ <section className="wrap">+ <FeatureRow+ eyebrow="Wired into alerting"+ title={+ <>+ Down pages a human, recovery <em>cleans up after itself</em>+ </>+ }+ description="Add a Monitor Down rule and every monitor in the project is covered: a message to Slack, or a real page through your on-call escalation policy. Pages deduplicate per monitor, re-fires never restart the escalation clock, and when the check recovers the page resolves itself, so a blip at night that recovers on its own never needs a human."+ bullets={[+ "One rule covers every monitor in the project",+ "Escalation channels open an on-call page instead of a message",+ "Recovery auto-resolves the page and sends the all-clear",+ "The alert carries the monitor name and the last probe error",+ ]}+ image={{+ src: "/images/oncall-pages.png",+ alt: "The Traceway on-call incident queue fed by monitor state changes",+ }}+ />+ </section>+ </div>++ <FinalCTA+ title={+ <>+ Stop paying for <em>a separate uptime tool</em>+ </>+ }+ description="Monitors, status pages, alerting, and on-call in the same tool that holds your traces, logs, and errors. Open source if you self-host."+ primary={{+ label: "Read the Monitors docs",+ href: "https://docs.tracewayapp.com/learn/monitors",+ }}+ secondary={{+ label: "Start Free",+ href: "https://cloud.tracewayapp.com/register",+ }}+ />++ <section className="wrap pt-10 pb-24">+ <div className="max-w-3xl mx-auto">+ <SectionHead+ align="center"+ eyebrow="FAQ"+ title="Questions about monitors"+ />+ <div className="mt-4">+ <FaqList+ items={[+ {+ q: "Do I still need UptimeRobot or Pingdom?",+ a: "Not for the checks themselves. Traceway covers HTTP, TCP, and real-browser probes, flap damping, incident history, public status pages with custom domains, and alerting that can page a rotating on-call schedule. The difference is that the monitor, the alert, the trace, and the stack trace live in one place, so 'the site is down' and 'here is why' are the same screen.",+ },+ {+ q: "Where do browser checks run?",+ a: (+ <>+ <p>+ Wherever you decide. The <code>:browser</code> Docker+ image runs them inside the container with Chromium+ baked in. Any other deployment, including a plain+ binary with no Docker, can either install Node and a+ Playwright harness next to the backend, or hand+ execution to <code>traceway-runner</code> machines that+ connect outbound-only and claim work over a long-poll.+ Scripts always run with an allowlisted environment and+ never see your server's secrets.+ </p>+ </>+ ),+ },+ {+ q: "What stops one slow probe from marking my site down?",+ a: "The failure threshold. A monitor only transitions to down after the configured number of consecutive failures, and only that transition alerts. Recovery works the same way in reverse: the first successful probe flips it back and sends the all-clear.",+ },+ {+ q: "What happens if my Traceway instance is down?",+ a: "The truth is preserved. Runs live in a durable queue, and a probe that outlives its execution window is recorded as missed rather than executed late, so the uptime timeline shows a gap instead of a fabricated 100%. A stale 'is it up' answer is worse than no answer.",+ },+ {+ q: "Can the status page live on my own domain?",+ a: (+ <>+ <p>+ Yes. Set the custom domain on the status page, point a+ CNAME at your Traceway instance, and terminate TLS for+ that hostname at your reverse proxy. Visitors landing+ on that host are routed straight to the status page,+ with no Traceway branding beyond a footer credit.+ </p>+ </>+ ),+ },+ {+ q: "Is any of this gated behind a paid plan?",+ a: "Self-hosted Traceway is 100% open source with every monitor type, status pages, and alerting included. On Traceway Cloud, HTTP and TCP monitors and status pages are part of every plan; browser checks are currently a self-hosted feature because they execute your scripts, and your plan sizes how many monitors you can create.",+ },+ ]}+ />+ </div>+ </div>+ </section>+ </main>+ );+}diff --git a/website/components/home-tabs.tsx b/website/components/home-tabs.tsxindex 3a4659b1..89e43c00 100644--- a/website/components/home-tabs.tsx+++ b/website/components/home-tabs.tsx@@ -89,11 +89,11 @@ const tabs: Tab[] = [color: "var(--a4)",heading: "Monitor fleets of devices at scale.",description:- "Traceway's OpenTelemetry-native ingestion and ClickHouse columnar storage handle high-volume telemetry from IoT devices efficiently. Enterprise pricing supports large device fleets with predictable, fixed costs. No per-event billing surprises.",+ "Traceway's OpenTelemetry-native ingestion and ClickHouse columnar storage handle high-volume telemetry from IoT devices efficiently. Custom enterprise pricing supports large device fleets with predictable costs. No per-event billing surprises.",bullets: ["High-volume ingestion via OTLP/HTTP","ClickHouse compression keeps storage costs low",- "Enterprise pricing for large device fleets",+ "Custom pricing for large device fleets","Custom metrics for device health and telemetry",],href: "/cloud",diff --git a/website/components/pricing-plans.tsx b/website/components/pricing-plans.tsxdeleted file mode 100644index 3da19fc1..00000000--- a/website/components/pricing-plans.tsx+++ /dev/null@@ -1,476 +0,0 @@-import Link from "next/link";-import { ArrowRight, Check, Minus } from "lucide-react";--import { getCalendlyUrl } from "@/lib/calendly";--const REGISTER_URL = "https://cloud.tracewayapp.com/register";--type Plan = {- id: string;- name: string;- blurb: string;- price: string;- period?: string;- cta: { label: string; href: string };- featuresLead?: string;- features: string[];- highlight?: boolean;- badge?: string;-};--const PLANS: Plan[] = [- {- id: "starter",- name: "Starter",- blurb: "For hobby projects and early prototypes.",- price: "Free",- cta: { label: "Start free", href: REGISTER_URL },- featuresLead: "Includes",- features: [- "10k exceptions / mo",- "1 GB ingest / mo",- "Distributed tracing, logs & metrics",- "Session replay",- "Community support",- ],- },- {- id: "pro",- name: "Pro",- blurb: "For small teams shipping to production.",- price: "$12.99",- period: "/ mo",- cta: { label: "Start free", href: REGISTER_URL },- featuresLead: "Everything in Starter, plus",- features: [- "100k exceptions / mo",- "50 GB ingest / mo",- "$0.25 / GB beyond",- "Priority issue triage",- ],- },- {- id: "premium",- name: "Premium",- blurb: "For growing products with real traffic.",- price: "$24.99",- period: "/ mo",- highlight: true,- badge: "Most popular",- cta: { label: "Start free", href: REGISTER_URL },- featuresLead: "Everything in Pro, plus",- features: [- "1M exceptions / mo",- "150 GB ingest / mo",- "$0.25 / GB beyond",- "90-day data retention",- ],- },- {- id: "enterprise",- name: "Enterprise",- blurb: "For high volume at the best per-GB rate.",- price: "$499.99",- period: "/ mo",- cta: { label: "Start free", href: REGISTER_URL },- featuresLead: "Everything in Premium, plus",- features: [- "200M exceptions / mo",- "2 TB ingest / mo",- "$0.20 / GB beyond",- "Shared Slack channel",- ],- },- {- id: "enterprise-plus",- name: "Enterprise+",- blurb: "Managed self-hosting with custom SLAs.",- price: "Custom",- badge: "Managed self-hosting",- cta: { label: "Contact us", href: getCalendlyUrl() },- featuresLead: "Everything in Enterprise, plus",- features: [- "Unlimited exceptions",- "Custom data volume",- "Dedicated SRE",- "No data leaves your cloud",- ],- },-];--export function PricingPlans() {- return (- <div className="grid items-stretch gap-5 md:grid-cols-2 xl:grid-cols-5">- {PLANS.map((plan) => (- <div- key={plan.id}- className="relative flex flex-col rounded-[20px] px-6 py-7"- style={- plan.highlight- ? {- background: "var(--ink-0)",- border:- "1px solid color-mix(in oklab, var(--a2) 55%, transparent)",- boxShadow:- "0 2px 6px rgba(10,14,24,0.05), 0 24px 50px -26px color-mix(in oklab, var(--a2) 28%, rgba(10,14,24,0.22))",- }- : {- background: "var(--ink-0)",- border: "1px solid var(--hair-2)",- boxShadow:- "0 1px 2px rgba(10,14,24,0.04), 0 12px 30px -18px rgba(10,14,24,0.14)",- }- }- >- {plan.badge ? (- <span- className="absolute -top-3 left-1/2 -translate-x-1/2 whitespace-nowrap rounded-full px-3 py-1 text-[11px] font-medium"- style={- plan.highlight- ? { color: "var(--ink-0)", background: "var(--a2)" }- : {- color: "var(--ok)",- background: "var(--ink-0)",- border:- "1px solid color-mix(in oklab, var(--ok) 45%, transparent)",- }- }- >- {plan.badge}- </span>- ) : null}-- <div- className="text-[17px] font-semibold"- style={{ color: "var(--fg-0)" }}- >- {plan.name}- </div>- <p- className="mt-2 min-h-[38px] text-[13.5px]"- style={{ color: "var(--fg-2)", lineHeight: 1.45 }}- >- {plan.blurb}- </p>-- <div className="mt-5 flex items-baseline gap-1.5 whitespace-nowrap">- <span- className="text-[32px] font-bold leading-none tracking-[-0.02em]"- style={{ color: "var(--fg-0)" }}- >- {plan.price}- </span>- {plan.period ? (- <span className="text-[14px]" style={{ color: "var(--fg-3)" }}>- {plan.period}- </span>- ) : null}- </div>-- <Link- href={plan.cta.href}- className={`btn ${plan.highlight ? "btn-accent" : "btn-ghost"} mt-6 w-full justify-center`}- >- {plan.cta.label}- <ArrowRight className="h-4 w-4" />- </Link>-- <div className="pt-7">- {plan.featuresLead ? (- <div- className="mb-4 text-[12px] font-medium"- style={{ color: "var(--fg-2)" }}- >- {plan.featuresLead}- </div>- ) : null}- <ul className="flex flex-col gap-3">- {plan.features.map((f) => (- <li- key={f}- className="flex items-start gap-2.5 text-[13.5px]"- style={{ color: "var(--fg-1)" }}- >- <Check- className="mt-[3px] h-[15px] w-[15px] shrink-0"- style={{ color: "var(--ok)" }}- />- <span style={{ lineHeight: 1.4 }}>{f}</span>- </li>- ))}- </ul>- </div>- </div>- ))}- </div>- );-}--type Cell = string | boolean;-type CompareGroup = {- category: string;- rows: { label: string; values: Cell[] }[];-};--const PLAN_COLS = ["Starter", "Pro", "Premium", "Enterprise", "Enterprise+"];-const HIGHLIGHT_COL = 2;--const COMPARISON: CompareGroup[] = [- {- category: "Pricing",- rows: [- {- label: "Monthly price",- values: ["Free", "$12.99", "$24.99", "$499.99", "Custom"],- },- {- label: "Data overage rate",- values: ["—", "$0.25 / GB", "$0.25 / GB", "$0.20 / GB", "Volume rate"],- },- ],- },- {- category: "Exceptions",- rows: [- {- label: "Exceptions / month",- values: ["10k", "100k", "1M", "200M", "Unlimited"],- },- {- label: "Automatic grouping & ranking (SLO)",- values: [true, true, true, true, true],- },- {- label: "Source-mapped stack traces",- values: [true, true, true, true, true],- },- {- label: "Archive & resolve workflow (AI)",- values: [true, true, true, true, true],- },- ],- },- {- category: "Data ingest (logs, traces, spans, metrics, replay)",- rows: [- {- label: "Data ingest included / mo",- values: ["1 GB", "50 GB", "150 GB", "2 TB", "Custom"],- },- {- label: "Beyond included",- values: [- "Upgrade to add",- "$0.25 / GB",- "$0.25 / GB",- "$0.20 / GB",- "Volume rate",- ],- },- { label: "Distributed tracing", values: [true, true, true, true, true] },- { label: "Session replay", values: [true, true, true, true, true] },- {- label: "Logs & custom metrics",- values: [true, true, true, true, true],- },- {- label: "AI / LLM observability",- values: [true, true, true, true, true],- },- ],- },- {- category: "Platform",- rows: [- {- label: "Projects",- values: ["3", "10", "Unlimited", "Unlimited", "Unlimited"],- },- {- label: "Team members",- values: ["3", "Unlimited", "Unlimited", "Unlimited", "Unlimited"],- },- {- label: "Data retention*",- values: ["7 days", "30 days", "90 days", "Custom", "Custom"],- },- {- label: "Alerting & notifications",- values: [true, true, true, true, true],- },- ],- },- {- category: "Support",- rows: [- {- label: "Community & GitHub issues",- values: [true, true, true, true, true],- },- {- label: "Priority issue triage",- values: [false, true, true, true, true],- },- {- label: "Shared Slack channel",- values: [false, false, false, true, true],- },- { label: "Dedicated SRE", values: [false, false, false, false, true] },- { label: "Custom SLAs", values: [false, false, false, false, true] },- {- label: "Self-host, data stays in your cloud",- values: [false, false, false, false, true],- },- ],- },-];--function Value({ value, highlight }: { value: Cell; highlight: boolean }) {- if (value === true) {- return (- <Check- className="mx-auto h-[17px] w-[17px]"- style={{ color: highlight ? "var(--a2)" : "var(--ok)" }}- />- );- }- if (value === false) {- return (- <Minus- className="mx-auto h-[16px] w-[16px]"- style={{ color: "var(--fg-3)" }}- />- );- }- return (- <span- className="text-[13px]"- style={{- color: highlight ? "var(--a2)" : "var(--fg-1)",- fontWeight: highlight ? 600 : 400,- }}- >- {value}- </span>- );-}--const HILITE = "color-mix(in oklab, var(--a2) 8%, transparent)";-const GRID_COLS = "1.7fr repeat(5, 1fr)";--export function PlanComparison() {- return (- <div className="overflow-x-auto min-[940px]:overflow-visible">- <div className="min-w-[880px]">- {/* Sticky: section title + column headers pin below the navbar (h-16 = 64px) */}- <div- className="sticky z-30"- style={{- top: "64px",- background: "var(--ink-0)",- borderBottom: "1px solid var(--hair-2)",- boxShadow: "0 10px 18px -14px rgba(10,14,24,0.1)",- }}- >- <h2- className="px-3 pb-4 pt-6 text-center text-[26px] font-bold tracking-tight"- style={{ color: "var(--fg-0)" }}- >- A closer look at each plan- </h2>- <div className="grid" style={{ gridTemplateColumns: GRID_COLS }}>- <div />- {PLAN_COLS.map((name, i) => (- <div- key={name}- className="flex items-center justify-center px-3 pb-3 pt-2 text-center text-[14px] font-semibold"- style={{- color: i === HIGHLIGHT_COL ? "var(--a2)" : "var(--fg-0)",- background: i === HIGHLIGHT_COL ? HILITE : undefined,- borderTopLeftRadius: i === HIGHLIGHT_COL ? 14 : undefined,- borderTopRightRadius: i === HIGHLIGHT_COL ? 14 : undefined,- }}- >- {name}- </div>- ))}- </div>- </div>-- {COMPARISON.map((group, gi) => (- <div key={group.category}>- {/* Category */}- <div- className="grid"- style={{- gridTemplateColumns: GRID_COLS,- borderTop: gi > 0 ? "1px solid var(--hair-2)" : undefined,- }}- >- <div- className="px-3 pb-2.5 pt-6 text-[12.5px] font-semibold"- style={{ color: "var(--fg-2)" }}- >- {group.category}- </div>- {PLAN_COLS.map((_, ci) => (- <div- key={ci}- style={{- background: ci === HIGHLIGHT_COL ? HILITE : undefined,- }}- />- ))}- </div>- {/* Rows */}- {group.rows.map((row, ri) => {- const lastRow =- gi === COMPARISON.length - 1 && ri === group.rows.length - 1;- return (- <div- key={row.label}- className="grid"- style={{- gridTemplateColumns: GRID_COLS,- borderTop: "1px solid var(--hair)",- }}- >- <div- className="flex items-center px-3 py-3.5 text-[13.5px]"- style={{ color: "var(--fg-1)" }}- >- {row.label}- </div>- {row.values.map((value, ci) => (- <div- key={ci}- className="flex items-center justify-center px-3 py-3.5"- style={{- background: ci === HIGHLIGHT_COL ? HILITE : undefined,- borderBottomLeftRadius:- ci === HIGHLIGHT_COL && lastRow ? 14 : undefined,- borderBottomRightRadius:- ci === HIGHLIGHT_COL && lastRow ? 14 : undefined,- }}- >- <Value value={value} highlight={ci === HIGHLIGHT_COL} />- </div>- ))}- </div>- );- })}- </div>- ))}- </div>- <p- className="mx-auto mt-6 max-w-3xl px-3 text-center text-[12px]"- style={{ color: "var(--fg-3)", lineHeight: 1.55 }}- >- * Retention applies to exceptions, traces, spans, logs, and session- replay. Metrics are kept longer at reduced granularity (1-minute- resolution for 30 days, 1-hour rollups for 1 year), and continuous- profiling data is retained for 30 days on every plan.- </p>- </div>- );-}diff --git a/website/components/site-footer.tsx b/website/components/site-footer.tsxindex 15d37f97..2842e151 100644--- a/website/components/site-footer.tsx+++ b/website/components/site-footer.tsx@@ -18,6 +18,8 @@ const COLUMNS: Column[] = [{ label: "Metrics", href: "/product/metrics" },{ label: "Session Replay", href: "/product/session-replay" },{ label: "Exceptions / Stack Traces", href: "/product/stack-traces" },+ { label: "Monitors", href: "/product/monitors" },+ { label: "On-Call", href: "/product/on-call" },],},{@@ -27,7 +29,6 @@ const COLUMNS: Column[] = [{ label: "MCP Server", href: "/product/mcp" },{ label: "AI Tracing", href: "/product/ai-tracing" },{ label: "Dashboards as Code", href: "/product/dashboards" },- { label: "On-Call", href: "/product/on-call" },{ label: "Performance", href: "/product/performance" },{ label: "Flutter Session Replay", href: "/product/flutter-session-replay" },{ label: "Symbolicator", href: "/product/symbolication" },diff --git a/website/components/site-header.tsx b/website/components/site-header.tsxindex 0d994e29..7abb484d 100644--- a/website/components/site-header.tsx+++ b/website/components/site-header.tsx@@ -19,6 +19,7 @@ import {Plug,LayoutDashboard,PhoneCall,+ Radar,} from "lucide-react";import { MobileNav } from "@/components/mobile-nav";import { DiscordIcon } from "@/components/discord-icon";@@ -64,6 +65,18 @@ const PILLARS: NavItem[] = [href: "/product/stack-traces",icon: Bug,},+ {+ title: "Monitors",+ description: "HTTP, TCP, and browser uptime checks with status pages.",+ href: "/product/monitors",+ icon: Radar,+ },+ {+ title: "On-Call",+ description: "Rotating schedules, escalation policies, real paging.",+ href: "/product/on-call",+ icon: PhoneCall,+ },];const SPECIALIZED: NavItem[] = [@@ -91,12 +104,6 @@ const SPECIALIZED: NavItem[] = [href: "/product/dashboards",icon: LayoutDashboard,},- {- title: "On-Call",- description: "Rotating schedules, escalation policies, real paging.",- href: "/product/on-call",- icon: PhoneCall,- },{title: "Performance",description: "P50/P95/P99 percentiles, waterfall traces.",diff --git a/website/public/images/monitors-detail.png b/website/public/images/monitors-detail.pngnew file mode 100644index 00000000..60283477Binary files /dev/null and b/website/public/images/monitors-detail.png differdiff --git a/website/public/images/monitors-editor.png b/website/public/images/monitors-editor.pngnew file mode 100644index 00000000..81e97cd1Binary files /dev/null and b/website/public/images/monitors-editor.png differdiff --git a/website/public/images/monitors-list.png b/website/public/images/monitors-list.pngnew file mode 100644index 00000000..9bfede0eBinary files /dev/null and b/website/public/images/monitors-list.png differdiff --git a/website/public/images/monitors-status-page.png b/website/public/images/monitors-status-page.pngnew file mode 100644index 00000000..360771c5Binary files /dev/null and b/website/public/images/monitors-status-page.png differ