Expose deduplicated size of individual image repositories through the API
Context
We are rolling out a new version of the Container Registry in GitLab.com that includes a metadata database (&5523 (closed)). Among others, this database will allow for efficient storage usage calculations.
This issue is part of a work plan to expose the deduplicated size of individual image repositories in the GitLab UI and API (&7575 (closed)).
The Container Registry has a new API under the /gitlab/v1/
prefix, documented here. This API includes a Get repository details operation which allows retrieving details about image repositories, including their deduplicated size.
Proposal
-
Add support for obtaining the size of the individual image repositories to the Rails container registry client class, using the get repository details operation of the new Container Registry API.
Please note that this issue is for individual image repositories only. Therefore, the
self_with_descendants
option for thesize
query parameter is out of scope. For the purpose of this issue we should set thesize
request query parameter toself
and parsesize_bytes
from the response; -
Expose the size of individual image repositories in the response of the GitLab API Get details of a single repository operation.
For the time being, this will require making an HTTP request against the new Container Registry API for each image repository. Therefore, we should start small and only add support for this to the Get details of a single repository operation, leaving the List registry repositories operation for later. Additionally, we should guard this new behavior behind an optional query parameter
size
(boolean), similartags
:curl --header "PRIVATE-TOKEN: <your_access_token>" \ "https://gitlab.example.com/api/v4/registry/repositories/2?size=true"
These restrictions can be lifted gradually later on, reducing risk and giving us time to identify possible improvements along the way (such as caching of repository sizes).
The response should include a new
size
attribute, which should be filled with the value ofsize_bytes
from the container registry app API response. This is the size in bytes.
Please note that for now, this operation will only be available for GitLab.com and for image repositories created on (or imported into) the new container registry platform backed by the metadata database. The Container Registry API will reply with a 404 Not Found
in case the repository does not exist on the new platform. In case we want to avoid making unnecessary HTTP requests just to find out that the information is not available, in Rails we can restrict this operation for container repositories whose created_at
is after November 2021, which was when we started the new registry platform rollout on GitLab.com.