Skip to content

Commit 27220ec

Browse files
committed
Move timeutils functions to the only places where they are used.
- Move time json marshaling to the jsonlog package: this is a docker internal hack that we should not promote as a library. - Move Timestamp encoding/decoding functions to the API types: This is only used there. It could be a standalone library but I don't this it's worth having a separated repo for this. It could introduce more complexity than it solves. Signed-off-by: David Calavera <david.calavera@gmail.com>
1 parent 2180dd6 commit 27220ec

File tree

15 files changed

+44
-50
lines changed

15 files changed

+44
-50
lines changed

api/client/lib/events.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"time"
77

88
"github.com/docker/docker/api/types"
9+
timetypes "github.com/docker/docker/api/types/time"
910
"github.com/docker/docker/pkg/parsers/filters"
10-
"github.com/docker/docker/pkg/timeutils"
1111
)
1212

1313
// 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) {
1717
ref := time.Now()
1818

1919
if options.Since != "" {
20-
ts, err := timeutils.GetTimestamp(options.Since, ref)
20+
ts, err := timetypes.GetTimestamp(options.Since, ref)
2121
if err != nil {
2222
return nil, err
2323
}
2424
query.Set("since", ts)
2525
}
2626
if options.Until != "" {
27-
ts, err := timeutils.GetTimestamp(options.Until, ref)
27+
ts, err := timetypes.GetTimestamp(options.Until, ref)
2828
if err != nil {
2929
return nil, err
3030
}

api/client/lib/logs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"time"
77

88
"github.com/docker/docker/api/types"
9-
"github.com/docker/docker/pkg/timeutils"
9+
timetypes "github.com/docker/docker/api/types/time"
1010
)
1111

1212
// 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
2222
}
2323

2424
if options.Since != "" {
25-
ts, err := timeutils.GetTimestamp(options.Since, time.Now())
25+
ts, err := timetypes.GetTimestamp(options.Since, time.Now())
2626
if err != nil {
2727
return nil, err
2828
}

api/server/router/container/container_routes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
"github.com/docker/distribution/registry/api/errcode"
1414
"github.com/docker/docker/api/server/httputils"
1515
"github.com/docker/docker/api/types"
16+
timetypes "github.com/docker/docker/api/types/time"
1617
"github.com/docker/docker/daemon"
1718
derr "github.com/docker/docker/errors"
1819
"github.com/docker/docker/pkg/ioutils"
1920
"github.com/docker/docker/pkg/signal"
20-
"github.com/docker/docker/pkg/timeutils"
2121
"github.com/docker/docker/runconfig"
2222
"github.com/docker/docker/utils"
2323
"golang.org/x/net/context"
@@ -101,7 +101,7 @@ func (s *containerRouter) getContainersLogs(ctx context.Context, w http.Response
101101

102102
var since time.Time
103103
if r.Form.Get("since") != "" {
104-
s, n, err := timeutils.ParseTimestamps(r.Form.Get("since"), 0)
104+
s, n, err := timetypes.ParseTimestamps(r.Form.Get("since"), 0)
105105
if err != nil {
106106
return err
107107
}

api/server/router/system/system_routes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
"github.com/docker/docker/api"
1010
"github.com/docker/docker/api/server/httputils"
1111
"github.com/docker/docker/api/types"
12+
timetypes "github.com/docker/docker/api/types/time"
1213
"github.com/docker/docker/pkg/ioutils"
1314
"github.com/docker/docker/pkg/jsonmessage"
1415
"github.com/docker/docker/pkg/parsers/filters"
15-
"github.com/docker/docker/pkg/timeutils"
1616
"golang.org/x/net/context"
1717
)
1818

@@ -46,11 +46,11 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r *
4646
if err := httputils.ParseForm(r); err != nil {
4747
return err
4848
}
49-
since, sinceNano, err := timeutils.ParseTimestamps(r.Form.Get("since"), -1)
49+
since, sinceNano, err := timetypes.ParseTimestamps(r.Form.Get("since"), -1)
5050
if err != nil {
5151
return err
5252
}
53-
until, untilNano, err := timeutils.ParseTimestamps(r.Form.Get("until"), -1)
53+
until, untilNano, err := timetypes.ParseTimestamps(r.Form.Get("until"), -1)
5454
if err != nil {
5555
return err
5656
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package timeutils
1+
package time
22

33
import (
44
"fmt"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package timeutils
1+
package time
22

33
import (
44
"fmt"

daemon/logger/jsonfilelog/jsonfilelog.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/docker/docker/daemon/logger"
1515
"github.com/docker/docker/daemon/logger/loggerutils"
1616
"github.com/docker/docker/pkg/jsonlog"
17-
"github.com/docker/docker/pkg/timeutils"
1817
"github.com/docker/docker/pkg/units"
1918
)
2019

@@ -87,8 +86,7 @@ func New(ctx logger.Context) (logger.Logger, error) {
8786

8887
// Log converts logger.Message to jsonlog.JSONLog and serializes it to file.
8988
func (l *JSONFileLogger) Log(msg *logger.Message) error {
90-
91-
timestamp, err := timeutils.FastMarshalJSON(msg.Timestamp)
89+
timestamp, err := jsonlog.FastTimeMarshalJSON(msg.Timestamp)
9290
if err != nil {
9391
return err
9492
}

daemon/logger/logger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import (
1111
"errors"
1212
"time"
1313

14-
"github.com/docker/docker/pkg/timeutils"
14+
"github.com/docker/docker/pkg/jsonlog"
1515
)
1616

1717
// ErrReadLogsNotSupported is returned when the logger does not support reading logs.
1818
var ErrReadLogsNotSupported = errors.New("configured logging reader does not support reading")
1919

2020
const (
2121
// TimeFormat is the time format used for timestamps sent to log readers.
22-
TimeFormat = timeutils.RFC3339NanoFixed
22+
TimeFormat = jsonlog.RFC3339NanoFixed
2323
logWatcherBufferSize = 4096
2424
)
2525

docker/daemon.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import (
2020
"github.com/docker/docker/daemon/logger"
2121
"github.com/docker/docker/dockerversion"
2222
"github.com/docker/docker/opts"
23+
"github.com/docker/docker/pkg/jsonlog"
2324
flag "github.com/docker/docker/pkg/mflag"
2425
"github.com/docker/docker/pkg/pidfile"
2526
"github.com/docker/docker/pkg/signal"
2627
"github.com/docker/docker/pkg/system"
27-
"github.com/docker/docker/pkg/timeutils"
2828
"github.com/docker/docker/pkg/tlsconfig"
2929
"github.com/docker/docker/registry"
3030
"github.com/docker/docker/utils"
@@ -150,7 +150,7 @@ func (cli *DaemonCli) CmdDaemon(args ...string) error {
150150
logrus.Warn("Running experimental build")
151151
}
152152

153-
logrus.SetFormatter(&logrus.TextFormatter{TimestampFormat: timeutils.RFC3339NanoFixed})
153+
logrus.SetFormatter(&logrus.TextFormatter{TimestampFormat: jsonlog.RFC3339NanoFixed})
154154

155155
if err := setDefaultUmask(); err != nil {
156156
logrus.Fatalf("Failed to set umask: %v", err)

integration-cli/docker_cli_logs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/docker/docker/pkg/integration/checker"
14-
"github.com/docker/docker/pkg/timeutils"
14+
"github.com/docker/docker/pkg/jsonlog"
1515
"github.com/go-check/check"
1616
)
1717

@@ -75,7 +75,7 @@ func (s *DockerSuite) TestLogsTimestamps(c *check.C) {
7575

7676
for _, l := range lines {
7777
if l != "" {
78-
_, err := time.Parse(timeutils.RFC3339NanoFixed+" ", ts.FindString(l))
78+
_, err := time.Parse(jsonlog.RFC3339NanoFixed+" ", ts.FindString(l))
7979
c.Assert(err, checker.IsNil, check.Commentf("Failed to parse timestamp from %v", l))
8080
// ensure we have padded 0's
8181
c.Assert(l[29], checker.Equals, uint8('Z'))

0 commit comments

Comments
 (0)