Skip to content

feat(proto): the ShipLogs stream and its batches (part of #232) - #458

Merged
samuelmbabhazi merged 4 commits into
mainfrom
feat/232-ship-logs-proto
Nov 24, 2026
Merged

samuelmbabhazi merged 4 commits into
mainfrom
feat/232-ship-logs-proto

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Part of #232 (M6.1). This is the contract of ADR 0029, stacked on #452, the ADR itself. The agent's reader and stream, and the gateway's writer to VictoriaLogs, follow in their own PRs.

What changed

  • proto/shipkeep/agent/v1/logs.proto.
    • ShipLogsRequest is LogsOpen{lease_epoch}, then LogBatches.
    • A LogBatch has a seq starting at 1 and its entries.
    • A LogEntry has the container name, a LogStream (stdout or stderr), Docker's timestamp, the line (at most 16 KiB, UTF-8, redacted) and truncated.
    • ShipLogsResponse is LogAck{seq}.
  • gateway.proto.
    • rpc ShipLogs(stream ShipLogsRequest) returns (stream ShipLogsResponse).
    • Welcome.logs: the control plane keeps logs, so the agent opens the stream.
    • ConfigUpdate.logs_endpoint is marked deprecated, since the direct push is gone. It was never set.
  • Generated Go and TypeScript code (pnpm gen), and the proto-ts export.

Why

ADR 0029: a dedicated stream beside Connect, not an action, so the closed action list is unchanged. With acknowledged batches, the agent can keep a cursor and resend after an outage.

How it was tested

  • buf lint passes.
  • buf breaking against main passes: the change only adds an RPC, messages and a field.
  • go build ./agent/... ./lib/... ./cli/... and the API typecheck pass.
  • Nothing uses the new messages yet. Without a handler, the API's gateway answers ShipLogs with Unimplemented, and the agent opens it only when Welcome.logs is true, which nothing sets yet.

Security considerations

  • The agent's container name is only a key: the control plane maps it to an allocation and never writes it as a label (ADR 0029).
  • The bounds are stated in the proto and enforced by the next PRs: 256 entries and 60 KiB per batch, and 16 KiB per line.

#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]>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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 28 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 35d4a27 and 6f313cf.

Files ignored due to path filters: 5

  • lib/gen/shipkeep/agent/v1/gateway.pb.go is excluded by !**/*.pb.go, !**/gen/**, !lib/gen/**
  • lib/gen/shipkeep/agent/v1/gateway_grpc.pb.go is excluded by !**/*.pb.go, !**/gen/**, !lib/gen/**
  • lib/gen/shipkeep/agent/v1/logs.pb.go is excluded by !**/*.pb.go, !**/gen/**, !lib/gen/**
  • packages/proto-ts/src/gen/shipkeep/agent/v1/gateway_pb.ts is excluded by !**/gen/**, !packages/proto-ts/src/gen/**
  • packages/proto-ts/src/gen/shipkeep/agent/v1/logs_pb.ts is excluded by !**/gen/**, !packages/proto-ts/src/gen/**
Files selected for processing: 3

  • packages/proto-ts/src/index.ts
  • proto/shipkeep/agent/v1/gateway.proto
  • proto/shipkeep/agent/v1/logs.proto
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow proto / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed⏩ skippedNov 24, 2026, 9:57 PM

@samuelmbabhazi
samuelmbabhazi merged commit 8604249 into main Nov 24, 2026
26 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/232-ship-logs-proto branch November 24, 2026 22:12
samuelmbabhazi added a commit that referenced this pull request Nov 25, 2026
…461)

Part of #232 (M6.1): the control plane's half of ADR 0029. It is stacked
on #458 (the `ShipLogs` contract), which sits on #452 (the ADR). The
agent's shipper is the other half, in its own PR. VictoriaLogs joins the
Compose project in #460.

## What changed

- **Gateway, `ShipLogs`** (`fleet/interface/log-stream.ts`). It runs
behind the shared mTLS and database identity guard.
  - **Refusals:**
    - with no log store configured: `FAILED_PRECONDITION`;
- when the first frame is not `LogsOpen` with the node's current lease
epoch, read through `AuthenticateNode`: `FAILED_PRECONDITION`;
    - when batches are not numbered 1, 2, 3, …: `INVALID_ARGUMENT`.
- **Acknowledgement.** Each batch gets its `LogAck` only once the store
has kept it. A failed write ends the stream with `UNAVAILABLE` and no
acknowledgement, so the agent sends again from its cursor.
- **`Welcome.logs`** is true only when a store is registered.
- **`fleet/application/log-batches.ts`** is the hook the observability
module registers on, as `MetricsReports` is for metrics.
- **`observability`:**
  - **Domain, `domain/logs.ts`, pure:**
- entries are bounded: at most 256 per batch, a container name in the
agent's grammar, a valid time, a line of at most 16 KiB;
- labels come from the node's placed allocations: org, project, env,
app, instance (the replica), node and stream. A line of any other
container is dropped, and no name the agent sent becomes a label;
- a time more than 5 minutes from the control plane's clock is replaced
by it;
    - a per-node byte bucket allows 512 KiB/s with bursts of 4 MiB.
- **`LogsIngest`:** it registers only with a store, drops malformed
entries with a warning, maps containers in the tenant transaction, and
waits for the node's rate before writing.
- **`VictoriaLogsStore`:** `POST /insert/jsonline` with
`_stream_fields=org,app,instance,stream`, `_time_field` and
`_msg_field`, and a 10-second timeout. A failure never carries the
store's text.
- **Config:** `VICTORIALOGS_URL` is optional, as `VICTORIAMETRICS_URL`
is. The Compose file (#460) and `.env.example` set it.
- **SPEC 12:** the refusals and what is dropped.

## How it was tested

- **Domain:**
  - bounds and malformed entries;
- labels from the allocation, with the agent's container name absent
from the records;
  - the skew rule;
  - the token bucket.
- **Stream:**
  - in-order acknowledgements after the store kept each batch;
- a missing open, a stale epoch, out-of-order numbers and a second open
are refused;
  - no acknowledgement when the store fails;
  - the stream is refused without a store.
- **Ingest:** registration only with a store, labels and drops, waiting
past the rate, a store failure.
- **Store**, against a local HTTP server: the query and the JSON lines,
quotes and newlines included. A 500 fails without the server's text, and
no records means no request.
- `node-stream.spec.ts` passes the new dependency.
- `vitest --project api`: 764 tests pass, and ESLint is clean.

## Security considerations

- Tenant isolation rests on the certificate identity and the control
plane's records. An agent can only write lines for containers placed on
its own node, and every label is set here.
- The batch, line and rate bounds protect the API and VictoriaLogs from
a flooding agent: past its rate, a node waits instead of being dropped.
- Logs change no state, so nothing is audited, as for metrics (ADR
0024).

---------

Signed-off-by: samuel mbabhazi <[email protected]>
samuelmbabhazi added a commit that referenced this pull request Nov 25, 2026
#459)

Part of #232 (M6.1). The agent reads a container's log lines, which the
`ShipLogs` stream of ADR 0029 will send (#458 is the contract). This PR
is stacked on #453 and reuses its frame reader for Docker's multiplexed
stream.

## What changed

`docker.Client.FollowLogs(ctx, ref, since, emit)` is in
`agent/internal/docker/logs.go`.

- It reads `GET /containers/{ref}/logs` with `follow`, `stdout`,
`stderr`, `timestamps` and `since` (seconds and nanoseconds). It uses
the client without a response-header timeout, and returns when the
container stops (the output ends), when ctx ends, or when `emit` fails.
- A `LogLine` has its stream (stdout or stderr), Docker's timestamp and
the text without its newline (and a trailing `\r`). `Truncated` tells
whether the line was cut.
- Lines:
- **Split lines.** Docker splits lines longer than its 16 KiB buffer.
Each part has its own timestamp, and the line has the first one. Parts
are joined per stream, so stderr in between does not mix in.
- **Size.** A line is cut at 16 KiB on a character boundary, and sent as
soon as it is full: the rest, up to its newline, is dropped, so a
progress bar that never writes a newline still shows. Each byte that is
not UTF-8 becomes U+FFFD (ADR 0029), and the line is cut again on a rune
boundary if replacements made it longer. A line without a final newline
is emitted when the container stops.
- **Resume.** Each line carries `Resume`, the time to read again from
once it is kept: its own time, or the start of a line of the other
stream still being joined, whose first part reading from the later time
would lose.
  - **Several lines in one message** each keep the message's timestamp.
- Refusals:
  - A frame without a valid timestamp is dropped, never shown as a line.
- A container with a terminal is refused (`raw-stream`). The agent never
creates one, and its output does not tell the streams apart.
  - Errors carry the status only, never the daemon's text.

## How it was tested

- **Fake daemon:** the cases above, the `since` query, an oversized
frame, an `emit` that fails and stops the read, 404 and other statuses.
- **Real Docker 29,** `-tags integration`,
`TestRealFollowLogsResumesFromACursor`: a busybox container writes
`one`, `two` on stderr, a 20,000-byte line and `three`.
- All four lines arrive, and the long line is cut to exactly 16 KiB and
marked as cut.
- Following again from the long line's timestamp, as after an outage,
gives that line and `three`. That is the at-least-once delivery the ADR
describes.
- `golangci-lint` reports 0 issues, with and without the `integration`
tag.

## Security considerations

- Container output is untrusted. Frame sizes are bounded before
allocating (1 MiB, from #453), lines at 16 KiB, and the text is made
valid UTF-8 before it goes anywhere.
- Secret redaction (ADR 0029) comes with the shipping PR, which knows
the container's secret names.



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Added support for following Docker container logs, with stdout and
stderr lines, timestamps, and resume points.
* Long log lines are safely truncated, and incomplete lines are emitted
when the stream ends.
* **Bug Fixes**
* Improved error messages for Docker exec output and log streams,
including clearer handling of missing containers and interrupted reads.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: samuel mbabhazi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant