Skip to content

daemon: refactor disk-usage endpoint#51436

Merged
thaJeztah merged 7 commits intomoby:masterfrom
thaJeztah:backend_buildcache
Nov 7, 2025
Merged

daemon: refactor disk-usage endpoint#51436
thaJeztah merged 7 commits intomoby:masterfrom
thaJeztah:backend_buildcache

Conversation

@thaJeztah
Copy link
Member

daemon/server/router/system: slightly rewrite logic for legacy

Rewrite the logic to have a better separation between producing legacy
fields, and verbose. We need to preserve / include all items in the
response either if a API >= v1.52 client requested "verbose" or
if we're about to produce legacy fields.

Also switch to using the httputils.BoolValue utility; while we lose
the error for invalid values (which we probably should have as a utility
in httputils), it aligns with values accepted for other boolean values.

daemon/server/router/system: use shorter names and comments

daemon/server/backend: align DiskUsage types with api

Make the "per-object" types aliases for the API type, and remove
the BuildBackend type, as it's not currently used

daemon: align build.DiskUsage() with other disk-usages

Move calculation of the data to the builder backend, to align with
the other type of objects. This also allows us to skip the verbose
data if it's not used.

daemon: remove intermediate vars when collecting diskUsage

Set values directly on the DiskUsage objects instead of using some
intermediate vars, some of which were named slightly confusing due
to them being used both for "totalSize" and "reclaimableSize".

daemon/server/router/system: use early return for disk-usage

Use early return for legacy response. When using API < v1.52, we'd
never return the new fields, so we can return early, and produce the
legacy-fields only.

daemon/server/router/system: simplify constructing response

Now that we separated the legacy response from non-legacy responses,
we can consume the data produced by the backend as-is; the backend
takes care of omitting "verbose" data (leaving the Items slices
empty), and with an early return for the legacy responses, we won't
end up with returning both responses on API < v1.52, but (TBD) still
return both responses for API v1.52.

- Human readable description for the release notes

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah added this to the 29.0.0 milestone Nov 7, 2025
@thaJeztah thaJeztah added status/2-code-review area/daemon Core Engine kind/refactor PR's that refactor, or clean-up code labels Nov 7, 2025
@thaJeztah thaJeztah marked this pull request as ready for review November 7, 2025 17:29
}

// BuildCacheDiskUsage contains disk usage for the build cache.
type BuildCacheDiskUsage struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit comment says "remove the BuildBackend type" - but should be "BuildCacheDiskUsage"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops! Let me fix that, thanks!

I'll push and set the validate-only label, then I'll rebase the other PRs once this is in ❤️

Rewrite the logic to have a better separation between producing legacy
fields, and verbose. We need to preserve / include all items in the
response _either_ if a API >= v1.52 client requested "verbose" _or_
if we're about to produce legacy fields.

Also switch to using the `httputils.BoolValue` utility; while we lose
the error for invalid values (which we probably should have as a utility
in `httputils`), it aligns with values accepted for other boolean values.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Make the "per-object" types aliases for the API type, and remove
the BuildCacheDiskUsage type, as it's not currently used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Move calculation of the data to the builder backend, to align with
the other type of objects. This also allows us to skip the verbose
data if it's not used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Set values directly on the DiskUsage objects instead of using some
intermediate vars, some of which were named slightly confusing due
to them being used both for "totalSize" and "reclaimableSize".

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Use early return for legacy response. When using API < v1.52, we'd
never return the new fields, so we can return early, and produce the
legacy-fields only.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Now that we separated the legacy response from non-legacy responses,
we can consume the data produced by the backend as-is; the backend
takes care of omitting "verbose" data (leaving the `Items` slices
empty), and with an early return for the legacy responses, we won't
end up with returning _both_ responses on API < v1.52, but (TBD) still
return both responses for API v1.52.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah merged commit 4dc87c5 into moby:master Nov 7, 2025
54 checks passed
@thaJeztah thaJeztah deleted the backend_buildcache branch November 7, 2025 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants