mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #83507 from lyft/support-resetting-cpuacct
Prevent returning invalid usageNanoCores value when cpuacct is reset in a live container
This commit is contained in:
commit
ac97b2d65e
@ -649,7 +649,7 @@ func (p *criStatsProvider) getAndUpdateContainerUsageNanoCores(stats *runtimeapi
|
||||
defer p.mutex.Unlock()
|
||||
|
||||
cached, ok := p.cpuUsageCache[id]
|
||||
if !ok || cached.stats.UsageCoreNanoSeconds == nil {
|
||||
if !ok || cached.stats.UsageCoreNanoSeconds == nil || stats.Cpu.UsageCoreNanoSeconds.Value < cached.stats.UsageCoreNanoSeconds.Value {
|
||||
// Cannot compute the usage now, but update the cached stats anyway
|
||||
p.cpuUsageCache[id] = &cpuUsageRecord{stats: stats.Cpu, usageNanoCores: nil}
|
||||
return nil, nil
|
||||
|
@ -891,8 +891,32 @@ func TestGetContainerUsageNanoCores(t *testing.T) {
|
||||
},
|
||||
expected: &value2,
|
||||
},
|
||||
{
|
||||
desc: "should return nil if cpuacct is reset to 0 in a live container",
|
||||
stats: &runtimeapi.ContainerStats{
|
||||
Attributes: &runtimeapi.ContainerAttributes{
|
||||
Id: "1",
|
||||
},
|
||||
Cpu: &runtimeapi.CpuUsage{
|
||||
Timestamp: 2,
|
||||
UsageCoreNanoSeconds: &runtimeapi.UInt64Value{
|
||||
Value: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
cpuUsageCache: map[string]*cpuUsageRecord{
|
||||
"1": {
|
||||
stats: &runtimeapi.CpuUsage{
|
||||
Timestamp: 1,
|
||||
UsageCoreNanoSeconds: &runtimeapi.UInt64Value{
|
||||
Value: 10000000000,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
provider := &criStatsProvider{cpuUsageCache: test.cpuUsageCache}
|
||||
// Before the update, the cached value should be nil
|
||||
|
Loading…
Reference in New Issue
Block a user