neiam
/vigil
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
Slice 7: cron monitors
06beb3b · gmorell · 2026-12-02 03:01
Files changed
modified
ROADMAP.md
+14
−1
@@ -374,7 +374,7 @@ The `/api/0` API:
| 374 | 374 | - `mix vigil.test ORG PROJECT --kind transaction` sends sample traced requests. |
| 375 | 375 | - Not done: N+1 detection ("Later"). The trace page queries twice per visit, once for the static render and once on connect. |
| 376 | 376 | |
| 377 | −### 7. Cron monitors · medium | |
| 377 | +### 7. Cron monitors · medium · **done** | |
| 378 | 378 | This is new: GlitchTip throws `check_in` items away. |
| 379 | 379 | - **Monitors:** |
| 380 | 380 | - Upserted from `monitor_config` (crontab or interval schedule, timezone, check-in margin, max runtime, failure and recovery thresholds), or created in the UI. |
@@ -388,6 +388,19 @@ This is new: GlitchTip throws `check_in` items away.
| 388 | 388 | - **UI:** monitors list with a status timeline per monitor, and the next expected run. |
| 389 | 389 | - `GET /api/0/organizations/{o}/monitors/` returns the shape sentry-cli expects. |
| 390 | 390 | - **Exit:** Vigil's own Oban cron jobs, reported through sentry-elixir, show up and alert when they're missed. |
| 391 | +- **As built:** | |
| 392 | + - Check-ins: | |
| 393 | + - `monitor_config` upserts the monitor by slug. Without a config, a check-in for an unknown slug is dropped, as Sentry does. | |
| 394 | + - `in_progress` and its result pair by `check_in_id`, which SDKs send as 32 hex digits or hyphenated. A repeated result is ignored. | |
| 395 | + - Every check-in moves `next_expected_at` to the schedule's next slot. | |
| 396 | + - Crontabs use Oban's parser (`next_at`, `@daily` and friends). Time zones apply only when the runtime has a tz database; Elixir ships UTC-only and no dependency was added, so schedules are UTC until one is. | |
| 397 | + - The minutely `Monitors.TickWorker`: | |
| 398 | + - Turns each slot past its margin into a `missed` check-in, at most 10 per monitor per tick, then skips ahead. | |
| 399 | + - Turns runs in progress past `max_runtime` into `timeout`. | |
| 400 | + - Thresholds open and close `monitor_incidents`, at most one open per monitor. Both edges alert through rules of the new kind `:monitor`. A notification can now carry a plain message instead of issues; email and every webhook type deliver it, and uptime (slice 8) can reuse it. | |
| 401 | + - `GET /api/0/organizations/{org}/monitors/` returns Sentry's shape for visible projects. | |
| 402 | + - Pages: the monitors list (status timeline, health, last and next run; live; inline "New monitor"), and a monitor's detail (settings, timeline, check-ins, incidents, edit, enable/disable, admin delete). The nav link reads "Crons". | |
| 403 | + - Tested with the real sentry-elixir 14.1 Oban cron integration, unchanged and fed Oban's job telemetry for Vigil's own MaintainWorker and EvaluateWorker: monitors appear, a missed nightly run opens an incident and alerts. Also tested with sentry-python's `@monitor` and sentry-cli 2.58 `monitors run` and `monitors list`. Vigil doesn't report its own crons to itself; that would mean adding sentry-elixir as a dependency. | |
| 391 | 404 | |
| 392 | 405 | ### 8. Uptime · medium |
| 393 | 406 | - **Monitors:** HTTP GET, HTTP POST, ping, TCP, SSL expiry, and heartbeat (push to `/api/0/organizations/{o}/heartbeat_check/{uuid}/`). |
modified
lib/vigil_web/components/monitor_components.ex
+3
−1
@@ -147,7 +147,9 @@ defmodule VigilWeb.MonitorComponents do
| 147 | 147 | counts = |
| 148 | 148 | check_ins |
| 149 | 149 | |> Enum.frequencies_by(& &1.status) |
| 150 | − |> then(fn f -> for s <- @statuses, n = f[s], do: "#{n} #{String.downcase(status_label(s))}" end) | |
| 150 | + |> then(fn f -> | |
| 151 | + for s <- @statuses, n = f[s], do: "#{n} #{String.downcase(status_label(s))}" | |
| 152 | + end) | |
| 151 | 153 | |> Enum.join(", ") |
| 152 | 154 | |
| 153 | 155 | "Last #{length(check_ins)} check-ins: #{counts}" |
modified
lib/vigil_web/live/monitor_live/index.ex
+15
−7
@@ -157,12 +157,14 @@ defmodule VigilWeb.MonitorLive.Index do
| 157 | 157 | <%= if @count > 0 do %> |
| 158 | 158 | <div class="flex flex-wrap items-center justify-between gap-2"> |
| 159 | 159 | <p id="monitors-summary" class="text-sm text-base-content/70"> |
| 160 | − {@count} {if @count == 1, do: "monitor", else: "monitors"}<span :if={@failing > 0}> | |
| 160 | + {@count} {if @count == 1, do: "monitor", else: "monitors"} | |
| 161 | + <span :if={@failing > 0}> | |
| 161 | 162 | · |
| 162 | 163 | <span class="font-semibold text-error"> |
| 163 | 164 | <.icon name="hero-exclamation-triangle-micro" class="size-4 align-text-bottom" /> |
| 164 | 165 | {@failing} failing |
| 165 | − </span></span> | |
| 166 | + </span> | |
| 167 | + </span> | |
| 166 | 168 | </p> |
| 167 | 169 | <.legend /> |
| 168 | 170 | </div> |
@@ -243,7 +245,10 @@ defmodule VigilWeb.MonitorLive.Index do
| 243 | 245 | |
| 244 | 246 | defp setup_crons(assigns) do |
| 245 | 247 | ~H""" |
| 246 | − <section id="monitors-empty" class="rounded-box border border-dashed border-base-300 bg-base-100 p-8"> | |
| 248 | + <section | |
| 249 | + id="monitors-empty" | |
| 250 | + class="rounded-box border border-dashed border-base-300 bg-base-100 p-8" | |
| 251 | + > | |
| 247 | 252 | <div class="mx-auto max-w-2xl space-y-5"> |
| 248 | 253 | <div class="text-center"> |
| 249 | 254 | <.icon name="hero-clock" class="mx-auto mb-2 block size-10 text-primary/60" /> |
@@ -259,8 +264,7 @@ defmodule VigilWeb.MonitorLive.Index do
| 259 | 264 | <div class="space-y-2"> |
| 260 | 265 | <h3 class="text-sm font-semibold">sentry-elixir</h3> |
| 261 | 266 | <p class="text-sm text-base-content/70"> |
| 262 | − Turn on the Oban or Quantum cron integration, or check in yourself with | |
| 263 | − <code class="font-mono">Sentry.capture_check_in/1</code>: | |
| 267 | + Turn on the Oban or Quantum cron integration, or check in yourself with <code class="font-mono">Sentry.capture_check_in/1</code>: | |
| 264 | 268 | </p> |
| 265 | 269 | <pre |
| 266 | 270 | id="setup-crons-elixir" |
@@ -306,8 +310,12 @@ defmodule VigilWeb.MonitorLive.Index do
| 306 | 310 | <p class="text-xs text-base-content/60"> |
| 307 | 311 | <.icon name="hero-bell-micro" class="size-3.5 align-text-bottom" /> |
| 308 | 312 | To be told when a job fails or recovers, add an alert rule |
| 309 | − <em>“A cron monitor fails or recovers”</em> on the project's | |
| 310 | − <.link navigate={@alerts_path} class="link link-hover" id="monitors-alerts-link">Alerts page</.link>. | |
| 313 | + <em>“A cron monitor fails or recovers”</em> | |
| 314 | + on the project's <.link | |
| 315 | + navigate={@alerts_path} | |
| 316 | + class="link link-hover" | |
| 317 | + id="monitors-alerts-link" | |
| 318 | + >Alerts page</.link>. | |
| 311 | 319 | </p> |
| 312 | 320 | </div> |
| 313 | 321 | </section> |
modified
lib/vigil_web/live/monitor_live/show.ex
+4
−1
@@ -120,7 +120,10 @@ defmodule VigilWeb.MonitorLive.Show do
| 120 | 120 | {:noreply, |
| 121 | 121 | socket |
| 122 | 122 | |> load(monitor) |
| 123 | − |> put_flash(:info, if(monitor.enabled, do: "Monitor enabled.", else: "Monitor disabled."))} | |
| 123 | + |> put_flash( | |
| 124 | + :info, | |
| 125 | + if(monitor.enabled, do: "Monitor enabled.", else: "Monitor disabled.") | |
| 126 | + )} | |
| 124 | 127 | |
| 125 | 128 | {:error, _} -> |
| 126 | 129 | {:noreply, put_flash(socket, :error, "You can't change this monitor.")} |
Parents: 3567cad