From fc62b8c3842c5b50c4e293b3ad4a794f5355efbe Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Thu, 25 Jun 2015 11:30:36 -0700 Subject: [PATCH 1/2] Copy stats before we convert them. Fix # 782 --- container/docker/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container/docker/handler.go b/container/docker/handler.go index 3476f4c4..9921a821 100644 --- a/container/docker/handler.go +++ b/container/docker/handler.go @@ -276,7 +276,7 @@ func (self *dockerContainerHandler) GetStats() (*info.ContainerStats, error) { } func convertInterfaceStats(stats *info.InterfaceStats) { - net := stats + net := *stats // Ingress for host veth is from the container. // Hence tx_bytes stat on the host veth is actually number of bytes received by the container. From ee119e26f19eb7e93bc3f21fd1b2a954643e007c Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Thu, 25 Jun 2015 11:36:58 -0700 Subject: [PATCH 2/2] Add a test for differing network stats. --- integration/tests/api/docker_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/integration/tests/api/docker_test.go b/integration/tests/api/docker_test.go index f21db5b8..0dc87d9d 100644 --- a/integration/tests/api/docker_test.go +++ b/integration/tests/api/docker_test.go @@ -249,7 +249,7 @@ func TestDockerContainerNetworkStats(t *testing.T) { defer fm.Cleanup() // Wait for the container to show up. - containerId := fm.Docker().RunBusybox("ping", "www.google.com") + containerId := fm.Docker().RunBusybox("sh", "-c", "wget www.google.com && ping www.google.com") waitForContainer(containerId, fm) request := &info.ContainerInfoRequest{ @@ -261,7 +261,11 @@ func TestDockerContainerNetworkStats(t *testing.T) { // Checks for NetworkStats. stat := containerInfo.Stats[0] - assert.NotEqual(t, 0, stat.Network.TxBytes, "Network tx bytes should not be zero") - assert.NotEqual(t, 0, stat.Network.TxPackets, "Network tx packets should not be zero") - // TODO(vmarmol): Can probably do a better test with two containers pinging each other. + assert := assert.New(t) + assert.NotEqual(0, stat.Network.TxBytes, "Network tx bytes should not be zero") + assert.NotEqual(0, stat.Network.TxPackets, "Network tx packets should not be zero") + assert.NotEqual(0, stat.Network.RxBytes, "Network rx bytes should not be zero") + assert.NotEqual(0, stat.Network.RxPackets, "Network rx packets should not be zero") + assert.NotEqual(stat.Network.RxBytes, stat.Network.TxBytes, "Network tx and rx bytes should not be equal") + assert.NotEqual(stat.Network.RxPackets, stat.Network.TxPackets, "Network tx and rx packets should not be equal") }