Skip to content

Log unsuccessful responses in the GitLab Container Registry client

🛩 Context

The rails backend relies heavily on the Container Registry API to get information and/or data out of it.

In !94065 (merged), we added support in the client for a new tags API. This endpoint is paginated.

We implemented that function as the others:

  • return the list of tags if the response is successful.
  • if not successful, return an empty structure.

Again, we used the same design applied to the other methods. One could question if we should do something with erroneous responses? Well, the container registry has its own logs that will surface the problem. Still, on the rails side, we could at least log the error as discussed here.

This MR does exactly that: update the new function so that unsuccessful responses are logged before returning the empty structure.

🔬 What does this MR do and why?

  • Update ContainerRegistry::GitlabApiClient#tags to log an error on erroneous response status codes.
  • Update the related specs.

🖥 Screenshots or screen recordings

n / a

📇 How to set up and validate locally

Follow the instructions in !94065 (merged) to setup a container registry with the metadata database.

  1. Push a container repository image.
  2. Let's try to get the tags from an unknown path:
    client = ContainerRepository.last.gitlab_api_client
    client.tags('foo/bar')
  3. Check the exceptions_json.log:
    {"severity":"ERROR","time":"2022-09-19T15:39:39.483Z","correlation_id":null,"exception.class":"ContainerRegistry::GitlabApiClient::UnsuccessfulResponseError","exception.message":"ContainerRegistry::GitlabApiClient::UnsuccessfulResponseError","user.username":null,"tags.program":"console","tags.locale":"en","tags.feature_category":null,"tags.correlation_id":null,"extra.class":"ContainerRegistry::GitlabApiClient","extra.url":"/gitlab/v1/repositories/foo/bar/tags/list/","extra.status_code":401}

The error from (2.) is properly logged

🛃 MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by David Fernandez

Merge request reports

Loading