Loading
feat(managementapi): serve remote container repository statistics (S17 repository statistics on remote repositories plan: 7/8)
Summary
- Problem: the repository statistics route answers
404for a remotedockerorocirepository, 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_repositoriesrow and counts its cache with the Step 3 query (!3542 (merged)). The body is the existing container shape: the row'sartifacts_count,size_bytesanddownloads_count, plusimages_count,tags_countandmanifests_countfrom the cache. tags_countstays: 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 withouttags_count, is not needed, andapi/openapi/v1.yamldoes not change.- The mistake this avoids: a remote repository also has a
container_repositoriesrow, but no cache rows sit under it. Counting through that row would answer200with every count at zero. The tests check that the hosted lookup is never called, and the integration test fails on zeros. - Downsides:
downloads_countis always the stored0for remote containers, as S17 says, until #292 gives that path a writer.- The API text in
api/openapi/v1.yamland the Bruno docs still say remote answers404. 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 .../statisticson a remotedockerorocirepository goes from404to200, with the existingContainerRepositoryStatisticsshape. No schema, storage or configuration change. S17 already describes this answer. The API description text changes in Step 8. - Failure: a missing
container_remote_repositoriesrow, or a failed lookup, answers the logged500that the container image, manifest and referrer routes already use for a remote repository. That log line now also carriesrepository_id, on those routes too. A failed count answers a logged500with the repository id and thecontainer_remote_repositoriesid, 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
404and a new pod answers200. - 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 indocs/dev/database-query-patterns.md. The lookup isFindRemoteDetailsByRepositoryID, 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.shreports 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
Depsfield or Go type. The container statistics interface gets the remote method, and the production store already has it, so the wiring does not change. findContainerRemoteRepositoryChildIDnow takes only the resolver it reads, not the wholecontainerReadersvalue. The other option was a one-fieldcontainerReadershere, but a later edit that read another field would panic on this route only.- Hosted and remote share one test table for the
200and one for the500s.
- No new
Merge order
None needed.
- Step 5 (!3586 (merged)) edits other functions in
statistics_repository.go,handler.goandcontract_test.go. The two branches merge cleanly, and the merged tree passesgo vet(default and integration tags) and the statistics unit tests. Checked at !3586 (merged)b1730fcd98and this MR'scd00c3d29. - !3579 (closed) and !2971 (merged) also edit
handler.go, in other places.
Closes #1673 (closed)