Merge pull request #5260 from hashicorp/b-driver-stats-timestamp

executor: fix bug and add tests for incorrect stats timestamp reporting
This commit is contained in:
Nick Ethier 2019-01-28 23:14:17 -05:00 committed by GitHub
commit 4fd95aca01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 4 deletions

View File

@ -284,6 +284,8 @@ func TestExecDriver_Stats(t *testing.T) {
select {
case stats := <-statsCh:
require.NotZero(stats.ResourceUsage.MemoryStats.RSS)
require.NotZero(stats.Timestamp)
require.WithinDuration(time.Now(), time.Unix(0, stats.Timestamp), time.Second)
case <-time.After(time.Second):
require.Fail("timeout receiving from channel")
}

View File

@ -178,9 +178,9 @@ func TestExecutor_WaitExitSignal(pt *testing.T) {
case <-time.After(time.Second):
return false, fmt.Errorf("stats failed to send on interval")
case ru := <-ch:
if len(ru.Pids) == 0 {
return false, fmt.Errorf("no pids recorded in stats")
}
assert.NotEmpty(t, ru.Pids, "no pids recorded in stats")
assert.NotZero(t, ru.ResourceUsage.MemoryStats.RSS)
assert.WithinDuration(t, time.Now(), time.Unix(0, ru.Timestamp), time.Second)
}
proc, err := os.FindProcess(ps.Pid)
if err != nil {

View File

@ -412,7 +412,7 @@ func TaskStatsFromProto(pb *proto.TaskStats) (*TaskResourceUsage, error) {
}
stats := &TaskResourceUsage{
Timestamp: timestamp.Unix(),
Timestamp: timestamp.UnixNano(),
ResourceUsage: resourceUsageFromProto(pb.AggResourceUsage),
Pids: pids,
}