Use the list repository tags API and its pagination in getContainerRepositoryTags
🌅
Context Rollout issue for feature flag: [Feature flag] Rollout of `use_repository_list_... (#426358 - closed)
Today, we have the epic: Use new container registry API for listing repo... (&10208 - closed) that aims to implement the usage of the new API to list repository tags. After the investigation in #403314 (closed), the list repository tags API endpoint will be updated in container-registry#1012 (closed), container-registry#1000 (closed), and container-registry#1008 (closed) to support the functionalities we need in listing registry tags in the Gitlab UI.
After the three issues in the Container Registry is done, #411265 (closed) then updates ContainerRegistry::GitlabApiClient#tags
, the interface on the rails side to the /gitlab/v1/*
, to support the additional parameters and return value of the list repository tags API endpoint.
In this issue, we then use the updated ContainerRegistry::GitlabApiClient#tags
in the resolver for getContainerRepositoryTags
.
We will be putting this change behind a feature flag to be able to gradually rollout the change.
🗺
Implementation Plan A. Updating the resolve function
In Resolvers::ContainerRepositoryTagsResolver#resolve
, we will have two flows:
- When the feature flag is on and the Gitlab API is supported, we fetch a page from
ContainerRegistry::GitlabApiClient#tags
- Else, we follow the original behaviour
def resolve(sort:, **filters)
if is_gitlab_com_and_feature_flag_on?
# Send in the parameters and get a page from the list registry tags API endpoint
...
Gitlab::graphql::ExternallyPaginatedArray.new(previous_cursor, next_cursor, *tags)
else
# current behaviour here
end
end
As we see above, we will utilize Gitlab::graphql::ExternallyPaginatedArray
to follow the pagination of the list repository tags API.
B. Getting a page from the list repository tags API
def get_tags_page(before: nil, last: nil, sort: nil, name: nil, page_size: 100)
raise ArgumentError, 'not a migrated repository' unless migrated?
raise ArgumentError, 'block not given' unless block
page = gitlab_api_client.tags(self.path,
page_size: page_size,
before: before,
last: last,
sort: sort,
name: name
)
return {} unless page&.key?(:response_body)
# return value here is still up for discussion, please see the Cursors section below
{
tags: transform_tags_page(page[:response_body]),
previous_cursor: # get from page link header,
next_cursor: # get from page link header,
}
end
previous_cursor
and next_cursor
can be fetched from the updates that will be added in container-registry#1012 (closed).
This issue can be reviewed and updated further once the container registry issues are closed