daemon: refactor disk-usage endpoint#51436
Merged
thaJeztah merged 7 commits intomoby:masterfrom Nov 7, 2025
Merged
Conversation
2 tasks
3 tasks
robmry
approved these changes
Nov 7, 2025
| } | ||
|
|
||
| // BuildCacheDiskUsage contains disk usage for the build cache. | ||
| type BuildCacheDiskUsage struct { |
Contributor
There was a problem hiding this comment.
The commit comment says "remove the BuildBackend type" - but should be "BuildCacheDiskUsage"?
Member
Author
There was a problem hiding this comment.
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>
e47ce66 to
71bcd22
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.BoolValueutility; while we losethe 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
Itemsslicesempty), 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)