Cumulative stats can't decrease

During removal of the container a stat value might be reported as zero; in this case the caluclation could end up with an extremely large number.  If the cumulative stat decreases report zero.

Signed-off-by: James Sturtevant <jstur@microsoft.com>
This commit is contained in:
James Sturtevant
2024-08-28 22:31:05 +00:00
parent 283149df7d
commit f6677a4ec5
2 changed files with 22 additions and 8 deletions

View File

@@ -224,6 +224,11 @@ func (c *criService) getUsageNanoCores(containerID string, isSandbox bool, curre
return 0, nil
}
// can't go backwards, this value might come in as 0 if the container was just removed
if currentUsageCoreNanoSeconds < oldStats.UsageCoreNanoSeconds {
return 0, nil
}
newUsageNanoCores := uint64(float64(currentUsageCoreNanoSeconds-oldStats.UsageCoreNanoSeconds) /
float64(nanoSeconds) * float64(time.Second/time.Nanosecond))