Use docker log timestamp as metric time (#7434)
This commit is contained in:
@@ -53,6 +53,14 @@ func (r *Response) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func MustParse(layout, value string) time.Time {
|
||||
tm, err := time.Parse(layout, value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return tm
|
||||
}
|
||||
|
||||
func Test(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -87,7 +95,7 @@ func Test(t *testing.T) {
|
||||
}, nil
|
||||
},
|
||||
ContainerLogsF: func(ctx context.Context, containerID string, options types.ContainerLogsOptions) (io.ReadCloser, error) {
|
||||
return &Response{Reader: bytes.NewBuffer([]byte("hello\n"))}, nil
|
||||
return &Response{Reader: bytes.NewBuffer([]byte("2020-04-28T18:43:16.432691200Z hello\n"))}, nil
|
||||
},
|
||||
},
|
||||
expected: []telegraf.Metric{
|
||||
@@ -104,7 +112,7 @@ func Test(t *testing.T) {
|
||||
"container_id": "deadbeef",
|
||||
"message": "hello",
|
||||
},
|
||||
time.Now(),
|
||||
MustParse(time.RFC3339Nano, "2020-04-28T18:43:16.432691200Z"),
|
||||
),
|
||||
},
|
||||
},
|
||||
@@ -130,7 +138,7 @@ func Test(t *testing.T) {
|
||||
ContainerLogsF: func(ctx context.Context, containerID string, options types.ContainerLogsOptions) (io.ReadCloser, error) {
|
||||
var buf bytes.Buffer
|
||||
w := stdcopy.NewStdWriter(&buf, stdcopy.Stdout)
|
||||
w.Write([]byte("hello from stdout"))
|
||||
w.Write([]byte("2020-04-28T18:42:16.432691200Z hello from stdout"))
|
||||
return &Response{Reader: &buf}, nil
|
||||
},
|
||||
},
|
||||
@@ -148,7 +156,7 @@ func Test(t *testing.T) {
|
||||
"container_id": "deadbeef",
|
||||
"message": "hello from stdout",
|
||||
},
|
||||
time.Now(),
|
||||
MustParse(time.RFC3339Nano, "2020-04-28T18:42:16.432691200Z"),
|
||||
),
|
||||
},
|
||||
},
|
||||
@@ -172,7 +180,9 @@ func Test(t *testing.T) {
|
||||
acc.Wait(len(tt.expected))
|
||||
plugin.Stop()
|
||||
|
||||
testutil.RequireMetricsEqual(t, tt.expected, acc.GetTelegrafMetrics(), testutil.IgnoreTime())
|
||||
require.Nil(t, acc.Errors) // no errors during gathering
|
||||
|
||||
testutil.RequireMetricsEqual(t, tt.expected, acc.GetTelegrafMetrics())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user