Skip to content

feat(agent): ship container logs to the control plane (part of #232) - #464

Merged
samuelmbabhazi merged 33 commits into
mainfrom
feat/232-log-shipper
Nov 25, 2026
Merged

samuelmbabhazi merged 33 commits into
mainfrom
feat/232-log-shipper

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

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 (feat(agent): read a container's log lines from a cursor (part of #232) #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:
  • go test ./agent/... and golangci-lint pass.

Security considerations

#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]>
Create, start with the daemon's hijacked connection, resize and inspect an exec. The multiplexed output is read frame by frame, refusing invalid headers and frames over 1 MiB. Tested against a fake daemon and a real Docker.

Signed-off-by: samuel mbabhazi <[email protected]>
The agent validates the session (managed container, bounded argv, user, time limit), opens an ExecStream on the current gateway session, and relays stdin, resizes and close to Docker, output and the exit code back. A session never resumes after a restart.

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]>
Follows Docker's logs API with timestamps from a time on, joins the lines Docker split, cuts them at 16 KiB, replaces invalid UTF-8 and drops frames without a timestamp. Refuses a container with a terminal. Tested against a fake daemon and a real Docker.

Signed-off-by: samuel mbabhazi <[email protected]>
…ag, and end with their context

From review: Docker's default detach sequence is replaced by one a terminal user does not type; CreateExec returns the instance with its terminal flag, which StartExec repeats; the start's context bounds the session; Next returns at most max bytes in both modes and refuses no room; errors keep their cause.

Signed-off-by: samuel mbabhazi <[email protected]>
From review: the action now ends once the session started, and the session runs under an owner the gateway closes, outside the journal's one step at a time. A stalled stream no longer outlives the time limit, the owner's close is told as closed, and stdin in flight after its close is dropped instead of killing the session.

Signed-off-by: samuel mbabhazi <[email protected]>
Signed-off-by: samuel mbabhazi <[email protected]>

# Conflicts:
#	agent/internal/actions/docker.go
#	agent/internal/agent/gateway.go
…gin/feat/232-ship-logs-proto' into feat/232-log-shipper
…nowledged batches (part of #232)

ADR 0029: on a ShipLogs stream opened after Welcome, the agent follows each running managed container from its cursor, redacts its secret variables (named by a new sk.secret_env label), sends batches of at most 256 entries and 60 KiB with four in flight, and moves each container's cursor only once the control plane acknowledged its batch. A failed stream is opened again.

Signed-off-by: samuel mbabhazi <[email protected]>
Docker orders stdout and stderr by timestamp, and two writes in the same instant can come out either way, as CI showed.

Signed-off-by: samuel mbabhazi <[email protected]>
…232-log-shipper

Signed-off-by: samuel mbabhazi <[email protected]>

# Conflicts:
#	agent/internal/actions/exec.go
#	agent/internal/actions/exec_test.go
#	agent/internal/agent/gateway.go
#	agent/internal/gateway/streams.go
@coderabbitai

coderabbitai Bot commented Nov 25, 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 46 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 c16d838 and 7ea7cd7.

Files selected for processing: 14

  • .github/workflows/ci.yml
  • agent/internal/actions/container_spec.go
  • agent/internal/actions/container_test.go
  • agent/internal/agent/gateway.go
  • agent/internal/docker/containers.go
  • agent/internal/gateway/runner.go
  • agent/internal/gateway/streams.go
  • agent/internal/journal/state.go
  • agent/internal/journal/state_test.go
  • agent/internal/logship/real_shipper_test.go
  • agent/internal/logship/redact.go
  • agent/internal/logship/redact_test.go
  • agent/internal/logship/shipper.go
  • agent/internal/logship/shipper_test.go
  • 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

@samuelmbabhazi
samuelmbabhazi changed the base branch from feat/232-docker-logs to main November 25, 2026 10:32
@samuelmbabhazi
samuelmbabhazi merged commit c3cec1f into main Nov 25, 2026
25 of 27 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/232-log-shipper branch November 25, 2026 11:35
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