Fix dashboard image disk usage calculation (#1461)
* fix dashboard image disk usage calculation * preserve image size fallback behavior
This commit is contained in:
1 parent
2a9299f932
commit
560b21e03f
4 files changed
+95
-4
No files matched your search
@@ -0,0 +1,32 @@
|
||||
export interface DockerDiskUsageLike {
|
||||
LayersSize?: unknown;
|
||||
ImageUsage?: {
|
||||
TotalSize?: unknown;
|
||||
} | null;
|
||||
Images?: Array<{
|
||||
Size?: unknown;
|
||||
}> | null;
|
||||
}
|
||||
|
||||
function asNonNegativeFiniteNumber(value: unknown): number | null {
|
||||
return typeof value === 'number' && Number.isFinite(value) && value >= 0
|
||||
? value
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Docker's aggregate image disk usage without double-counting shared layers.
|
||||
*
|
||||
* `Images[].Size` is each image's virtual size (shared + unique), so adding those
|
||||
* values overstates disk usage whenever images share layers. Docker exposes the
|
||||
* deduplicated total as `ImageUsage.TotalSize` in the current API and as
|
||||
* `LayersSize` in the legacy response shape.
|
||||
*/
|
||||
export function getImageDiskUsageTotalSize(
|
||||
diskUsage: DockerDiskUsageLike | null | undefined
|
||||
): number | null {
|
||||
const currentTotal = asNonNegativeFiniteNumber(diskUsage?.ImageUsage?.TotalSize);
|
||||
if (currentTotal !== null) return currentTotal;
|
||||
|
||||
return asNonNegativeFiniteNumber(diskUsage?.LayersSize);
|
||||
}
|
||||
Reference in new issue
Block a user