Make kubelet report usageNanoCores for node on Windows
This commit is contained in:
@@ -38,6 +38,7 @@ func (f fakeWinNodeStatsClient) startMonitoring() error {
|
||||
func (f fakeWinNodeStatsClient) getNodeMetrics() (nodeMetrics, error) {
|
||||
return nodeMetrics{
|
||||
cpuUsageCoreNanoSeconds: 123,
|
||||
cpuUsageNanoCores: 23,
|
||||
memoryPrivWorkingSetBytes: 1234,
|
||||
memoryCommittedBytes: 12345,
|
||||
timeStamp: timeStamp,
|
||||
@@ -78,6 +79,11 @@ func TestWinContainerInfos(t *testing.T) {
|
||||
Total: 123,
|
||||
},
|
||||
},
|
||||
CpuInst: &cadvisorapiv2.CpuInstStats{
|
||||
Usage: cadvisorapiv2.CpuInstUsage{
|
||||
Total: 23,
|
||||
},
|
||||
},
|
||||
Memory: &cadvisorapi.MemoryStats{
|
||||
WorkingSet: 1234,
|
||||
Usage: 12345,
|
||||
@@ -100,6 +106,7 @@ func TestWinContainerInfos(t *testing.T) {
|
||||
assert.Equal(t, actualRootInfos["/"].Spec, infos["/"].Spec)
|
||||
assert.Equal(t, len(actualRootInfos["/"].Stats), len(infos["/"].Stats))
|
||||
assert.Equal(t, actualRootInfos["/"].Stats[0].Cpu, infos["/"].Stats[0].Cpu)
|
||||
assert.Equal(t, actualRootInfos["/"].Stats[0].CpuInst, infos["/"].Stats[0].CpuInst)
|
||||
assert.Equal(t, actualRootInfos["/"].Stats[0].Memory, infos["/"].Stats[0].Memory)
|
||||
}
|
||||
|
||||
@@ -123,6 +130,34 @@ func TestWinVersionInfo(t *testing.T) {
|
||||
KernelVersion: "v42"})
|
||||
}
|
||||
|
||||
func TestConvertCPUValue(t *testing.T) {
|
||||
testCases := []struct {
|
||||
cpuValue uint64
|
||||
expected uint64
|
||||
}{
|
||||
{cpuValue: uint64(50), expected: uint64(2000000000)},
|
||||
{cpuValue: uint64(0), expected: uint64(0)},
|
||||
{cpuValue: uint64(100), expected: uint64(4000000000)},
|
||||
}
|
||||
var cpuCores = 4
|
||||
|
||||
for _, tc := range testCases {
|
||||
p := perfCounterNodeStatsClient{}
|
||||
newValue := p.convertCPUValue(cpuCores, tc.cpuValue)
|
||||
assert.Equal(t, newValue, tc.expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCPUUsageNanoCores(t *testing.T) {
|
||||
p := perfCounterNodeStatsClient{}
|
||||
p.cpuUsageCoreNanoSecondsCache = cpuUsageCoreNanoSecondsCache{
|
||||
latestValue: uint64(5000000000),
|
||||
previousValue: uint64(2000000000),
|
||||
}
|
||||
cpuUsageNanoCores := p.getCPUUsageNanoCores()
|
||||
assert.Equal(t, cpuUsageNanoCores, uint64(300000000))
|
||||
}
|
||||
|
||||
func getClient(t *testing.T) Client {
|
||||
f := fakeWinNodeStatsClient{}
|
||||
c, err := newClient(f)
|
||||
|
Reference in New Issue
Block a user