neiam
/vigil
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
Log in to mark this repository.
Uptime: HTTP/ping/TCP/TLS/heartbeat checks, self-rescheduling chain, alerts, status pages
e47e04f · gmorell · 2026-12-02 03:07
Files changed
modified
config/config.exs
+4
−1
| 54 | 54 | {"* * * * *", Vigil.Alerts.EvaluateWorker}, |
| 55 | 55 | # Cron monitors: missed check-ins and timed-out runs (Vigil.Monitors). |
| 56 | 56 | {"* * * * *", Vigil.Monitors.TickWorker}, |
| 57 | + # Uptime checks whose self-rescheduling chain stopped (Vigil.Uptime). | |
| 58 | + {"* * * * *", Vigil.Uptime.ReconcileWorker}, | |
| 57 | 59 | # Chunk blobs and assemble statuses past a day (Vigil.Artifacts). |
| 58 | 60 | {"41 3 * * *", Vigil.Artifacts.CleanupWorker} |
| 59 | 61 | ]} |
| 69 | 71 | %{table: "project_counts", kind: :weekly, ahead_days: 21, keep_days: 400}, |
| 70 | 72 | # Spans are many and short-lived; their rollups last longer. |
| 71 | 73 | %{table: "spans", kind: :uuid7_daily, ahead_days: 3, keep_days: 14}, |
| 72 | − %{table: "transaction_counts", kind: :weekly, ahead_days: 21, keep_days: 90} | |
| 74 | + %{table: "transaction_counts", kind: :weekly, ahead_days: 21, keep_days: 90}, | |
| 75 | + %{table: "uptime_checks", kind: :uuid7_daily, ahead_days: 3, keep_days: 30} | |
| 73 | 76 | ] |
| 74 | 77 | |
| 75 | 78 | # Configure the endpoint |
modified
config/test.exs
+6
−0
| 63 | 63 | # Uploaded files (chunks, bundle files) go under _build, per test partition. |
| 64 | 64 | config :vigil, Vigil.Storage.Local, |
| 65 | 65 | root: Path.expand("../_build/test/storage#{System.get_env("MIX_TEST_PARTITION")}", __DIR__) |
| 66 | + | |
| 67 | +# Uptime HTTP checks go to Req.Test stubs, with hosts "resolving" to a | |
| 68 | +# public address (Vigil.Uptime.Checker). | |
| 69 | +config :vigil, :uptime_opts, | |
| 70 | + req_options: [plug: {Req.Test, Vigil.Uptime.Checker}], | |
| 71 | + resolver: &Vigil.TestResolver.public/1 |
modified
lib/vigil/alerts.ex
+2
−2
| 216 | 216 | rules = |
| 217 | 217 | Repo.all( |
| 218 | 218 | from r in Rule, |
| 219 | − where: r.project_id == ^project_id and r.enabled and r.kind != :monitor, | |
| 219 | + where: r.project_id == ^project_id and r.enabled and r.kind not in [:monitor, :uptime], | |
| 220 | 220 | preload: :recipients |
| 221 | 221 | ) |
| 222 | 222 |
| 288 | 288 | end |
| 289 | 289 | |
| 290 | 290 | @doc """ |
| 291 | − Tells a project's enabled rules of `kind` (`:monitor`) a `message` | |
| 291 | + Tells a project's enabled rules of `kind` (`:monitor`, `:uptime`) a `message` | |
| 292 | 292 | (`%{title:, text:, url:, level:}`): a notification per rule, delivered |
| 293 | 293 | to its recipients as issue alerts are. Returns the notifications. |
| 294 | 294 | """ |
modified
lib/vigil/alerts/rule.ex
+4
−2
| 8 | 8 | * `:regression`: a resolved issue came back; |
| 9 | 9 | * `:monitor`: a cron monitor started failing (an incident opened) or |
| 10 | 10 | recovered (`Vigil.Monitors`). Told once per incident, so |
| 11 | − `renotify_minutes` doesn't apply. | |
| 11 | + `renotify_minutes` doesn't apply; | |
| 12 | + * `:uptime`: an uptime monitor went down or came back up | |
| 13 | + (`Vigil.Uptime`), once per change. | |
| 12 | 14 | |
| 13 | 15 | Each issue is told about once per rule, until it regresses, or again |
| 14 | 16 | after `renotify_minutes` when that is set (GlitchTip has no re-notify). |
| 18 | 20 | |
| 19 | 21 | schema "alert_rules" do |
| 20 | 22 | field :name, :string |
| 21 | − field :kind, Ecto.Enum, values: [:frequency, :new_issue, :regression, :monitor] | |
| 23 | + field :kind, Ecto.Enum, values: [:frequency, :new_issue, :regression, :monitor, :uptime] | |
| 22 | 24 | field :quantity, :integer |
| 23 | 25 | field :timespan_minutes, :integer |
| 24 | 26 | field :renotify_minutes, :integer |
modified
lib/vigil/outbound.ex
+18
−3
| 96 | 96 | `{:ok, [ip_tuple]} | {:error, reason}`; defaults to asking |
| 97 | 97 | `:inet.getaddrs/2` for both IPv4 and IPv6 addresses. Tests use it to |
| 98 | 98 | avoid real DNS. |
| 99 | + * `:allow_private` — skip the address checks for this call, as the | |
| 100 | + `:allow_private_outbound` setting does for all (tests). | |
| 99 | 101 | """ |
| 100 | 102 | @spec check_url(String.t(), keyword()) :: :ok | {:error, reason()} |
| 101 | 103 | def check_url(url, opts \\ []) |
| 102 | 104 | |
| 103 | 105 | def check_url(url, opts) when is_binary(url) do |
| 104 | 106 | with {:ok, host} <- parse(url) do |
| 105 | − if Application.get_env(:vigil, :allow_private_outbound, false), | |
| 107 | + if opts[:allow_private] || Application.get_env(:vigil, :allow_private_outbound, false), | |
| 106 | 108 | do: :ok, |
| 107 | − else: check_host(host, Keyword.get(opts, :resolver, &resolve/1)) | |
| 109 | + else: check_resolved(host, Keyword.get(opts, :resolver, &resolve/1)) | |
| 108 | 110 | end |
| 109 | 111 | end |
| 110 | 112 | |
| 111 | 113 | def check_url(_url, _opts), do: {:error, :invalid_url} |
| 112 | 114 | |
| 115 | + @doc """ | |
| 116 | + The same check for a bare `host` (a TCP or TLS target, not a URL): `:ok` | |
| 117 | + when every address it resolves to is public. Options as `check_url/2`. | |
| 118 | + """ | |
| 119 | + @spec check_host(String.t(), keyword()) :: :ok | {:error, reason()} | |
| 120 | + def check_host(host, opts) when is_binary(host) and host != "" do | |
| 121 | + if opts[:allow_private] || Application.get_env(:vigil, :allow_private_outbound, false), | |
| 122 | + do: :ok, | |
| 123 | + else: check_resolved(host, Keyword.get(opts, :resolver, &resolve/1)) | |
| 124 | + end | |
| 125 | + | |
| 126 | + def check_host(_host, opts) when is_list(opts), do: {:error, :missing_host} | |
| 127 | + | |
| 113 | 128 | @doc "True when `ip` (an `:inet` address tuple) must not be connected to." |
| 114 | 129 | @spec blocked_address?(:inet.ip_address()) :: boolean() |
| 115 | 130 | def blocked_address?({_, _, _, _} = ip), do: Enum.any?(@ipv4_blocked, &in_cidr?(ip, &1)) |
| 137 | 152 | end |
| 138 | 153 | end |
| 139 | 154 | |
| 140 | − defp check_host(host, resolver) do | |
| 155 | + defp check_resolved(host, resolver) do | |
| 141 | 156 | with {:ok, addresses} <- addresses(host, resolver) do |
| 142 | 157 | case Enum.find(addresses, &blocked_address?/1) do |
| 143 | 158 | nil -> :ok |
added
lib/vigil/uptime.ex
+431
−0
Click to load diff…
added
lib/vigil/uptime/check.ex
+23
−0
Click to load diff…
added
lib/vigil/uptime/check_worker.ex
+29
−0
Click to load diff…
added
lib/vigil/uptime/checker.ex
+280
−0
Click to load diff…
added
lib/vigil/uptime/monitor.ex
+132
−0
Click to load diff…
added
lib/vigil/uptime/reconcile_worker.ex
+10
−0
Click to load diff…
added
lib/vigil/uptime/status_page.ex
+41
−0
Click to load diff…
added
lib/vigil_web/api/v0/heartbeat_controller.ex
+21
−0
Click to load diff…
modified
lib/vigil_web/live/project_live/alerts.ex
+6
−2
Click to load diff…
modified
lib/vigil_web/router.ex
+4
−0
Click to load diff…
added
priv/repo/migrations/20261202030307_create_uptime.exs
+101
−0
Click to load diff…
modified
?
+0
−0
Click to load diff…
added
test/vigil/uptime_test.exs
+253
−0
Click to load diff…
added
test/vigil_web/api/heartbeat_test.exs
+25
−0
Click to load diff…
Parents: 06beb3b