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 @@ -891,8 +891,32 @@ func TestGetContainerUsageNanoCores(t *testing.T) {
891
891
},
892
892
expected : & value2 ,
893
893
},
894
+ {
895
+ desc : "should return nil if cpuacct is reset to 0 in a live container" ,
896
+ stats : & runtimeapi.ContainerStats {
897
+ Attributes : & runtimeapi.ContainerAttributes {
898
+ Id : "1" ,
899
+ },
900
+ Cpu : & runtimeapi.CpuUsage {
901
+ Timestamp : 2 ,
902
+ UsageCoreNanoSeconds : & runtimeapi.UInt64Value {
903
+ Value : 0 ,
904
+ },
905
+ },
906
+ },
907
+ cpuUsageCache : map [string ]* cpuUsageRecord {
908
+ "1" : {
909
+ stats : & runtimeapi.CpuUsage {
910
+ Timestamp : 1 ,
911
+ UsageCoreNanoSeconds : & runtimeapi.UInt64Value {
912
+ Value : 10000000000 ,
913
+ },
914
+ },
915
+ },
916
+ },
917
+ expected : nil ,
918
+ },
894
919
}
895
-
896
920
for _ , test := range tests {
897
921
provider := & criStatsProvider {cpuUsageCache : test .cpuUsageCache }
898
922
// Before the update, the cached value should be nil
You can’t perform that action at this time.
0 commit comments