Skip to content

Expose downloads_count and downloaded_at of Maven cache entries in APIs

🪧 Context

This is a follow up of Add downloads analytics in the virtual registry... (!196689 - merged) • David Fernandez • 18.3 where we added some metrics to the maven virtual registry cache entry model.

For more details, see the context there.

This MR expose the metrics in the entities classes so that they are exposed in the related Rest API endpoints.

🤔 What does this MR do and why?

  • Expose downloads_count and downloaded_at of Maven cache entries in the related API endpoints
  • Update the related specs.

📚 References

🦄 Screenshots or screen recordings

No UI changes

⚙️ How to set up and validate locally

Requirements:

  • Have a GitLab instance with an EE license as the maven virtual registry is an EE only feature.
  • Have a top level group id ready (maintainer access level).
  • Have a PAT ready (scope api).

Let's create a virtual registry and an upstream:

# create the registry object and note the id
$ curl -X POST -H "PRIVATE-TOKEN: <PAT>" "http://gdk.test:8000/api/v4/groups/<top level group id>/-/virtual_registries/packages/maven/registries?name=testing_counters"

# create the upstream and note the id
$ curl -H "PRIVATE-TOKEN: <PAT>" --data-urlencode 'url=https://repo1.maven.org/maven2' --data-urlencode 'name=upstream' -X POST http://gdk.test:8000/api/v4/virtual_registries/packages/maven/registries/<registry id>/upstreams

Pull a file through the registry/upstream:

$ curl --header "Private-Token: <PAT>" "http://gdk.test:8000/api/v4/virtual_registries/packages/maven/<registry id>/org/eclipse/jetty/jetty-client/12.0.19/jetty-client-12.0.19.pom"

Now, let's browse the cache entries of the upstream:

$ curl -H "Private-Token: <PAT>" "http://gdk.test:8000/api/v4/virtual_registries/packages/maven/upstreams/<upstream id>/cache_entries"
[
  {
    "id": "MjQxIC9vcmcvZWNsaXBzZS9qZXR0eS9qZXR0eS1jbGllbnQvMTIuMC4xOS9qZXR0eS1jbGllbnQtMTIuMC4xOS5wb20=",
    "group_id": 24,
    "upstream_id": 241,
    "upstream_checked_at": "2025-08-28T08:49:29.461Z",
    "file_md5": "32f2a2872c289c105485403aae29cba3",
    "file_sha1": "dd567c3708a83373db990c18916dbdc42e9e30ab",
    "size": 5495,
    "relative_path": "/org/eclipse/jetty/jetty-client/12.0.19/jetty-client-12.0.19.pom",
    "upstream_etag": "\"32f2a2872c289c105485403aae29cba3\"",
    "content_type": "text/xml",
    "created_at": "2025-08-28T08:49:29.474Z",
    "updated_at": "2025-08-28T08:49:29.474Z",
    "downloads_count": 1,
    "downloaded_at": "2025-08-28T08:59:35.313Z"
  }
]

Notice the presence of the fields downloads_count and downloaded_at. The changes behave as expected

⚠️ Their values are not updated in real time. You need to wait at least 10 minutes so that the metrics temporary stored in Redis are flushed in the database.

🏁 MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by David Fernandez

Merge request reports

Loading