Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json output of podman ps lacks a human-readable time of creation #6594

Closed
HarryMichal opened this issue Jun 12, 2020 · 9 comments
Closed

Json output of podman ps lacks a human-readable time of creation #6594

HarryMichal opened this issue Jun 12, 2020 · 9 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@HarryMichal
Copy link
Member

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

Json output of podman ps lacks a field with a human-readable time of the creation of the container. This string used to be (in Podman V1) in the Created field and the time used to be in the CreatedAt field.

From looking at the code the json-formated output is printed before the string is created (the string in fact is created but only for the default output).

Steps to reproduce the issue:

  1. Have at least one container on a machine
  2. podman ps -a --format json (Podman V2)
  3. podman ps -a --format json (Podman V1)
  4. Compare the two outputs

Describe the results you received:

Json-formated info about a container without a field with a human-readable time of creation.

Describe the results you expected:

Json-formated info about a container with a field with a human-readable time of creation.

Additional information you deem important (e.g. issue happens only occasionally):

Part of output of podman ps -a --format json with podman-1.9.3-1.fc31.x86_64:

{
          "ID": "4878022abe7a",
          "Image": "registry.fedoraproject.org/f31/fedora-toolbox:31",
          "ImageID": "64e68e194389",
          "Command": "toolbox --verbose...",
          "Created": "7 minutes ago",
          "Ports": "",
          "Names": "fedora-toolbox-31",
          "IsInfra": false,
          "Status": "Created",
          "State": 1,
          "Pid": 0,
          "Size": null,
          "Pod": "",
          "PodName": "",
          "CreatedAt": "2020-05-14T17:32:51.897587288+02:00",
          "ExitedAt": "0001-01-01T00:00:00Z",
          "StartedAt": "0001-01-01T00:00:00Z",
          "Labels": {
               "architecture": "x86_64",
               "authoritative-source-url": "registry.fedoraproject.org",
               "build-date": "2020-02-28T01:55:06.444991",
               "com.github.containers.toolbox": "true",
               "com.github.debarshiray.toolbox": "true",
               "com.redhat.build-host": "osbs-node02.phx2.fedoraproject.org",
               "com.redhat.component": "fedora-toolbox",
               "distribution-scope": "public",
               "license": "MIT",
               "maintainer": "Debarshi Ray \[email protected]\u003e",
               "name": "f31/fedora-toolbox",
               "release": "9",
               "summary": "Base image for creating Fedora toolbox containers",
               "usage": "This image is meant to be used with the toolbox command",
               "vcs-ref": "c771d69fe6038dc613950610282a515649e713d2",
               "vcs-type": "git",
               "vendor": "Fedora Project",
               "version": "31"
          },
          "PID": "",
          "Cgroup": "",
          "IPC": "",
          "MNT": "",
          "NET": "",
          "PIDNS": "",
          "User": "",
          "UTS": "",
          "Mounts": "/run/dbus/system_bus_socket /run/.heim_org.h5l.kcm-socket /run/user/1000 /usr/bin/toolbox /run/host/usr /run/host/etc /run/host/monitor /run/media /etc/profile.d/toolbox.sh /home/harry /dev /mnt /media /run/host/var /run/host/tmp /run/host/run"
}

Part of output of podman ps -a --format json with podman-2.0.0-rc5.fc32.x86_64:

{
    "Command": [
      "toolbox",
      "--log-level",
      "debug",
      "init-container",
      "--home",
      "/home/omichal",
      "--monitor-host",
      "--shell",
      "/bin/bash",
      "--uid",
      "1000",
      "--user",
      "omichal",
      "--home-link"
    ],
    "Created": 1588259467,
    "Exited": true,
    "ExitedAt": 1591977675,
    "ExitCode": 143,
    "Id": "b0ff4cefca84ec4d92799d52b0434ce676524aaf57d7539501018c8c9d254aa6",
    "Image": "registry.fedoraproject.org/f32/fedora-toolbox:32",
    "ImageID": "f7cf4b593fc1cd042b917d9d91ad66ecaeadd503328a420ecfedfaf4d06effd2",
    "IsInfra": false,
    "Labels": {
      "architecture": "x86_64",
      "authoritative-source-url": "registry.fedoraproject.org",
      "build-date": "2020-03-12T05:28:10.440778",
      "com.github.containers.toolbox": "true",
      "com.github.debarshiray.toolbox": "true",
      "com.redhat.build-host": "osbs-node01.phx2.fedoraproject.org",
      "com.redhat.component": "fedora-toolbox",
      "distribution-scope": "public",
      "license": "MIT",
      "maintainer": "Debarshi Ray \[email protected]\u003e",
      "name": "f32/fedora-toolbox",
      "release": "4",
      "summary": "Base image for creating Fedora toolbox containers",
      "usage": "This image is meant to be used with the toolbox command",
      "vcs-ref": "fccc0ad0cfa9f41a932d088ccbd53f4778ebe464",
      "vcs-type": "git",
      "vendor": "Fedora Project",
      "version": "32"
    },
    "Mounts": [
      "/run/user/1000",
      "/var/home/omichal",
      "/run/host/monitor",
      "/run/media",
      "/run/host/tmp",
      "/media",
      "/run/dbus/system_bus_socket",
      "/run/host/var",
      "/run/host/etc",
      "/etc/profile.d/toolbox.sh",
      "/mnt",
      "/run/host/run",
      "/usr/bin/toolbox",
      "/run/.heim_org.h5l.kcm-socket",
      "/dev",
      "/run/host/usr"
    ],
    "Names": [
      "fedora-toolbox-32"
    ],
    "Namespaces": {
      
    },
    "Pid": 0,
    "Pod": "",
    "PodName": "",
    "Ports": null,
    "Size": null,
    "StartedAt": 1590852277,
    "State": "exited"
}

Output of podman version:

Version:      2.0.0-rc5
API Version:  1
Go Version:   go1.14.3
Built:        Thu Jan  1 01:00:00 1970
OS/Arch:      linux/amd64

Output of podman info --debug:

host:
  arch: amd64
  buildahVersion: 1.15.0-dev
  cgroupVersion: v2
  conmon:
    package: conmon-2.0.17-1.fc32.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.0.17, commit: bb8e273f5925c1a51737644637ef65d094a67ab1'
  cpus: 8
  distribution:
    distribution: fedora
    version: "32"
  eventLogger: file
  hostname: harry-work
  idMappings:
    gidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
    uidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
  kernel: 5.6.16-300.fc32.x86_64
  linkmode: dynamic
  memFree: 319549440
  memTotal: 16655806464
  ociRuntime:
    name: crun
    package: crun-0.13-2.fc32.x86_64
    path: /usr/bin/crun
    version: |-
      crun version 0.13
      commit: e79e4de4ac16da0ce48777afb72c6241de870525
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +YAJL
  os: linux
  remoteSocket:
    exists: true
    path: /run/user/1000/podman/podman.sock
  rootless: true
  slirp4netns:
    executable: /usr/bin/slirp4netns
    package: slirp4netns-1.0.0-1.fc32.x86_64
    version: |-
      slirp4netns version 1.0.0
      commit: a3be729152a33e692cd28b52f664defbf2e7810a
      libslirp: 4.2.0
  swapFree: 8406429696
  swapTotal: 8413769728
  uptime: 1h 17m 49.68s (Approximately 0.04 days)
registries:
  search:
  - registry.fedoraproject.org
  - registry.access.redhat.com
  - registry.centos.org
  - docker.io
store:
  configFile: /var/home/omichal/.config/containers/storage.conf
  containerStore:
    number: 12
    paused: 0
    running: 1
    stopped: 11
  graphDriverName: overlay
  graphOptions:
    overlay.mount_program:
      Executable: /usr/bin/fuse-overlayfs
      Package: fuse-overlayfs-1.0.0-1.fc32.x86_64
      Version: |-
        fusermount3 version: 3.9.1
        fuse-overlayfs: version 1.0.0
        FUSE library version 3.9.1
        using FUSE kernel interface version 7.31
  graphRoot: /var/home/omichal/.local/share/containers/storage
  graphStatus:
    Backing Filesystem: extfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Using metacopy: "false"
  imageStore:
    number: 10
  runRoot: /run/user/1000/containers
  volumePath: /var/home/omichal/.local/share/containers/storage/volumes
version:
  APIVersion: 1
  Built: 0
  BuiltTime: Thu Jan  1 01:00:00 1970
  GitCommit: ""
  GoVersion: go1.14.3
  OsArch: linux/amd64
  Version: 2.0.0-rc5

Package info (e.g. output of rpm -q podman or apt list podman):

podman-2.0.0-rc5.fc32.x86_64

Additional environment details (AWS, VirtualBox, physical, etc.):

Fedora Silverblue 32

@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Jun 12, 2020
@rhatdan
Copy link
Member

rhatdan commented Jun 13, 2020

Interested in opening a PR to fix this issue?

@HarryMichal
Copy link
Member Author

Yeah, sure. I'll do it when I can.

@baude
Copy link
Member

baude commented Jun 15, 2020

this is already fixed upstream in master. closing ....


    {
        "Id": "56cbd47d116aaa366db4005d4d2da202c5b8d570972faecbf4b51672ba600f06",
        "Created": "2020-06-15T14:16:54.865835174-05:00",
        "Path": "top",
        "Args": [
            "top"
...

@baude baude closed this as completed Jun 15, 2020
@HarryMichal
Copy link
Member Author

this is already fixed upstream in master. closing ....


    {
        "Id": "56cbd47d116aaa366db4005d4d2da202c5b8d570972faecbf4b51672ba600f06",
        "Created": "2020-06-15T14:16:54.865835174-05:00",
        "Path": "top",
        "Args": [
            "top"
...

Ah! I just realized that the output you're mentioning ^ is from podman inspect --type container but this issue is about podman ps.

Before V2 the key Created held strings like this: 7 minutes ago and CreatedAt held values like 2020-05-14T17:32:51.897587288+02:00 (as the key Created in your snipper).

I'll try to put together a PR.

@HarryMichal
Copy link
Member Author

HarryMichal commented Jun 19, 2020

Snipper of conversation with @baude on IRC:

baude:
i could make an arguement that json has no requirement to be human-readable.
and if it is json being slurped by go, it would be trivial to convert that
harrymichal, what do you think

harrymichal:
fair enough, my argument is mainly based on the fact that in V1 that field was a string holding the human-readable time
which is no longer the case in V2

I spent some time hacking on the code of listing of images + containers (commands podman ps and podman images) and there's a bit of a difference between them:

podman ps does not make an opinion about the JSON output and just formats the data and prints.

podman images makes an opinion about the JSON output -> one field is altered (Created) and one added (CreatedAt). Created originally holds time using Golang's time format (time.RFC3339Nano), after formating it's the human-readable string (e.g., "5 minutes ago"). CreatedAt holds the value that was originally in Created (time.RFC3339Nano).

So my question here is, how this should be handled. Either do it the way it is done in podman images -> have an opinion and inject the data or print it raw like in podman ps.

EDIT: Based on @baude's answer on IRC I'd say the approach in podman ps is the right one.

@baude
Copy link
Member

baude commented Jun 19, 2020

What I was trying to express is that JSON is not typically meant for human consumption. Given that you are ingesting this straight into go, a conversion should be trivial. Whereas having it human readable makes the conversion more difficult and loses precision.

@debarshiray
Copy link
Member

Toolbox consumes the JSON emitted by Podman. Whenever the JSON changes in subtly incompatible ways it breaks something. eg., when the id and names fields changed to ID and Names in Podman 1.8.3.

Similarly, in this case about Created and CreatedAt, where the former changed semantics and the latter is no longer there.

We can handle things by adding version checks and otherwise adjusting the Toolbox code, but in general it would be nice if the JSON didn't keep changing.

@baude
Copy link
Member

baude commented Jun 19, 2020

this is a major version change hence our excuse to do so.

@baude
Copy link
Member

baude commented Jun 19, 2020

submit a pr, we can review it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

No branches or pull requests

5 participants