feat(managementapi): serve remote container repository statistics (S17 repository statistics on remote repositories plan: 7/8)

Summary

  • Problem: the repository statistics route answers 404 for a remote docker or oci repository, the same answer as a missing one.
  • Impact: API callers, and the monolith sidebar, which can move remote repositories to this route (gitlab#632276) once every format serves them. After this MR, a remote container repository answers 200.
  • Change: the container handler's remote case finds the container_remote_repositories row and counts its cache with the Step 3 query (!3542 (merged)). The body is the existing container shape: the row's artifacts_count, size_bytes and downloads_count, plus images_count, tags_count and manifests_count from the cache.
  • tags_count stays: Step 3 timed the remote tag count at 16.7 ms for 100,000 tags, inside the 100 ms budget. So the plan's fallback, a new response shape without tags_count, is not needed, and api/openapi/v1.yaml does not change.
  • The mistake this avoids: a remote repository also has a container_repositories row, but no cache rows sit under it. Counting through that row would answer 200 with every count at zero. The tests check that the hosted lookup is never called, and the integration test fails on zeros.
  • Downsides:
    • downloads_count is always the stored 0 for remote containers, as S17 says, until #292 gives that path a writer.
    • The API text in api/openapi/v1.yaml and the Bruno docs still say remote answers 404. Step 8 (#1674 (closed)) fixes the text once every format serves remote.

S17 criterion 115, for container:

Criterion Evidence
The container shape, with tags_count matching the tags list TestStatisticsContainerRepository_ServesTheStoredThreeAndTheLiveThree pins the six keys, for hosted and remote. The contract row oci 200 remote repository validates the body. Step 3's integration test checks tags_count against the remote tags list.
The counts equal the remote lists, for docker and oci Step 3's integration test compares the query with the remote image, manifest and tag lists. TestStatisticsContainerRepositoryIntegration_RemoteServesItsCacheOverRealRows serves a seeded cache for one remote docker and one remote oci repository through the real router.
downloads_count is the stored 0 The same integration test.

Checklist

  • Ran it: not against a booted service. The integration test drives the route through the real router and the production stores, on PostgreSQL 17.10. Each remote repository is made by the production create path, with a seeded cache.
  • Interfaces and data: one API answer changes: GET .../statistics on a remote docker or oci repository goes from 404 to 200, with the existing ContainerRepositoryStatistics shape. No schema, storage or configuration change. S17 already describes this answer. The API description text changes in Step 8.
  • Failure: a missing container_remote_repositories row, or a failed lookup, answers the logged 500 that the container image, manifest and referrer routes already use for a remote repository. That log line now also carries repository_id, on those routes too. A failed count answers a logged 500 with the repository id and the container_remote_repositories id, and no partial body. If the client cancels, nothing is written or logged.
  • Rollout: no schema or configuration change. During a deploy, an old pod answers 404 and a new pod answers 200.
  • Hot path: the statistics route only. A remote request runs one point lookup and one count query, the same number as a hosted one.
  • Database: no new or changed query. The count is Step 3's AggregateContainerRemoteRepositoryEntityCounts, whose plan and timing are on !3542 (merged) and in docs/dev/database-query-patterns.md. The lookup is FindRemoteDetailsByRepositoryID, which the container image, manifest and referrer routes already call.
  • Security: no new input, route or permission. The route keeps read_repository. The remote row is found by the request's namespace and the resolved repository id.
  • ADRs: ./scripts/adr-freshness.sh reports the mirror is current (it cannot count internal ADRs). ADR-009: the statistics route has no kind limit, and remote now serves. ADR-021: the permission is unchanged. ADR-007: the count reads the remote cache tables. This MR changes none of them.
  • E2E: no new row. Container statistics have no hosted row either, and the integration test covers remote. docs/user/: no change, because no page there says which kinds the route serves. Conformance: not affected, because no package-client path changes.
  • Simplicity:
    • No new Deps field or Go type. The container statistics interface gets the remote method, and the production store already has it, so the wiring does not change.
    • findContainerRemoteRepositoryChildID now takes only the resolver it reads, not the whole containerReaders value. The other option was a one-field containerReaders here, but a later edit that read another field would panic on this route only.
    • Hosted and remote share one test table for the 200 and one for the 500s.

Merge order

None needed.

  • Step 5 (!3586 (merged)) edits other functions in statistics_repository.go, handler.go and contract_test.go. The two branches merge cleanly, and the merged tree passes go vet (default and integration tags) and the statistics unit tests. Checked at !3586 (merged) b1730fcd98 and this MR's cd00c3d29.
  • !3579 (closed) and !2971 (merged) also edit handler.go, in other places.

Closes #1673 (closed)

Merge request reports

Loading
Loading