Commit 241c273
feat(cloud): observability ingest pipeline — issues + incidents (Phase 3) (#140)
* feat(cloud): add the observability ingest pipeline (issues + incidents)
Phase 3 of the observability plan — durable, cross-deployment monitoring
in the Lunora Cloud control plane, fed by the Phase 2 OTLP transport.
- ingest: `POST /v1/telemetry` accepts OTLP-over-HTTP/JSON from the tenant
`otlpSink` and the container exporter, decodes the error spans
(`src/telemetry/otlp.ts`), and folds them into grouped issues/incidents
through a deploy-key-authorized `telemetry.ingest` mutation. Synchronous
— the cloud app has no queue producer binding, so ingest inserts to D1
directly (like `usage.ingest`); auth reuses `authorizeDeployKey`, not the
plaintext admin token.
- store: `issues` + `incidents` `.global()` D1 tables, fingerprinted with
`@lunora/fingerprint` (the same hash the local Studio computes, so a local
Issue and a cloud Issue are one object); `lunora/{issues,incidents}.ts`
member-authorized read/triage functions. A `TelemetryStore` adapter
(`src/telemetry/store.ts`) owns the non-relational side — AE metrics plus a
guarded Pipeline→R2 archive, each a no-op without its binding.
- dashboard: hosted `IssuesSection` / `IncidentsSection`, gated behind the
`logStreams` entitlement, wired into `OrganizationDashboard`.
- bindings: a `TELEMETRY` AE dataset + `TELEMETRY_BUCKET` R2 bucket.
Vendors `@lunora/fingerprint` (Phase 1, not yet merged) so this stacks on
the cloud branch; the graft folds away once Phase 1 lands on alpha.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018sRFb1136YE8KDmDbFMYmm
* feat(cloud): observability alerts — rules + delivery (Phase 4) (#141)
* feat(cloud): add observability alerts — rules, firing + delivery
Phase 4 of the observability plan (the "watches while you sleep" tier),
stacked on the Phase 3 ingest.
- schema: `alertRules` (name, target issue/incident, threshold, channel
email/webhook, destination, enabled) + `alerts` (fired-alert audit trail
with firing→delivered state, notification denormalized).
- firing: the telemetry `ingest` mutation loads the org's enabled rules and
fires each the first time a source's count crosses its threshold
(`before < threshold <= after`, so exactly once), inserting a `firing`
alert row. The pure crossing/render logic lives in `src/telemetry/alerts.ts`
(unit-tested), mirroring how `usage.ingest` delegates to `evaluateSpendCap`.
- delivery: the `/v1/telemetry` edge handler delivers fired alerts
best-effort (email via `@lunora/mail`, webhook via JSON POST) then stamps
them delivered — never blocking or failing ingest.
- functions: `alerts.{rules,createRule,setRuleEnabled,deleteRule,list,
markDelivered}` (member-authed reads/writes; deploy-key-authed markDelivered).
- dashboard: `AlertsSection` (manage rules + recent fired alerts), gated
behind the `logStreams` entitlement, wired into `OrganizationDashboard`.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018sRFb1136YE8KDmDbFMYmm
* fix(cloud): validate webhook alert destinations against SSRF
An alert rule's webhook `destination` is `fetch`ed by the control plane
when the alert fires, so an owner/admin could otherwise aim it at internal
infrastructure (loopback, RFC-1918, the 169.254.169.254 metadata IP, …) —
server-side request forgery. Add a pure `isSafeWebhookUrl` guard (https
only, public host, no embedded credentials, no loopback/private/link-local
IPv4 or IPv6) enforced both at `createRule` (reject the rule) and in
`deliverAlert` (never fetch an unsafe target — defense in depth for any
rule created before this guard). String-level, so it can't defeat DNS
rebinding, but it blocks the direct-address cases. Unit-tested.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018sRFb1136YE8KDmDbFMYmm
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* fix(cloud): harden webhook SSRF guard
Two SSRF gaps in the Observability alert delivery path:
- deliverAlert followed webhook redirects, so a destination that passes
isSafeWebhookUrl could 3xx-redirect to an internal address (e.g. the
metadata IP). Set redirect: "manual" and reject 3xx responses.
- isSafeWebhookUrl let IPv4-mapped IPv6 (::ffff:169.254.169.254, which
the URL parser compresses to ::ffff:7f00:1) and the unspecified
address (::) through. Reject the whole ::-prefixed non-global class.
Numeric IPv4 forms (2130706433, 0x7f000001, 0177.0.0.1) were already
blocked via WHATWG URL normalization; added as regression tests.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017hfLmCwH5xMfz7L73LRPFj
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 7c630e6 commit 241c273
24 files changed
Lines changed: 5759 additions & 1355 deletions
File tree
- apps/cloud
- __tests__
- lunora
- _generated
- src
- client
- deploy
- mail
- telemetry
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
10 | 18 | | |
11 | 19 | | |
12 | 20 | | |
| |||
19 | 27 | | |
20 | 28 | | |
21 | 29 | | |
22 | | - | |
| 30 | + | |
23 | 31 | | |
24 | 32 | | |
25 | 33 | | |
| |||
37 | 45 | | |
38 | 46 | | |
39 | 47 | | |
40 | | - | |
| 48 | + | |
41 | 49 | | |
42 | 50 | | |
43 | 51 | | |
| |||
57 | 65 | | |
58 | 66 | | |
59 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
60 | 72 | | |
61 | 73 | | |
62 | 74 | | |
63 | | - | |
| 75 | + | |
64 | 76 | | |
65 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
66 | 82 | | |
67 | 83 | | |
68 | 84 | | |
| |||
93 | 109 | | |
94 | 110 | | |
95 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
96 | 115 | | |
97 | 116 | | |
98 | 117 | | |
| |||
0 commit comments