File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -649,7 +649,7 @@ func (p *criStatsProvider) getAndUpdateContainerUsageNanoCores(stats *runtimeapi
649
649
defer p .mutex .Unlock ()
650
650
651
651
cached , ok := p .cpuUsageCache [id ]
652
- if ! ok || cached .stats .UsageCoreNanoSeconds == nil {
652
+ if ! ok || cached .stats .UsageCoreNanoSeconds == nil || stats . Cpu . UsageCoreNanoSeconds . Value < cached . stats . UsageCoreNanoSeconds . Value {
653
653
// Cannot compute the usage now, but update the cached stats anyway
654
654
p .cpuUsageCache [id ] = & cpuUsageRecord {stats : stats .Cpu , usageNanoCores : nil }
655
655
return nil , nil
Original file line number Diff line number Diff line change @@ -881,8 +881,32 @@ func TestGetContainerUsageNanoCores(t *testing.T) {
881
881
},
882
882
expected : & value2 ,
883
883
},
884
+ {
885
+ desc : "should return nil if cpuacct is reset to 0 in a live container" ,
886
+ stats : & runtimeapi.ContainerStats {
887
+ Attributes : & runtimeapi.ContainerAttributes {
888
+ Id : "1" ,
889
+ },
890
+ Cpu : & runtimeapi.CpuUsage {
891
+ Timestamp : 2 ,
892
+ UsageCoreNanoSeconds : & runtimeapi.UInt64Value {
893
+ Value : 0 ,
894
+ },
895
+ },
896
+ },
897
+ cpuUsageCache : map [string ]* cpuUsageRecord {
898
+ "1" : {
899
+ stats : & runtimeapi.CpuUsage {
900
+ Timestamp : 1 ,
901
+ UsageCoreNanoSeconds : & runtimeapi.UInt64Value {
902
+ Value : 10000000000 ,
903
+ },
904
+ },
905
+ },
906
+ },
907
+ expected : nil ,
908
+ },
884
909
}
885
-
886
910
for _ , test := range tests {
887
911
provider := & criStatsProvider {cpuUsageCache : test .cpuUsageCache }
888
912
// Before the update, the cached value should be nil
You can’t perform that action at this time.
0 commit comments