mirror of
https://github.com/moby/moby.git
synced 2026-08-08 17:11:38 +00:00
Windows network stats were only available via the builtin HCS runtime; the containerd runtime (runhcs shim) reports no network data, so `docker stats` returned empty Networks (0B NET I/O) and TestStatsNetworkStats was skipped. Implement getNetworkStats on Windows to query stats from HNS per endpoint (GetHNSEndpointStats, keyed by the driver's hnsid). GetContainerStats only falls back to it when Networks is empty, leaving the builtin runtime unchanged. Un-skip TestStatsNetworkStats and add a conversion unit test. Signed-off-by: Dawei Wei <wei.dawei.cn@gmail.com>
38 lines
871 B
Go
38 lines
871 B
Go
package daemon
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Microsoft/hcsshim"
|
|
containertypes "github.com/moby/moby/api/types/container"
|
|
"gotest.tools/v3/assert"
|
|
is "gotest.tools/v3/assert/cmp"
|
|
)
|
|
|
|
func TestHNSStatsToNetworkStats(t *testing.T) {
|
|
in := &hcsshim.HNSEndpointStats{
|
|
EndpointID: "endpoint-1",
|
|
InstanceID: "instance-1",
|
|
BytesReceived: 100,
|
|
PacketsReceived: 10,
|
|
DroppedPacketsIncoming: 1,
|
|
BytesSent: 200,
|
|
PacketsSent: 20,
|
|
DroppedPacketsOutgoing: 2,
|
|
}
|
|
|
|
got := hnsStatsToNetworkStats(in)
|
|
|
|
assert.Check(t, is.DeepEqual(got, containertypes.NetworkStats{
|
|
RxBytes: 100,
|
|
RxPackets: 10,
|
|
RxDropped: 1,
|
|
TxBytes: 200,
|
|
TxPackets: 20,
|
|
TxDropped: 2,
|
|
EndpointID: "endpoint-1",
|
|
InstanceID: "instance-1",
|
|
// RxErrors/TxErrors are not reported by HNS and remain zero.
|
|
}))
|
|
}
|