Part 2 of #66 covers items 3, 4 and 5. Item 6 waits for tinker_tickets#126, and item 7 (taking over hwmonDaemon's network checks) will be its own PR.
What changes
Thor first (items 3 and 4). Before opening these tickets, Gandalf asks Thor's GET /api/incidents/covering:
Ticket
Asked as
When
No metrics from host
?host=<name>
only when every switch port of the host is up
Planned reboot didn't come back
?host=<name>
same
Ping host unreachable
?host=<name>
same
No Prometheus data
?scope=source:prometheus
always
Interface link-down, cluster network failure
not asked
these are network evidence, so they're Gandalf's tickets under the contract
Covered: when Thor names a ticket, Gandalf posts its full report there as an "Also seen by Gandalf" comment. It then tracks that ticket for the alert, so the recovery note goes there too. If the comment fails, Gandalf tries again next cycle instead of opening a duplicate.
Fail open: Gandalf opens its own ticket as before in every other case: no thor config, a 4 second timeout, any HTTP error, a reply that doesn't parse, or an answer with only shadow incidents. The shadow incident keys are logged next to Gandalf's ticket for the before and after comparison.
Dedup keys (item 5). Every ticket now sends a dedup_key. The scheme is in the README:
host:<host>:iface_down:<iface>
host:<host>:metrics_missing
device:<name>:unreachable and device:<name>:offline
device:<switch>:cable_mismatch:<cable>
cluster:network:failure
source:prometheus:unavailable
site:wan:<event type>[:<detail>]
A WAN ticket that bundles several alerts uses the key of the first one.
Backfill:scripts/dedup_key_map.py (read only) prints {ticket_id: dedup_key} for Gandalf's tickets that are still open in Tinker. Tinker's scripts/backfill_dedup_keys.php takes that file as input. A dry run on prod data with this branch found 38 open tickets in Tinker, of which 2 are Gandalf's:
Make Gandalf's key: I generate a key on CT 157, put it in config.json under thor, and give you only its SHA-256. You add {"name": "gandalf", "sha256": "<hex>", "scopes": ["read"], "sources": ["10.10.10.61/32"]} to Thor's /etc/thor/thor.json and restart thor on CT 173. Until then Gandalf never asks Thor, and behaves exactly as today apart from the keys.
Run the backfill on Tinker: run it with --dry-run first, then for real, so a recurrence of either open ticket matches it instead of opening a new one.
Tests
759 pass (19 new):
tests/test_thor.py: covered, scope, shadow, and failing open on 400, 401, 503, timeout, bad JSON and a non-object reply.
TestThorFirst: comment instead of a ticket, retry on a failed comment, network evidence skips Thor, interface and cluster tickets never ask, WAN keys.
Key scheme, Tinker's key format, and the backfill map.
Part 2 of #66 covers items 3, 4 and 5. Item 6 waits for tinker_tickets#126, and item 7 (taking over hwmonDaemon's network checks) will be its own PR.
## What changes
**Thor first (items 3 and 4).** Before opening these tickets, Gandalf asks Thor's `GET /api/incidents/covering`:
| Ticket | Asked as | When |
|---|---|---|
| No metrics from host | `?host=<name>` | only when every switch port of the host is up |
| Planned reboot didn't come back | `?host=<name>` | same |
| Ping host unreachable | `?host=<name>` | same |
| No Prometheus data | `?scope=source:prometheus` | always |
| Interface link-down, cluster network failure | not asked | these are network evidence, so they're Gandalf's tickets under the contract |
- **Covered:** when Thor names a ticket, Gandalf posts its full report there as an "Also seen by Gandalf" comment. It then tracks that ticket for the alert, so the recovery note goes there too. If the comment fails, Gandalf tries again next cycle instead of opening a duplicate.
- **Fail open:** Gandalf opens its own ticket as before in every other case: no `thor` config, a 4 second timeout, any HTTP error, a reply that doesn't parse, or an answer with only shadow incidents. The shadow incident keys are logged next to Gandalf's ticket for the before and after comparison.
**Dedup keys (item 5).** Every ticket now sends a `dedup_key`. The scheme is in the README:
- `host:<host>:iface_down:<iface>`
- `host:<host>:metrics_missing`
- `device:<name>:unreachable` and `device:<name>:offline`
- `device:<switch>:cable_mismatch:<cable>`
- `cluster:network:failure`
- `source:prometheus:unavailable`
- `site:wan:<event type>[:<detail>]`
A WAN ticket that bundles several alerts uses the key of the first one.
**Backfill:** `scripts/dedup_key_map.py` (read only) prints `{ticket_id: dedup_key}` for Gandalf's tickets that are still open in Tinker. Tinker's `scripts/backfill_dedup_keys.php` takes that file as input. A dry run on prod data with this branch found 38 open tickets in Tinker, of which 2 are Gandalf's:
```
460506581 site:wan:wan_unstable
666018103 host:monitor-01:iface_down:enp3s0
```
No two tickets share a key.
## After merge (operator steps)
1. **Make Gandalf's key:** I generate a key on CT 157, put it in `config.json` under `thor`, and give you only its SHA-256. You add `{"name": "gandalf", "sha256": "<hex>", "scopes": ["read"], "sources": ["10.10.10.61/32"]}` to Thor's `/etc/thor/thor.json` and restart `thor` on CT 173. Until then Gandalf never asks Thor, and behaves exactly as today apart from the keys.
2. **Run the backfill on Tinker:** run it with `--dry-run` first, then for real, so a recurrence of either open ticket matches it instead of opening a new one.
## Tests
- 759 pass (19 new):
- `tests/test_thor.py`: covered, scope, shadow, and failing open on 400, 401, 503, timeout, bad JSON and a non-object reply.
- `TestThorFirst`: comment instead of a ticket, retry on a failed comment, network evidence skips Thor, interface and cluster tickets never ask, WAN keys.
- Key scheme, Tinker's key format, and the backfill map.
- flake8, `bandit -ll` and the dash check are clean.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared
merged commit 4cbfc02801 into main2026-11-28 20:01:40 -05:00
jared
deleted branch thor-contract-22026-11-28 20:01:43 -05:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Part 2 of #66 covers items 3, 4 and 5. Item 6 waits for tinker_tickets#126, and item 7 (taking over hwmonDaemon's network checks) will be its own PR.
What changes
Thor first (items 3 and 4). Before opening these tickets, Gandalf asks Thor's
GET /api/incidents/covering:?host=<name>?host=<name>?host=<name>?scope=source:prometheusthorconfig, a 4 second timeout, any HTTP error, a reply that doesn't parse, or an answer with only shadow incidents. The shadow incident keys are logged next to Gandalf's ticket for the before and after comparison.Dedup keys (item 5). Every ticket now sends a
dedup_key. The scheme is in the README:host:<host>:iface_down:<iface>host:<host>:metrics_missingdevice:<name>:unreachableanddevice:<name>:offlinedevice:<switch>:cable_mismatch:<cable>cluster:network:failuresource:prometheus:unavailablesite:wan:<event type>[:<detail>]A WAN ticket that bundles several alerts uses the key of the first one.
Backfill:
scripts/dedup_key_map.py(read only) prints{ticket_id: dedup_key}for Gandalf's tickets that are still open in Tinker. Tinker'sscripts/backfill_dedup_keys.phptakes that file as input. A dry run on prod data with this branch found 38 open tickets in Tinker, of which 2 are Gandalf's:No two tickets share a key.
After merge (operator steps)
config.jsonunderthor, and give you only its SHA-256. You add{"name": "gandalf", "sha256": "<hex>", "scopes": ["read"], "sources": ["10.10.10.61/32"]}to Thor's/etc/thor/thor.jsonand restartthoron CT 173. Until then Gandalf never asks Thor, and behaves exactly as today apart from the keys.--dry-runfirst, then for real, so a recurrence of either open ticket matches it instead of opening a new one.Tests
tests/test_thor.py: covered, scope, shadow, and failing open on 400, 401, 503, timeout, bad JSON and a non-object reply.TestThorFirst: comment instead of a ticket, retry on a failed comment, network evidence skips Thor, interface and cluster tickets never ask, WAN keys.bandit -lland the dash check are clean.🤖 Generated with Claude Code