Repository navigation
feat(api): search an application's logs (part of #232) - #463
Merged
Merged
Conversation
#232) The maintainer chose a dedicated ShipLogs stream, as for metrics (ADR 0024): no published port, agent credential or agent label to trust. Acknowledged batches and a cursor per container let logs survive a control plane outage within Docker's rotation; the agent redacts secret environment values first. Signed-off-by: samuel mbabhazi <[email protected]>
ADR 0029: LogsOpen with the lease epoch, LogBatch of entries (container, stream, Docker time, line, truncated) acknowledged by sequence number, and Welcome.logs. ConfigUpdate.logs_endpoint is deprecated. Signed-off-by: samuel mbabhazi <[email protected]>
ShipLogs on the gateway checks the open's lease epoch and the batches' order, and acknowledges each one once VictoriaLogs kept it. Lines are labelled from the node's placed allocations only, malformed entries are dropped, and each node writes at most 512 KiB/s with 4 MiB bursts. VICTORIALOGS_URL is now optional; Welcome.logs says whether logs are kept. Signed-off-by: samuel mbabhazi <[email protected]>
GET …/applications/{id}/logs reads VictoriaLogs with a LogsQL query whose filters come from validated identifiers and whose text is one quoted phrase; it answers the lines newest first, at most 500, over 30 days at most, and kept: false without a log store.
Signed-off-by: samuel mbabhazi <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 31 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Signed-off-by: samuel mbabhazi <[email protected]>
Signed-off-by: samuel mbabhazi <[email protected]> # Conflicts: # docs/SPEC.md
Signed-off-by: samuel mbabhazi <[email protected]>
Signed-off-by: samuel mbabhazi <[email protected]> # Conflicts: # docs/SPEC.md
Signed-off-by: samuel mbabhazi <[email protected]>
Signed-off-by: samuel mbabhazi <[email protected]>
Signed-off-by: samuel mbabhazi <[email protected]>
Signed-off-by: samuel mbabhazi <[email protected]> # Conflicts: # apps/api/src/modules/fleet/fleet.module.ts
Signed-off-by: samuel mbabhazi <[email protected]> # Conflicts: # apps/api/src/modules/observability/domain/logs.spec.ts # docs/SPEC.md # docs/generated/route-role-matrix.md # packages/api-client/src/gen/openapi.ts
… and keep nanoseconds Signed-off-by: samuel mbabhazi <[email protected]>
Collaborator
Author
|
An independent review of this PR (high effort, while CodeRabbit is rate limited) raised eight points. All eight held up; 8e5e0d3 and 224a877 fix them.
SPEC 12 describes the substring, |
Signed-off-by: samuel mbabhazi <[email protected]> # Conflicts: # apps/api/src/modules/observability/application/logs-ingest.spec.ts # apps/api/src/modules/observability/application/logs-ingest.ts # apps/api/src/modules/observability/application/ports.ts # apps/api/src/modules/observability/domain/logs.spec.ts # apps/api/src/modules/observability/domain/logs.ts # apps/api/src/modules/observability/infrastructure/victoria-logs.store.spec.ts # apps/api/src/modules/observability/infrastructure/victoria-logs.store.ts # apps/api/src/modules/observability/observability.module.ts # docs/SPEC.md
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 25, 2026
…464) Part of #232 (M6.1). The agent side of ADR 0029: it follows every managed container's output and sends it to the control plane on the `ShipLogs` stream, which #461 writes to VictoriaLogs. Stacked on #459 (the Docker logs reader). Retarget to `main` once #459 is merged. ## What changed - **`agent/internal/logship`**: the shipper. - It follows every running container labelled `sk.managed`, from that container's cursor, and rescans every 10 s for new ones. A follower that ends is started again on the next scan, including when the daemon restarts with live-restore. - Lines go out in batches of at most 256 entries and 60 KiB, flushed every second. At most 4 batches wait for their acknowledgement. - When a batch is acknowledged, the cursor of each container in it moves to that batch's last `LogLine.Resume`. `Resume` is the time from which reading again loses nothing, even while a line of the other stream is still being joined (#459). Lines therefore arrive at least once, and none is lost while Docker still holds it. - **Redaction** (`redact.go`): the values of the container's secret environment variables of 8 bytes or more become `[redacted]` before a line leaves the agent, longest first. Their names come from the new `sk.secret_env` label, and their values from the container's own environment. A redacted line is cut again to 16 KiB. - **`actions`**: `CreateContainer` sets `sk.secret_env`, the sorted names of the spec's secrets. Names are not secret. - **`journal`**: a `log_cursors` table, keyed by container name. A cursor only moves forward, and those of containers that are gone are forgotten. - **`gateway`**: `Streams.OpenLogs` opens the stream. The runner starts the shipper with the session's lease epoch once Welcome says logs are kept, and stops it with the session. A failed stream is retried after 5 s. - **CI**: the integration job also runs `./agent/internal/logship/`. ## How it was tested - Unit tests: batching and bounds, acknowledgements that move cursors only once kept, out-of-order or unexpected answers ending the stream, redaction (short values left alone, overlapping values, the cut after redaction), and cursor storage. - `TestRealShipperSendsAContainersRedactedLinesAndKeepsItsCursor` runs against a real Docker Engine: a busybox container prints a secret on stderr, which arrives as `token is [redacted]`, and the cursor is stored. It now checks only its own container, so it also passes on an engine that runs other managed containers (it did, in the lab node). - **Lab**, agent `0.1.0-lab.27` from this branch on a node with an nginx application: - lines printed before, during and after an agent restart all reached VictoriaLogs and were found by the API's search; - the last acknowledged line came once more after the restart, as at-least-once allows; #463 shows it once. - `go test ./agent/...` and golangci-lint pass. ## Security considerations - Container output is untrusted. Lines are bounded by #459 and by the batch limits. The control plane validates every entry and sets every label itself, so an agent can only write lines for its own placed containers (#461). - Secret values are read from the container's environment for redaction only. They are never logged, stored or sent. Secrets mounted as files, and values an application derives from a secret, are not redacted. ADR 0029 and THREAT_MODEL say so. - No new action and no new shell invocation. The shipper uses Docker's logs and inspect APIs only. --------- Signed-off-by: samuel mbabhazi <[email protected]>
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 25, 2026
… (part of #232) (#468) Part of #232 (M6.1); closes #477: the application page's Logs and Terminal tabs on real data, replacing the samples they showed. Stacked on #457, the exec WebSocket; retarget to `main` once #457 is merged. The maintainer validated the screens on desktop and phone on 2026-11-25, from captures of a lab installation. ## What changed - **Logs tab** (`logs-panel.ts`, `logs-view.ts`): - the replicas' output, newest first, from `GET …/applications/{id}/logs` (#463); - filters All, stdout and stderr, and a text search (a substring, matched with its case); - a live view that asks again every 3 s while the tab is shown, and not at all without a log store. It reads forward from shortly before its newest line, oldest first, page after page (`order=oldest`, up to 5 pages a tick), so a burst between two ticks is not skipped. Each tick waits for the previous read to end. - Lines are merged without repeats. Times are shown in the viewer's time zone. On a phone, the time, replica and stream sit above the line at full width. - An installation without a log store says that it keeps no logs. - **Terminal tab** (`terminal-panel.ts`, `terminal-view.ts`): - a command line in the first replica (r0), over the exec WebSocket (`/api/v1/exec/{id}`, #457): Connect, then one command per line; - output bounded: a line keeps its first 4096 characters and is marked with ` …` past them, dropping the rest up to its newline, and the screen keeps at most 2000 lines and 1 Mi characters, the newest first (#477); - stdout and stderr shown apart, stderr in rose, and Disconnect; - the notice that the session is recorded in the audit log and that no SSH port is open. - **Shared tab bar** (`shell/tabs.ts`): on a narrow screen it scrolls to keep the open tab in view, for example when a link opens `?tab=terminal`. - **CSP**: `connect-src` adds `wss://` for the API's own host only (`socketOrigin()`), so the terminal's WebSocket can connect. - **`DeliveryApi`** gains `logs()` and `openExecSession()`. French translations are in `fr.ts`. - **API, logs route** (found in review): `from` written in UTC with up to nine digits of fraction now goes into the LogsQL query as written (`fromExact`), so a live view can read forward from a line's exact time. A `Date` cut it to milliseconds and stalled on bursts. - **After review:** - each live read starts three seconds before the newest line, so lines another server sent late still show; - only a submitted search applies; - a terminal left while connecting joins nothing; - the header reads "shell connected", the one text change from the validated captures. ## How it was tested - Web unit tests (55 files): log merging, keys, times, the forward reading (page after page from the last line, its bound, and a full page that does not move), terminal frames, and the tab bar's scroll. - `nx typecheck lint test` for web and API, and the browser suite (Chromium against the production build, 28 tests), which enforces the CSP. - **Lab** (control plane 0.1.0-lab.26, agent 0.1.0-lab.27, an nginx application): - the Logs tab showed the replica's real lines, and the search found them; - the Terminal ran `echo`, `ls` and `nginx -v` in the container, with stderr apart. ## Security considerations - The terminal goes through the agent and its typed exec action, and it is audited, as #455 to #457 describe. No new route. - The CSP opens WebSockets to the API's own origin only. - Log lines arrive already redacted by the agent (ADR 0029). The panel renders them as text and never as HTML. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added live application logs with stream filters, text search, pause/resume, and retryable error handling. * Added an interactive terminal for running commands in an application replica. * Kept the active tab visible when navigating a narrow tab bar. * **Bug Fixes** * Improved log updates to include recently delayed entries and support precise UTC time filters. * Allowed WebSocket connections from the configured public URL. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: samuel mbabhazi <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #232 (M6.1). This is the read side of ADR 0029: searching an application's logs. It is stacked on #461, which writes them. The web UI comes next.
What changed
GET …/applications/{applicationId}/logs(environment.read, sessions and API tokens).text: at most 256 characters, a phrase the lines contain;stream:stdoutorstderr;instance: the replica;fromandto: the last hour by default, and a period of 30 days at most, starting before it ends;limit: 200 by default, 500 at most.kept, false without a log store;lines, newest first, each withtime,stream,instance,lineandtruncated.The live view asks again from its newest line's time.
logsQuery(domain, pure):organdapp, the labels the control plane wrote (feat(api): write agents' log batches to VictoriaLogs (part of #232) #461), from identifiers it validates as UUIDs._time:[from, to], the stream and the instance, then the text as one quoted phrase: backslashes and quotes escaped, control characters removed.| sort by (_time desc) | limit n.logLineOfreads back only well-formed records.VictoriaLogsStore.querycalls/select/logsql/query.503"Logs temporarily unavailable.", never the store's text.LogsQuerieschecks the permission and that the application exists in its environment, then searches.Generated
openapi.json, API client and route-role matrix. SPEC 12: the route.How it was tested
" | delete, a backslash before a quote, newlines and NUL, and} {org="other"};kept: falsewithout a store; an unknown application or no permission gives 404.nx run-many -t typecheck lint -p apipasses, and the 53 observability tests pass.Security considerations