Maven VReg: Move the cache_validity_period column to the upstreams table

Context

In Maven virtual registry MVC (API only interactions) (&14137 - closed), we have the virtual_registries_packages_maven_registries database table that hosts the column cache_validity_period. This column holds the duration in hours, after which the cache will be considered stale, and the registry should check for a fresh copy on the upstream.

At the beginning of the feature implementation, the motive to put this column in the registries table was the desire to avoid making users have to set up multiple similar periods for the many upstreams support. Later, with the idea of shared upstreams, it makes less sense to have the cache_validity_hours on the registry level. One registry could say that for upstream U, the cache is valid for 1.hour and a second registry could say 1.day for the exact same upstream U. We believe it isn't wise to allow such confusion or mix of settings.

So, we decided to move this column to the virtual_registries_packages_maven_upstreams table.

What does this MR do?

  • Add cache_validity_period column to the virtual_registries_packages_maven_upstreams database table.
  • Ignore virtual_registries_packages_maven_registries' cache_validity_period column to be dropped in the next milestone.
  • Replace any usage for the old cache_validity_period with the new one in the codebase.
  • Update the specs accordingly.

MR acceptance checklist

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

Screenshots or screen recordings

N/A

How to set up and validate locally

  1. Enable the feature flag : Feature.enable(:virtual_registry_maven).

  2. Make sure you have the dependency proxy enabled in your GDK, or simply comment out this line for easier testing.

  3. Have a PAT and a root group (any visibility) ready.

  4. In rails console, create a new registry:

    registry = ::VirtualRegistries::Packages::Maven::Registry.create!(group: <root_group>)
  5. From your terminal, create a new upstream and pass a value for cache_validity_period:

    curl -i -H 'Content-Type: application/json' \
       -d '{ "url": "https://maven.test", "username": "test", "password": "password", "cache_validity_period": 5 }' \
       -X POST \
       http://root:<PAT>@gdk.test:3000/api/v4/virtual_registries/packages/maven/registries/<registry_id>/upstreams
  6. Update cache_validity_period's value

    curl -i -H 'Content-Type: application/json' \
       -d '{ "cache_validity_hours": 10 }' \
       -X PATCH \
       http://root:<PAT>@gdk.test:3000/api/v4/virtual_registries/packages/maven/registries/<registry_id>/upstreams/<upstream_id>
  7. Follow these steps to test that pulling from the cache still works as usual after moving the column from the registry to the upstream

Related to #500664 (closed)

Edited by David Fernandez

Merge request reports

Loading