You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docker service logs <service> does not return results in chronological order.
Reproduce
Run docker service logs --timestamps <service>.
Example output:
2024-04-02T02:22:14.799036157Z service | bad service
2024-04-02T02:23:06.141097002Z service | bad service
2024-04-02T02:22:48.642065164Z service | good service
2024-04-02T02:22:14.799081539Z service | bad service
2024-04-02T02:23:07.541907132Z service | bad service
2024-04-02T02:22:20.755475776Z service | bad service
Expected behavior
The expected results from the command is to see log results in chronological order as determined by their timestamps.
Showing log results in non-chronological order can be highly distracting during debugging, as something that may appear to be a fault has already been resolved, except that the erroneous condition is being shown last in the log output.
Although the docker internals may store the log results in non-chronological order, the docker cli should have the functionality to perform sorting of log results before/while displaying them.
The docker cli should have the sorting functionality built-in, either as default or behind a flag. It should not be necessary to patch the docker cli using shell functions to achieve this functionality.
All relevant log commands should be updated with the same functionality.
docker version
Client: Docker Engine - Community
Version: 26.0.0
API version: 1.45
Go version: go1.21.8
Git commit: 2ae903e
Built: Wed Mar 20 15:17:48 2024
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 26.0.0
API version: 1.45 (minimum version 1.24)
Go version: go1.21.8
Git commit: 8b79278
Built: Wed Mar 20 15:17:48 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.28
GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
runc:
Version: 1.1.12
GitCommit: v1.1.12-0-g51d5e94
docker-init:
Version: 0.19.0
GitCommit: de40ad0
I'm not sure if this is possible to fix, or at least this would require careful consideration; when running swarm services, those services are distributed in the cluster, and may be running on different nodes. In addition, the logs printed can originate from STDOUT and STDERR, one of which is buffered, the other is not; for the latter one there's a (still open) ticket; moby/moby#31706
The docker service logs will print such logs when they arrive which, in a distributed system, may mean that log entries from different nodes may arrive at different moment. So to sort these log entries, all log-entries would have to be buffered before they can be sorted, which would only be possible in the "one-off" (without --follow) case, and in that case would still have a potential of requiring a large amount of memory to be used (buffering all log entries). For the --folow case, things will be more complicated, as there's no real way to predict when new log-entries arrive (if any) from all instances of a service.
For debugging purposes, you could consider using sort to sort the output to see if that addresses your immediate issue;
docker service logs --timestamps myservice 2>&1| sort
Description
docker service logs <service>
does not return results in chronological order.Reproduce
docker service logs --timestamps <service>
.Example output:
Expected behavior
The expected results from the command is to see log results in chronological order as determined by their timestamps.
docker version
Client: Docker Engine - Community Version: 26.0.0 API version: 1.45 Go version: go1.21.8 Git commit: 2ae903e Built: Wed Mar 20 15:17:48 2024 OS/Arch: linux/amd64 Context: default Server: Docker Engine - Community Engine: Version: 26.0.0 API version: 1.45 (minimum version 1.24) Go version: go1.21.8 Git commit: 8b79278 Built: Wed Mar 20 15:17:48 2024 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.28 GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb runc: Version: 1.1.12 GitCommit: v1.1.12-0-g51d5e94 docker-init: Version: 0.19.0 GitCommit: de40ad0
docker info
Additional Info
No response
The text was updated successfully, but these errors were encountered: