From f5bfa506d602aee38b69f04eae61b76d02c56197 Mon Sep 17 00:00:00 2001 From: Filip Barl Date: Thu, 2 Nov 2017 13:16:54 +0100 Subject: [PATCH] Verified the TODO comments and make durations be in seconds. --- client/app/scripts/utils/string-utils.js | 2 +- probe/docker/container.go | 6 ++---- probe/docker/container_test.go | 4 ++-- probe/host/reporter.go | 3 +-- probe/host/reporter_test.go | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/client/app/scripts/utils/string-utils.js b/client/app/scripts/utils/string-utils.js index bd6970936..ab278d195 100644 --- a/client/app/scripts/utils/string-utils.js +++ b/client/app/scripts/utils/string-utils.js @@ -101,7 +101,7 @@ export function formatDataType(field, referenceTimestampStr = null) { }; }, duration(durationString) { - const humanizedDuration = moment.duration(parseInt(durationString, 10)).humanize(); + const humanizedDuration = moment.duration(Number(durationString), 'seconds').humanize(); return { value: humanizedDuration, title: humanizedDuration, diff --git a/probe/docker/container.go b/probe/docker/container.go index 949a09bbd..b31f2ff37 100644 --- a/probe/docker/container.go +++ b/probe/docker/container.go @@ -425,14 +425,12 @@ func (c *container) GetNode() report.Node { controls := c.controlsMap() if !c.container.State.Paused && c.container.State.Running { - // TODO: Use mtime.Now() only as a fallback from Time Travel - // timestamp here to get accurate durations when time travelling. - uptimeMs := mtime.Now().Sub(c.container.State.StartedAt) / time.Millisecond + uptimeSeconds := int(mtime.Now().Sub(c.container.State.StartedAt) / time.Second) networkMode := "" if c.container.HostConfig != nil { networkMode = c.container.HostConfig.NetworkMode } - latest[ContainerUptime] = strconv.Itoa(int(uptimeMs)) + latest[ContainerUptime] = strconv.Itoa(uptimeSeconds) latest[ContainerRestartCount] = strconv.Itoa(c.container.RestartCount) latest[ContainerNetworkMode] = networkMode } diff --git a/probe/docker/container_test.go b/probe/docker/container_test.go index 3e2298218..10c6f7074 100644 --- a/probe/docker/container_test.go +++ b/probe/docker/container_test.go @@ -59,7 +59,7 @@ func TestContainer(t *testing.T) { // Now see if we go them { - uptimeMs := int(now.Sub(startTime) / time.Millisecond) + uptimeSeconds := int(now.Sub(startTime) / time.Second) controls := map[string]report.NodeControlData{ docker.UnpauseContainer: {Dead: true}, docker.RestartContainer: {Dead: false}, @@ -80,7 +80,7 @@ func TestContainer(t *testing.T) { "docker_label_foo2": "bar2", "docker_container_state": "running", "docker_container_state_human": c.Container().State.String(), - "docker_container_uptime": strconv.Itoa(uptimeMs), + "docker_container_uptime": strconv.Itoa(uptimeSeconds), "docker_env_FOO": "secret-bar", }).WithLatestControls( controls, diff --git a/probe/host/reporter.go b/probe/host/reporter.go index c0a71c210..0be791dd0 100644 --- a/probe/host/reporter.go +++ b/probe/host/reporter.go @@ -103,7 +103,6 @@ func (r *Reporter) Report() (report.Report, error) { localCIDRs = append(localCIDRs, localNet.String()) } - // TODO: Make sure uptime is accurate also when time travelling. uptime, err := GetUptime() if err != nil { return rep, err @@ -132,7 +131,7 @@ func (r *Reporter) Report() (report.Report, error) { HostName: r.hostName, OS: runtime.GOOS, KernelVersion: kernel, - Uptime: strconv.Itoa(int(uptime / time.Millisecond)), + Uptime: strconv.Itoa(int(uptime / time.Second)), // uptime in seconds ScopeVersion: r.version, }). WithSets(report.MakeSets(). diff --git a/probe/host/reporter_test.go b/probe/host/reporter_test.go index 568ed1924..c3084c378 100644 --- a/probe/host/reporter_test.go +++ b/probe/host/reporter_test.go @@ -25,7 +25,7 @@ func TestReporter(t *testing.T) { host.CPUUsage: report.MakeSingletonMetric(timestamp, 30.0).WithMax(100.0), host.MemoryUsage: report.MakeSingletonMetric(timestamp, 60.0).WithMax(100.0), } - uptime = "3600000" // one hour + uptime = "3600" // one hour kernel = "release version" _, ipnet, _ = net.ParseCIDR(network) )