Default events since to current time

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2015-06-04 19:47:46 -07:00
parent 55bdb51659
commit 74c12aa429
4 changed files with 23 additions and 7 deletions

View File

@ -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 {

View File

@ -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 <SvenDowideit@home.org.au>
June 2015, updated by Brian Goff <cpuguy83@gmail.com>

View File

@ -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 machines time.
client machines time. If you do not provide the --since option, the command
returns only new and/or live events.
#### Filtering

View File

@ -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, "")
}