From 74c12aa42918e3f349afcb46e6e54b724ef789a9 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Thu, 4 Jun 2015 19:47:46 -0700 Subject: [PATCH] Default events since to current time Signed-off-by: Brian Goff --- api/server/server.go | 4 ++++ docs/man/docker-events.1.md | 4 ++++ docs/sources/reference/commandline/cli.md | 3 ++- integration-cli/docker_cli_events_test.go | 19 +++++++++++++------ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/api/server/server.go b/api/server/server.go index 3f5cc27c0b..d88a1d0882 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -395,6 +395,7 @@ func (s *Server) getEvents(version version.Version, w http.ResponseWriter, r *ht } until = u } + timer := time.NewTimer(0) timer.Stop() if until > 0 { @@ -453,6 +454,9 @@ func (s *Server) getEvents(version version.Version, w http.ResponseWriter, r *ht } current, l := es.Subscribe() + if since == -1 { + current = nil + } defer es.Evict(l) for _, ev := range current { if ev.Time < since { diff --git a/docs/man/docker-events.1.md b/docs/man/docker-events.1.md index 5e7f6e25fa..f854bbc1ad 100644 --- a/docs/man/docker-events.1.md +++ b/docs/man/docker-events.1.md @@ -76,7 +76,11 @@ relative to the current time on the client machine: 2015-05-12T15:53:45.999999999Z07:00 7805c1d35632: (from redis:2.8) die 2015-05-12T15:54:03.999999999Z07:00 7805c1d35632: (from redis:2.8) stop +If you do not provide the --since option, the command returns only new and/or +live events. + # HISTORY April 2014, Originally compiled by William Henry (whenry at redhat dot com) based on docker.com source material and internal work. June 2014, updated by Sven Dowideit +June 2015, updated by Brian Goff diff --git a/docs/sources/reference/commandline/cli.md b/docs/sources/reference/commandline/cli.md index e97738e5e6..3b98c6fcd9 100644 --- a/docs/sources/reference/commandline/cli.md +++ b/docs/sources/reference/commandline/cli.md @@ -1125,7 +1125,8 @@ and Docker images will report: The `--since` and `--until` parameters can be Unix timestamps, RFC3339 dates or Go duration strings (e.g. `10m`, `1h30m`) computed relative to -client machine’s time. +client machine’s time. If you do not provide the --since option, the command +returns only new and/or live events. #### Filtering diff --git a/integration-cli/docker_cli_events_test.go b/integration-cli/docker_cli_events_test.go index cba909a9ef..36a8436b94 100644 --- a/integration-cli/docker_cli_events_test.go +++ b/integration-cli/docker_cli_events_test.go @@ -595,7 +595,7 @@ func (s *DockerSuite) TestEventsCommit(c *check.C) { c.Fatalf("Couldn't stop: %s\n%q", out, err) } - cmd = exec.Command(dockerBinary, "events", "-f", "container="+cID, "--until="+strconv.Itoa(int(since))) + cmd = exec.Command(dockerBinary, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since))) out, _, err = runCommandWithOutput(cmd) if err != nil { c.Fatalf("Couldn't get events: %s\n%q", out, err) @@ -628,7 +628,7 @@ func (s *DockerSuite) TestEventsCopy(c *check.C) { c.Fatalf("Failed getting file:%q\n%q", out, err) } - cmd = exec.Command(dockerBinary, "events", "-f", "container=cptest", "--until="+strconv.Itoa(int(since))) + cmd = exec.Command(dockerBinary, "events", "--since=0", "-f", "container=cptest", "--until="+strconv.Itoa(int(since))) out, _, err = runCommandWithOutput(cmd) if err != nil { c.Fatalf("Couldn't get events: %s\n%q", out, err) @@ -661,7 +661,7 @@ func (s *DockerSuite) TestEventsResize(c *check.C) { c.Fatalf("Couldn't stop: %s\n%q", out, err) } - cmd = exec.Command(dockerBinary, "events", "-f", "container="+cID, "--until="+strconv.Itoa(int(since))) + cmd = exec.Command(dockerBinary, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since))) out, _, err = runCommandWithOutput(cmd) if err != nil { c.Fatalf("Couldn't get events: %s\n%q", out, err) @@ -706,7 +706,7 @@ func (s *DockerSuite) TestEventsAttach(c *check.C) { c.Fatalf("Couldn't stop: %s\n%q", out, err) } - cmd = exec.Command(dockerBinary, "events", "-f", "container="+cID, "--until="+strconv.Itoa(int(since))) + cmd = exec.Command(dockerBinary, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since))) out, _, err = runCommandWithOutput(cmd) if err != nil { c.Fatalf("Couldn't get events: %s\n%q", out, err) @@ -732,7 +732,7 @@ func (s *DockerSuite) TestEventsRename(c *check.C) { c.Fatalf("Couldn't rename: %s\n%q", out, err) } - cmd := exec.Command(dockerBinary, "events", "-f", "container=newName", "--until="+strconv.Itoa(int(since))) + cmd := exec.Command(dockerBinary, "events", "--since=0", "-f", "container=newName", "--until="+strconv.Itoa(int(since))) out, _, err = runCommandWithOutput(cmd) if err != nil { c.Fatalf("Couldn't get events: %s\n%q", out, err) @@ -766,7 +766,7 @@ func (s *DockerSuite) TestEventsTop(c *check.C) { c.Fatalf("Couldn't stop: %s\n%q", out, err) } - cmd = exec.Command(dockerBinary, "events", "-f", "container="+cID, "--until="+strconv.Itoa(int(since))) + cmd = exec.Command(dockerBinary, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since))) out, _, err = runCommandWithOutput(cmd) if err != nil { c.Fatalf("Couldn't get events: %s\n%q", out, err) @@ -776,3 +776,10 @@ func (s *DockerSuite) TestEventsTop(c *check.C) { c.Fatalf("Missing 'top' log event\n%s", out) } } + +// #13753 +func (s *DockerSuite) TestEventsDefaultEmpty(c *check.C) { + dockerCmd(c, "run", "-d", "busybox") + out, _ := dockerCmd(c, "events", fmt.Sprintf("--until=%d", daemonTime(c).Unix())) + c.Assert(strings.TrimSpace(out), check.Equals, "") +}