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 { select {
case stats := <-statsCh: case stats := <-statsCh:
require.NotZero(stats.ResourceUsage.MemoryStats.RSS) 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): case <-time.After(time.Second):
require.Fail("timeout receiving from channel") require.Fail("timeout receiving from channel")
} }

View file

@ -178,9 +178,9 @@ func TestExecutor_WaitExitSignal(pt *testing.T) {
case <-time.After(time.Second): case <-time.After(time.Second):
return false, fmt.Errorf("stats failed to send on interval") return false, fmt.Errorf("stats failed to send on interval")
case ru := <-ch: case ru := <-ch:
if len(ru.Pids) == 0 { assert.NotEmpty(t, ru.Pids, "no pids recorded in stats")
return false, fmt.Errorf("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) proc, err := os.FindProcess(ps.Pid)
if err != nil { if err != nil {

View file

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