Commit 85be3d2
feat(logs): add admin aggregated logs endpoint (#12)
* feat(logs): add admin aggregated GET /logs endpoint
When admin calls GET /logs without X-App-ID, iterates all registered
apps from KV, queries each app's DO in parallel, and returns combined
log entries with app_id field on each entry.
Preserves existing single-app behavior when X-App-ID header is provided
(for both API key and admin auth paths).
Per-app limit is calculated as max(10, ceil(globalLimit / numApps)) to
avoid overloading any single DO. Results are merged, sorted by timestamp
DESC, and truncated to the global limit.
Also exports AggregatedLogEntry type (LogEntry + app_id) from types.ts
for consumers that need to type-check aggregated responses.
Co-Authored-By: Claude <noreply@anthropic.com>
* test(logs): add integration tests for admin aggregated logs
Tests cover:
- GET /logs with admin key and no X-App-ID returns combined entries
from all registered apps, each with an app_id field
- Level filter (e.g., ?level=ERROR) is forwarded to each app's DO
- Global limit (e.g., ?limit=2) caps the total results returned
- GET /logs with admin key AND X-App-ID falls through to single-app
path, returning raw DO response without app_id field
Adds beforeAll setup that creates two apps (agg-app-1, agg-app-2)
and writes distinct log levels to each so assertions can verify
cross-app aggregation.
Co-Authored-By: Claude <noreply@anthropic.com>
* test(aggregated-logs): add filter and auth tests for admin all-logs endpoint
Extend the "Admin aggregated logs" integration test suite with 7 new tests
that cover scenarios not already tested in Phase 1:
Auth edge cases:
- No auth (missing both X-Admin-Key and X-App-ID) returns 400
- Invalid admin key returns 401
Aggregated filter scenarios (new nested describe with isolated app fixtures):
- since=far-future timestamp returns empty array (filter applied per-app)
- until=far-past timestamp returns empty array
- search filter returns matching entries across multiple apps
- context.* filter returns entries with matching JSON context field
- request_id filter returns exactly the one matching entry with correct app_id
Each test verifies that app_id field is present on aggregated results and
that filters are correctly propagated to per-app DO queries.
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor(logs): simplify aggregated logs limit parsing and remove unused test variables
Replace verbose has/get/parseInt pattern with Number() + nullish fallback for
the globalLimit parameter. Remove dead-code queryString conditional since
perAppParams always contains at least the limit key. Remove unused
filterApiKey1/filterApiKey2 variables from test setup -- the filter tests
authenticate exclusively via admin key.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* use string comparison for sort
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>1 parent 1dc3f1d commit 85be3d2
3 files changed
Lines changed: 389 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 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 | + | |
105 | 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 | + | |
106 | 161 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
111 | 167 | | |
112 | 168 | | |
113 | 169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
112 | 119 | | |
113 | 120 | | |
114 | 121 | | |
| |||
0 commit comments