mirror of
https://github.com/moby/moby.git
synced 2026-08-03 14:41:03 +00:00
Add system time to /info
This change adds daemon's system time as RFC3339Nano to the `/info` endpoint and shows in a more readable format (UnixDate) in `docker -D info` output. I will be using this to fix the clock skew between the remote test host and the CI machines running `docker events`-related tests as they're using `--since` and `--until` and the timestamps are not matching when daemon is not on the same machine. Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
@@ -69,6 +70,15 @@ func (env *Env) SetBool(key string, value bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (env *Env) GetTime(key string) (time.Time, error) {
|
||||
t, err := time.Parse(time.RFC3339Nano, env.Get(key))
|
||||
return t, err
|
||||
}
|
||||
|
||||
func (env *Env) SetTime(key string, t time.Time) {
|
||||
env.Set(key, t.Format(time.RFC3339Nano))
|
||||
}
|
||||
|
||||
func (env *Env) GetInt(key string) int {
|
||||
return int(env.GetInt64(key))
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/testutils"
|
||||
)
|
||||
@@ -94,6 +95,27 @@ func TestSetenvBool(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetenvTime(t *testing.T) {
|
||||
job := mkJob(t, "dummy")
|
||||
|
||||
now := time.Now()
|
||||
job.SetenvTime("foo", now)
|
||||
if val, err := job.GetenvTime("foo"); err != nil {
|
||||
t.Fatalf("GetenvTime failed to parse: %v", err)
|
||||
} else {
|
||||
nowStr := now.Format(time.RFC3339)
|
||||
valStr := val.Format(time.RFC3339)
|
||||
if nowStr != valStr {
|
||||
t.Fatalf("GetenvTime returns incorrect value: %s, Expected: %s", valStr, nowStr)
|
||||
}
|
||||
}
|
||||
|
||||
job.Setenv("bar", "Obviously I'm not a date")
|
||||
if val, err := job.GetenvTime("bar"); err == nil {
|
||||
t.Fatalf("GetenvTime was supposed to fail, instead returned: %s", val)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetenvInt(t *testing.T) {
|
||||
job := mkJob(t, "dummy")
|
||||
|
||||
|
||||
@@ -145,6 +145,14 @@ func (job *Job) SetenvBool(key string, value bool) {
|
||||
job.env.SetBool(key, value)
|
||||
}
|
||||
|
||||
func (job *Job) GetenvTime(key string) (value time.Time, err error) {
|
||||
return job.env.GetTime(key)
|
||||
}
|
||||
|
||||
func (job *Job) SetenvTime(key string, value time.Time) {
|
||||
job.env.SetTime(key, value)
|
||||
}
|
||||
|
||||
func (job *Job) GetenvSubEnv(key string) *Env {
|
||||
return job.env.GetSubEnv(key)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user