Use protobuf Timestamp type instead of uint64

This will ensure nanoseconds are taken in account.

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickael Laventure 2016-06-30 14:09:40 -07:00
parent 3dfa04b2f4
commit dfb626dccc
16 changed files with 1210 additions and 173 deletions

View file

@ -20,6 +20,7 @@ import (
"github.com/docker/containerd/api/grpc/types"
"github.com/docker/containerd/specs"
"github.com/docker/docker/pkg/term"
"github.com/golang/protobuf/ptypes"
netcontext "golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/grpclog"
@ -650,7 +651,7 @@ var updateCommand = cli.Command{
}
func waitForExit(c types.APIClient, events types.API_EventsClient, id, pid string, closer func()) {
timestamp := uint64(time.Now().Unix())
timestamp := time.Now()
for {
e, err := events.Recv()
if err != nil {
@ -659,10 +660,16 @@ func waitForExit(c types.APIClient, events types.API_EventsClient, id, pid strin
os.Exit(128 + int(syscall.SIGHUP))
}
time.Sleep(1 * time.Second)
events, _ = c.Events(netcontext.Background(), &types.EventsRequest{Timestamp: timestamp})
tsp, err := ptypes.TimestampProto(timestamp)
if err != nil {
closer()
fmt.Fprintf(os.Stderr, "%s", err.Error())
os.Exit(1)
}
events, _ = c.Events(netcontext.Background(), &types.EventsRequest{Timestamp: tsp})
continue
}
timestamp = e.Timestamp
timestamp, err = ptypes.Timestamp(e.Timestamp)
if e.Id == id && e.Type == "exit" && e.Pid == pid {
closer()
os.Exit(int(e.Status))

View file

@ -8,6 +8,7 @@ import (
"github.com/codegangsta/cli"
"github.com/docker/containerd/api/grpc/types"
"github.com/golang/protobuf/ptypes"
netcontext "golang.org/x/net/context"
)
@ -22,7 +23,7 @@ var eventsCommand = cli.Command{
},
Action: func(context *cli.Context) {
var (
t int64
t = time.Time{}
c = getClient(context)
)
if ts := context.String("timestamp"); ts != "" {
@ -30,15 +31,19 @@ var eventsCommand = cli.Command{
if err != nil {
fatal(err.Error(), 1)
}
t = from.Unix()
t = from
}
tsp, err := ptypes.TimestampProto(t)
if err != nil {
fatal(err.Error(), 1)
}
events, err := c.Events(netcontext.Background(), &types.EventsRequest{
Timestamp: uint64(t),
Timestamp: tsp,
})
if err != nil {
fatal(err.Error(), 1)
}
w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
w := tabwriter.NewWriter(os.Stdout, 31, 1, 1, ' ', 0)
fmt.Fprint(w, "TIME\tTYPE\tID\tPID\tSTATUS\n")
w.Flush()
for {
@ -46,7 +51,12 @@ var eventsCommand = cli.Command{
if err != nil {
fatal(err.Error(), 1)
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\n", time.Unix(int64(e.Timestamp), 0).Format(time.RFC3339Nano), e.Type, e.Id, e.Pid, e.Status)
t, err := ptypes.Timestamp(e.Timestamp)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to convert timestamp")
t = time.Time{}
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\n", t.Format(time.RFC3339Nano), e.Type, e.Id, e.Pid, e.Status)
w.Flush()
}
},