diff --git a/api/client/lib/events.go b/api/client/lib/events.go index 1d63a845a0..887c6502de 100644 --- a/api/client/lib/events.go +++ b/api/client/lib/events.go @@ -6,8 +6,8 @@ import ( "time" "github.com/docker/docker/api/types" + timetypes "github.com/docker/docker/api/types/time" "github.com/docker/docker/pkg/parsers/filters" - "github.com/docker/docker/pkg/timeutils" ) // Events returns a stream of events in the daemon in a ReadCloser. @@ -17,14 +17,14 @@ func (cli *Client) Events(options types.EventsOptions) (io.ReadCloser, error) { ref := time.Now() if options.Since != "" { - ts, err := timeutils.GetTimestamp(options.Since, ref) + ts, err := timetypes.GetTimestamp(options.Since, ref) if err != nil { return nil, err } query.Set("since", ts) } if options.Until != "" { - ts, err := timeutils.GetTimestamp(options.Until, ref) + ts, err := timetypes.GetTimestamp(options.Until, ref) if err != nil { return nil, err } diff --git a/api/client/lib/logs.go b/api/client/lib/logs.go index 241bac33de..119f41306d 100644 --- a/api/client/lib/logs.go +++ b/api/client/lib/logs.go @@ -6,7 +6,7 @@ import ( "time" "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/timeutils" + timetypes "github.com/docker/docker/api/types/time" ) // ContainerLogs returns the logs generated by a container in an io.ReadCloser. @@ -22,7 +22,7 @@ func (cli *Client) ContainerLogs(options types.ContainerLogsOptions) (io.ReadClo } if options.Since != "" { - ts, err := timeutils.GetTimestamp(options.Since, time.Now()) + ts, err := timetypes.GetTimestamp(options.Since, time.Now()) if err != nil { return nil, err } diff --git a/api/server/router/container/container_routes.go b/api/server/router/container/container_routes.go index dd300a498f..94c8a9661f 100644 --- a/api/server/router/container/container_routes.go +++ b/api/server/router/container/container_routes.go @@ -13,11 +13,11 @@ import ( "github.com/docker/distribution/registry/api/errcode" "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/types" + timetypes "github.com/docker/docker/api/types/time" "github.com/docker/docker/daemon" derr "github.com/docker/docker/errors" "github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/signal" - "github.com/docker/docker/pkg/timeutils" "github.com/docker/docker/runconfig" "github.com/docker/docker/utils" "golang.org/x/net/context" @@ -101,7 +101,7 @@ func (s *containerRouter) getContainersLogs(ctx context.Context, w http.Response var since time.Time if r.Form.Get("since") != "" { - s, n, err := timeutils.ParseTimestamps(r.Form.Get("since"), 0) + s, n, err := timetypes.ParseTimestamps(r.Form.Get("since"), 0) if err != nil { return err } diff --git a/api/server/router/system/system_routes.go b/api/server/router/system/system_routes.go index 0ebe171c9c..331f326380 100644 --- a/api/server/router/system/system_routes.go +++ b/api/server/router/system/system_routes.go @@ -9,10 +9,10 @@ import ( "github.com/docker/docker/api" "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/types" + timetypes "github.com/docker/docker/api/types/time" "github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/parsers/filters" - "github.com/docker/docker/pkg/timeutils" "golang.org/x/net/context" ) @@ -46,11 +46,11 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r * if err := httputils.ParseForm(r); err != nil { return err } - since, sinceNano, err := timeutils.ParseTimestamps(r.Form.Get("since"), -1) + since, sinceNano, err := timetypes.ParseTimestamps(r.Form.Get("since"), -1) if err != nil { return err } - until, untilNano, err := timeutils.ParseTimestamps(r.Form.Get("until"), -1) + until, untilNano, err := timetypes.ParseTimestamps(r.Form.Get("until"), -1) if err != nil { return err } diff --git a/pkg/timeutils/utils.go b/api/types/time/timestamp.go similarity index 99% rename from pkg/timeutils/utils.go rename to api/types/time/timestamp.go index 077d091f0b..68895ec727 100644 --- a/pkg/timeutils/utils.go +++ b/api/types/time/timestamp.go @@ -1,4 +1,4 @@ -package timeutils +package time import ( "fmt" diff --git a/pkg/timeutils/utils_test.go b/api/types/time/timestamp_test.go similarity index 99% rename from pkg/timeutils/utils_test.go rename to api/types/time/timestamp_test.go index 1c443490ba..19854d0ea3 100644 --- a/pkg/timeutils/utils_test.go +++ b/api/types/time/timestamp_test.go @@ -1,4 +1,4 @@ -package timeutils +package time import ( "fmt" diff --git a/daemon/logger/jsonfilelog/jsonfilelog.go b/daemon/logger/jsonfilelog/jsonfilelog.go index 437e09562f..fd4671a12a 100644 --- a/daemon/logger/jsonfilelog/jsonfilelog.go +++ b/daemon/logger/jsonfilelog/jsonfilelog.go @@ -14,7 +14,6 @@ import ( "github.com/docker/docker/daemon/logger" "github.com/docker/docker/daemon/logger/loggerutils" "github.com/docker/docker/pkg/jsonlog" - "github.com/docker/docker/pkg/timeutils" "github.com/docker/docker/pkg/units" ) @@ -87,8 +86,7 @@ func New(ctx logger.Context) (logger.Logger, error) { // Log converts logger.Message to jsonlog.JSONLog and serializes it to file. func (l *JSONFileLogger) Log(msg *logger.Message) error { - - timestamp, err := timeutils.FastMarshalJSON(msg.Timestamp) + timestamp, err := jsonlog.FastTimeMarshalJSON(msg.Timestamp) if err != nil { return err } diff --git a/daemon/logger/logger.go b/daemon/logger/logger.go index 5fc821e710..cf8d571fa4 100644 --- a/daemon/logger/logger.go +++ b/daemon/logger/logger.go @@ -11,7 +11,7 @@ import ( "errors" "time" - "github.com/docker/docker/pkg/timeutils" + "github.com/docker/docker/pkg/jsonlog" ) // ErrReadLogsNotSupported is returned when the logger does not support reading logs. @@ -19,7 +19,7 @@ var ErrReadLogsNotSupported = errors.New("configured logging reader does not sup const ( // TimeFormat is the time format used for timestamps sent to log readers. - TimeFormat = timeutils.RFC3339NanoFixed + TimeFormat = jsonlog.RFC3339NanoFixed logWatcherBufferSize = 4096 ) diff --git a/docker/daemon.go b/docker/daemon.go index 72da5c2c03..6aac30bf19 100644 --- a/docker/daemon.go +++ b/docker/daemon.go @@ -20,11 +20,11 @@ import ( "github.com/docker/docker/daemon/logger" "github.com/docker/docker/dockerversion" "github.com/docker/docker/opts" + "github.com/docker/docker/pkg/jsonlog" flag "github.com/docker/docker/pkg/mflag" "github.com/docker/docker/pkg/pidfile" "github.com/docker/docker/pkg/signal" "github.com/docker/docker/pkg/system" - "github.com/docker/docker/pkg/timeutils" "github.com/docker/docker/pkg/tlsconfig" "github.com/docker/docker/registry" "github.com/docker/docker/utils" @@ -150,7 +150,7 @@ func (cli *DaemonCli) CmdDaemon(args ...string) error { logrus.Warn("Running experimental build") } - logrus.SetFormatter(&logrus.TextFormatter{TimestampFormat: timeutils.RFC3339NanoFixed}) + logrus.SetFormatter(&logrus.TextFormatter{TimestampFormat: jsonlog.RFC3339NanoFixed}) if err := setDefaultUmask(); err != nil { logrus.Fatalf("Failed to set umask: %v", err) diff --git a/integration-cli/docker_cli_logs_test.go b/integration-cli/docker_cli_logs_test.go index 94ca1d3de8..1b4f0ddb62 100644 --- a/integration-cli/docker_cli_logs_test.go +++ b/integration-cli/docker_cli_logs_test.go @@ -11,7 +11,7 @@ import ( "time" "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/timeutils" + "github.com/docker/docker/pkg/jsonlog" "github.com/go-check/check" ) @@ -75,7 +75,7 @@ func (s *DockerSuite) TestLogsTimestamps(c *check.C) { for _, l := range lines { if l != "" { - _, err := time.Parse(timeutils.RFC3339NanoFixed+" ", ts.FindString(l)) + _, err := time.Parse(jsonlog.RFC3339NanoFixed+" ", ts.FindString(l)) c.Assert(err, checker.IsNil, check.Commentf("Failed to parse timestamp from %v", l)) // ensure we have padded 0's c.Assert(l[29], checker.Equals, uint8('Z')) diff --git a/pkg/jsonlog/jsonlog_marshalling.go b/pkg/jsonlog/jsonlog_marshalling.go index 6dcb69d470..31b047e3e3 100644 --- a/pkg/jsonlog/jsonlog_marshalling.go +++ b/pkg/jsonlog/jsonlog_marshalling.go @@ -13,8 +13,6 @@ // "bytes" //- // "unicode/utf8" -//+ -//+ "github.com/docker/docker/pkg/timeutils" // ) // // func (mj *JSONLog) MarshalJSON() ([]byte, error) { @@ -43,7 +41,7 @@ // } // buf.WriteString(`"time":`) //- obj, err = mj.Created.MarshalJSON() -//+ timestamp, err = timeutils.FastMarshalJSON(mj.Created) +//+ timestamp, err = FastTimeMarshalJSON(mj.Created) // if err != nil { // return err // } @@ -69,8 +67,6 @@ package jsonlog import ( "bytes" "unicode/utf8" - - "github.com/docker/docker/pkg/timeutils" ) // MarshalJSON marshals the JSONLog. @@ -111,7 +107,7 @@ func (mj *JSONLog) MarshalJSONBuf(buf *bytes.Buffer) error { buf.WriteString(`,`) } buf.WriteString(`"time":`) - timestamp, err = timeutils.FastMarshalJSON(mj.Created) + timestamp, err = FastTimeMarshalJSON(mj.Created) if err != nil { return err } diff --git a/pkg/timeutils/json.go b/pkg/jsonlog/time_marshalling.go similarity index 74% rename from pkg/timeutils/json.go rename to pkg/jsonlog/time_marshalling.go index ea19daad51..2117338149 100644 --- a/pkg/timeutils/json.go +++ b/pkg/jsonlog/time_marshalling.go @@ -1,5 +1,5 @@ -// Package timeutils provides helper functions to parse and print time (time.Time). -package timeutils +// Package jsonlog provides helper functions to parse and print time (time.Time) as JSON. +package jsonlog import ( "errors" @@ -15,9 +15,9 @@ const ( JSONFormat = `"` + time.RFC3339Nano + `"` ) -// FastMarshalJSON avoids one of the extra allocations that +// FastTimeMarshalJSON avoids one of the extra allocations that // time.MarshalJSON is making. -func FastMarshalJSON(t time.Time) (string, error) { +func FastTimeMarshalJSON(t time.Time) (string, error) { if y := t.Year(); y < 0 || y >= 10000 { // RFC 3339 is clear that years are 4 digits exactly. // See golang.org/issue/4556#c15 for more discussion. diff --git a/pkg/timeutils/json_test.go b/pkg/jsonlog/time_marshalling_test.go similarity index 63% rename from pkg/timeutils/json_test.go rename to pkg/jsonlog/time_marshalling_test.go index 1ff3331797..02d0302c4a 100644 --- a/pkg/timeutils/json_test.go +++ b/pkg/jsonlog/time_marshalling_test.go @@ -1,4 +1,4 @@ -package timeutils +package jsonlog import ( "testing" @@ -6,23 +6,23 @@ import ( ) // Testing to ensure 'year' fields is between 0 and 9999 -func TestFastMarshalJSONWithInvalidDate(t *testing.T) { +func TestFastTimeMarshalJSONWithInvalidDate(t *testing.T) { aTime := time.Date(-1, 1, 1, 0, 0, 0, 0, time.Local) - json, err := FastMarshalJSON(aTime) + json, err := FastTimeMarshalJSON(aTime) if err == nil { - t.Fatalf("FastMarshalJSON should throw an error, but was '%v'", json) + t.Fatalf("FastTimeMarshalJSON should throw an error, but was '%v'", json) } anotherTime := time.Date(10000, 1, 1, 0, 0, 0, 0, time.Local) - json, err = FastMarshalJSON(anotherTime) + json, err = FastTimeMarshalJSON(anotherTime) if err == nil { - t.Fatalf("FastMarshalJSON should throw an error, but was '%v'", json) + t.Fatalf("FastTimeMarshalJSON should throw an error, but was '%v'", json) } } -func TestFastMarshalJSON(t *testing.T) { +func TestFastTimeMarshalJSON(t *testing.T) { aTime := time.Date(2015, 5, 29, 11, 1, 2, 3, time.UTC) - json, err := FastMarshalJSON(aTime) + json, err := FastTimeMarshalJSON(aTime) if err != nil { t.Fatal(err) } @@ -36,7 +36,7 @@ func TestFastMarshalJSON(t *testing.T) { t.Fatal(err) } aTime = time.Date(2015, 5, 29, 11, 1, 2, 3, location) - json, err = FastMarshalJSON(aTime) + json, err = FastTimeMarshalJSON(aTime) if err != nil { t.Fatal(err) } diff --git a/pkg/jsonmessage/jsonmessage.go b/pkg/jsonmessage/jsonmessage.go index c234ff6804..419a47d9c9 100644 --- a/pkg/jsonmessage/jsonmessage.go +++ b/pkg/jsonmessage/jsonmessage.go @@ -7,8 +7,8 @@ import ( "strings" "time" + "github.com/docker/docker/pkg/jsonlog" "github.com/docker/docker/pkg/term" - "github.com/docker/docker/pkg/timeutils" "github.com/docker/docker/pkg/units" ) @@ -123,9 +123,9 @@ func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error { return nil } if jm.TimeNano != 0 { - fmt.Fprintf(out, "%s ", time.Unix(0, jm.TimeNano).Format(timeutils.RFC3339NanoFixed)) + fmt.Fprintf(out, "%s ", time.Unix(0, jm.TimeNano).Format(jsonlog.RFC3339NanoFixed)) } else if jm.Time != 0 { - fmt.Fprintf(out, "%s ", time.Unix(jm.Time, 0).Format(timeutils.RFC3339NanoFixed)) + fmt.Fprintf(out, "%s ", time.Unix(jm.Time, 0).Format(jsonlog.RFC3339NanoFixed)) } if jm.ID != "" { fmt.Fprintf(out, "%s: ", jm.ID) diff --git a/pkg/jsonmessage/jsonmessage_test.go b/pkg/jsonmessage/jsonmessage_test.go index 7f46a8f63e..b81b656994 100644 --- a/pkg/jsonmessage/jsonmessage_test.go +++ b/pkg/jsonmessage/jsonmessage_test.go @@ -7,8 +7,8 @@ import ( "testing" "time" + "github.com/docker/docker/pkg/jsonlog" "github.com/docker/docker/pkg/term" - "github.com/docker/docker/pkg/timeutils" ) func TestError(t *testing.T) { @@ -71,8 +71,8 @@ func TestJSONMessageDisplay(t *testing.T) { From: "From", Status: "status", }: { - fmt.Sprintf("%v ID: (from From) status\n", time.Unix(now.Unix(), 0).Format(timeutils.RFC3339NanoFixed)), - fmt.Sprintf("%v ID: (from From) status\n", time.Unix(now.Unix(), 0).Format(timeutils.RFC3339NanoFixed)), + fmt.Sprintf("%v ID: (from From) status\n", time.Unix(now.Unix(), 0).Format(jsonlog.RFC3339NanoFixed)), + fmt.Sprintf("%v ID: (from From) status\n", time.Unix(now.Unix(), 0).Format(jsonlog.RFC3339NanoFixed)), }, // General, with nano precision time JSONMessage{ @@ -81,8 +81,8 @@ func TestJSONMessageDisplay(t *testing.T) { From: "From", Status: "status", }: { - fmt.Sprintf("%v ID: (from From) status\n", time.Unix(0, now.UnixNano()).Format(timeutils.RFC3339NanoFixed)), - fmt.Sprintf("%v ID: (from From) status\n", time.Unix(0, now.UnixNano()).Format(timeutils.RFC3339NanoFixed)), + fmt.Sprintf("%v ID: (from From) status\n", time.Unix(0, now.UnixNano()).Format(jsonlog.RFC3339NanoFixed)), + fmt.Sprintf("%v ID: (from From) status\n", time.Unix(0, now.UnixNano()).Format(jsonlog.RFC3339NanoFixed)), }, // General, with both times Nano is preferred JSONMessage{ @@ -92,8 +92,8 @@ func TestJSONMessageDisplay(t *testing.T) { From: "From", Status: "status", }: { - fmt.Sprintf("%v ID: (from From) status\n", time.Unix(0, now.UnixNano()).Format(timeutils.RFC3339NanoFixed)), - fmt.Sprintf("%v ID: (from From) status\n", time.Unix(0, now.UnixNano()).Format(timeutils.RFC3339NanoFixed)), + fmt.Sprintf("%v ID: (from From) status\n", time.Unix(0, now.UnixNano()).Format(jsonlog.RFC3339NanoFixed)), + fmt.Sprintf("%v ID: (from From) status\n", time.Unix(0, now.UnixNano()).Format(jsonlog.RFC3339NanoFixed)), }, // Stream over status JSONMessage{