Browse Source

Default events since to current time

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Brian Goff 10 years ago
parent
commit
74c12aa429

+ 4 - 0
api/server/server.go

@@ -395,6 +395,7 @@ func (s *Server) getEvents(version version.Version, w http.ResponseWriter, r *ht
 		}
 		}
 		until = u
 		until = u
 	}
 	}
+
 	timer := time.NewTimer(0)
 	timer := time.NewTimer(0)
 	timer.Stop()
 	timer.Stop()
 	if until > 0 {
 	if until > 0 {
@@ -453,6 +454,9 @@ func (s *Server) getEvents(version version.Version, w http.ResponseWriter, r *ht
 	}
 	}
 
 
 	current, l := es.Subscribe()
 	current, l := es.Subscribe()
+	if since == -1 {
+		current = nil
+	}
 	defer es.Evict(l)
 	defer es.Evict(l)
 	for _, ev := range current {
 	for _, ev := range current {
 		if ev.Time < since {
 		if ev.Time < since {

+ 4 - 0
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:53:45.999999999Z07:00  7805c1d35632: (from redis:2.8) die
     2015-05-12T15:54:03.999999999Z07:00  7805c1d35632: (from redis:2.8) stop
     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
 # HISTORY
 April 2014, Originally compiled by William Henry (whenry at redhat dot com)
 April 2014, Originally compiled by William Henry (whenry at redhat dot com)
 based on docker.com source material and internal work.
 based on docker.com source material and internal work.
 June 2014, updated by Sven Dowideit <SvenDowideit@home.org.au>
 June 2014, updated by Sven Dowideit <SvenDowideit@home.org.au>
+June 2015, updated by Brian Goff <cpuguy83@gmail.com>

+ 2 - 1
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
 The `--since` and `--until` parameters can be Unix timestamps, RFC3339
 dates or Go duration strings (e.g. `10m`, `1h30m`) computed relative to
 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
 #### Filtering
 
 

+ 13 - 6
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)
 		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)
 	out, _, err = runCommandWithOutput(cmd)
 	if err != nil {
 	if err != nil {
 		c.Fatalf("Couldn't get events: %s\n%q", out, err)
 		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)
 		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)
 	out, _, err = runCommandWithOutput(cmd)
 	if err != nil {
 	if err != nil {
 		c.Fatalf("Couldn't get events: %s\n%q", out, err)
 		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)
 		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)
 	out, _, err = runCommandWithOutput(cmd)
 	if err != nil {
 	if err != nil {
 		c.Fatalf("Couldn't get events: %s\n%q", out, err)
 		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)
 		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)
 	out, _, err = runCommandWithOutput(cmd)
 	if err != nil {
 	if err != nil {
 		c.Fatalf("Couldn't get events: %s\n%q", out, err)
 		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)
 		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)
 	out, _, err = runCommandWithOutput(cmd)
 	if err != nil {
 	if err != nil {
 		c.Fatalf("Couldn't get events: %s\n%q", out, err)
 		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)
 		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)
 	out, _, err = runCommandWithOutput(cmd)
 	if err != nil {
 	if err != nil {
 		c.Fatalf("Couldn't get events: %s\n%q", out, err)
 		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)
 		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, "")
+}