mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
address comments
This commit is contained in:
parent
99a7a0a53b
commit
e6e8615db3
@ -207,7 +207,8 @@ func (p *perfCounterNodeStatsClient) convertCPUValue(cpuCores int, cpuValue uint
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *perfCounterNodeStatsClient) getCPUUsageNanoCores() uint64 {
|
func (p *perfCounterNodeStatsClient) getCPUUsageNanoCores() uint64 {
|
||||||
cpuUsageNanoCores := (p.cpuUsageCoreNanoSecondsCache.latestValue - p.cpuUsageCoreNanoSecondsCache.previousValue) * uint64(time.Second/time.Nanosecond) / uint64(defaultCachePeriod)
|
cachePeriodSeconds := uint64(defaultCachePeriod / time.Second)
|
||||||
|
cpuUsageNanoCores := (p.cpuUsageCoreNanoSecondsCache.latestValue - p.cpuUsageCoreNanoSecondsCache.previousValue) / cachePeriodSeconds
|
||||||
return cpuUsageNanoCores
|
return cpuUsageNanoCores
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,13 +149,25 @@ func TestConvertCPUValue(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetCPUUsageNanoCores(t *testing.T) {
|
func TestGetCPUUsageNanoCores(t *testing.T) {
|
||||||
p := perfCounterNodeStatsClient{}
|
testCases := []struct {
|
||||||
p.cpuUsageCoreNanoSecondsCache = cpuUsageCoreNanoSecondsCache{
|
latestValue uint64
|
||||||
latestValue: uint64(5000000000),
|
previousValue uint64
|
||||||
previousValue: uint64(2000000000),
|
expected uint64
|
||||||
|
}{
|
||||||
|
{latestValue: uint64(0), previousValue: uint64(0), expected: uint64(0)},
|
||||||
|
{latestValue: uint64(2000000000), previousValue: uint64(0), expected: uint64(200000000)},
|
||||||
|
{latestValue: uint64(5000000000), previousValue: uint64(2000000000), expected: uint64(300000000)},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
p := perfCounterNodeStatsClient{}
|
||||||
|
p.cpuUsageCoreNanoSecondsCache = cpuUsageCoreNanoSecondsCache{
|
||||||
|
latestValue: tc.latestValue,
|
||||||
|
previousValue: tc.previousValue,
|
||||||
|
}
|
||||||
|
cpuUsageNanoCores := p.getCPUUsageNanoCores()
|
||||||
|
assert.Equal(t, cpuUsageNanoCores, tc.expected)
|
||||||
}
|
}
|
||||||
cpuUsageNanoCores := p.getCPUUsageNanoCores()
|
|
||||||
assert.Equal(t, cpuUsageNanoCores, uint64(300000000))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getClient(t *testing.T) Client {
|
func getClient(t *testing.T) Client {
|
||||||
|
Loading…
Reference in New Issue
Block a user