feat(logs): accept Docker-compatible timestamp filters#1765
Open
stephenlclarke wants to merge 14 commits into
Open
feat(logs): accept Docker-compatible timestamp filters#1765stephenlclarke wants to merge 14 commits into
stephenlclarke wants to merge 14 commits into
Conversation
…ient.logs
Adds an additive overload to ContainerClient.logs that accepts a
ContainerLogOptions { since: Date?, timestamps: Bool } and plumbs the
two parameters through XPC into the daemon's existing log-handle path.
Motivation
----------
External orchestrators that drive the API server (the canonical use
case is a Compose-spec orchestrator implementing 'compose logs --since
<timestamp>' and '--timestamps') need to retrieve only recent log
output and optionally annotate lines with timestamps. Today
ContainerClient.logs(id:) returns raw containerLog + bootlog file
handles unconditionally; consumers either replay the entire log buffer
or implement their own line-by-line filter on the client. Surfacing
the parameters at the API boundary keeps the line scanning where the
file lives — server-side — and matches the docker-compose UX users
expect.
What this PR changes
--------------------
- Sources/ContainerResource/Container/ContainerLogOptions.swift (new):
the ContainerLogOptions struct, Sendable + Codable, with a static
'.default' equivalent to the original logs(id:) zero-config call.
- Sources/Services/ContainerAPIService/Client/XPC+.swift: two new
XPCKeys cases ('logSince', 'logTimestamps') for the optional
parameters.
- Sources/Services/ContainerAPIService/Client/ContainerClient.swift:
new logs(id:options:) overload. The existing logs(id:) is retained
as a thin wrapper over .default for source compatibility.
- Sources/Services/ContainerAPIService/Server/Containers/ContainersService.swift:
matching logs(id:options:) overload; when options.since is provided,
applies a private 'filterFileHandleSince' that parses ISO-8601
timestamps from line starts and drops older lines (lines without a
parseable timestamp pass through unchanged).
- Sources/Services/ContainerAPIService/Server/Containers/ContainersHarness.swift:
parses the two optional XPC keys, builds ContainerLogOptions, and
forwards to the new service overload.
Wire compatibility
------------------
XPC calls without the new keys decode as 'sinceRaw.timeIntervalSince1970
== 0' (the harness treats this as 'no since filter') and 'timestamps =
false', so older clients hitting a newer server see unchanged behavior.
Newer clients hitting an older server send the keys; an old harness
will silently drop them and run the original codepath.
Known limitations (intentional, follow-up work)
-----------------------------------------------
- The 'options.timestamps' parameter is plumbed end-to-end but the
daemon does not currently decorate raw log lines that lack a
timestamp prefix. Line decoration is a deliberate follow-up; keeping
the parameter on the API surface today avoids a second wire-format
break later.
- 'filterFileHandleSince' currently slurps the file into memory then
returns a Pipe-backed FileHandle. For the typical container log
size this is fine; for very large logs a streaming line iterator
would be a worthwhile optimization. Filed as a known-issue for the
follow-up timestamp-decoration PR.
Verification
------------
Full 'swift build' clean on macOS 26 / Apple silicon (release config,
all targets including downstream consumers of ContainerClient.logs).
7 tasks
c4e1989 to
9c5df9d
Compare
6f0dd14 to
7ab07bd
Compare
7ab07bd to
6d09d2d
Compare
6d09d2d to
3273286
Compare
3273286 to
d61e4a3
Compare
d61e4a3 to
f0673cb
Compare
f0673cb to
b3929ca
Compare
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.
Type of Change
Motivation and Context
This is a draft stacked follow-up to #1592 and #1764. Once log retrieval filters are exposed through
ContainerLogOptions, the CLI should accept the timestamp forms users expect from Docker-compatible log commands instead of only accepting RFC 3339 values.Docker-compatible log workflows commonly use Unix timestamps, fractional Unix timestamps, and relative Go-style durations such as
1m30s. External orchestrators need the same parser behavior as thecontainer logsCLI, so this draft moves timestamp parsing intoContainerResourceas a small reusable helper rather than leaving ad hoc parsing in the command layer.Draft/stacking note: this branch is based on the updated
logs-tail-until-optionsbranch from #1764, which is itself based on #1592. Because GitHub PRs toapple/containertargetmain, this diff includes #1592 and #1764. The intended review delta for this draft is:d7cc54c feat(logs): accept docker-compatible timestampseaf8fce test(logs): cover relative timestamp argumentsfdb387e fix(logs): parse date-only filters in local timeb3929ca fix(logs): accept signed relative durationsWhat Changed
ContainerLogTimestampParserinContainerResource.1m30s,250ms, and1.5h.+1s,-1s, and-.5h.container logs --sinceand--untilargument parsing to use the shared parser.docs/command-reference.md.Relationship to Existing Work
tail/untilretrieval filter surface.container logsbehavior; no Compose-specific behavior is included.Non-Goals
ns,us/µs/μs,ms,s,m, andh.Testing
Local verification:
Result: focused validation passed locally. The focused tests ran 31 tests across
ContainerLogsCommandTests,ContainerLogsTests, andContainerLogOptionsTests.