From 3fdc48eb0181433753a9ac8cb58633086b8b3788 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Fri, 4 Dec 2015 15:12:57 -0800 Subject: [PATCH] Add checkpoint timestamp based on mtime Signed-off-by: Michael Crosby --- README.md | 6 ++++-- api/v1/server.go | 1 + api/v1/types.go | 13 ++++++++----- delete.go | 5 ++--- linux/linux.go | 5 ++--- start.go | 1 + worker.go | 1 - 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 4061f1a..af93331 100644 --- a/README.md +++ b/README.md @@ -173,13 +173,15 @@ Response: "name" : "test1", "unixSockets" : false, "tcp" : false, - "shell" : false + "shell" : false, + "timestamp" : "2015-12-04T15:09:14.915868934-08:00" }, { "name" : "test2", "tcp" : false, "unixSockets" : false, - "shell" : false + "shell" : false, + "timestamp" : "2015-12-04T15:09:14.915868934-08:00" } ] ``` diff --git a/api/v1/server.go b/api/v1/server.go index bb9a17e..2713929 100644 --- a/api/v1/server.go +++ b/api/v1/server.go @@ -314,6 +314,7 @@ func (s *server) listCheckpoints(w http.ResponseWriter, r *http.Request) { Tcp: c.Tcp, Shell: c.Shell, UnixSockets: c.UnixSockets, + Timestamp: c.Timestamp, }) } if err := json.NewEncoder(w).Encode(out); err != nil { diff --git a/api/v1/types.go b/api/v1/types.go index cb5e361..3618a8f 100644 --- a/api/v1/types.go +++ b/api/v1/types.go @@ -1,5 +1,7 @@ package v1 +import "time" + type State struct { Containers []Container `json:"containers"` Machine Machine `json:"machine"` @@ -58,9 +60,10 @@ type Event struct { } type Checkpoint struct { - Name string `json:"name,omitempty"` - Exit bool `json:"exit,omitempty"` - Tcp bool `json:"tcp"` - UnixSockets bool `json:"unixSockets"` - Shell bool `json:"shell"` + Name string `json:"name,omitempty"` + Timestamp time.Time `json:"timestamp,omitempty"` + Exit bool `json:"exit,omitempty"` + Tcp bool `json:"tcp"` + UnixSockets bool `json:"unixSockets"` + Shell bool `json:"shell"` } diff --git a/delete.go b/delete.go index c4a225b..c36a279 100644 --- a/delete.go +++ b/delete.go @@ -13,10 +13,9 @@ func (h *DeleteEvent) Handle(e *Event) error { if container, ok := h.s.containers[e.ID]; ok { if err := h.deleteContainer(container); err != nil { logrus.WithField("error", err).Error("containerd: deleting container") - } else { - ContainersCounter.Dec(1) - h.s.containerGroup.Done() } + ContainersCounter.Dec(1) + h.s.containerGroup.Done() } return nil } diff --git a/linux/linux.go b/linux/linux.go index c8555af..92110c4 100644 --- a/linux/linux.go +++ b/linux/linux.go @@ -13,7 +13,6 @@ import ( "strconv" "strings" "syscall" - "time" "github.com/docker/containerd/runtime" "github.com/opencontainers/runc/libcontainer" @@ -202,7 +201,8 @@ func (c *libcontainerContainer) Checkpoints() ([]runtime.Checkpoint, error) { } for _, fi := range files { out = append(out, runtime.Checkpoint{ - Name: fi.Name(), + Name: fi.Name(), + Timestamp: fi.ModTime(), }) } return out, nil @@ -238,7 +238,6 @@ func (c *libcontainerContainer) Checkpoint(cp runtime.Checkpoint) error { if err := c.c.Checkpoint(opts); err != nil { return err } - cp.Timestamp = time.Now() return nil } diff --git a/start.go b/start.go index 36e3eac..9400e08 100644 --- a/start.go +++ b/start.go @@ -9,6 +9,7 @@ func (h *StartEvent) Handle(e *Event) error { if err != nil { return err } + h.s.containerGroup.Add(1) h.s.containers[e.ID] = container ContainersCounter.Inc(1) task := &StartTask{ diff --git a/worker.go b/worker.go index 4cebf7f..d77ebef 100644 --- a/worker.go +++ b/worker.go @@ -50,7 +50,6 @@ func (w *worker) Start() { continue } } - w.s.containerGroup.Add(1) ContainerStartTimer.UpdateSince(started) t.Err <- nil }