Loading
feat(managementapi): serve remote npm repository statistics (S17 repository statistics on remote repositories plan: 6/8)
Summary
- Problem: the repository statistics route answers
404for a remote npm 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 npm repository answers
200. - Change: the npm handler's remote case finds the
npm_remote_repositoriesrow and counts its cache with the Step 2 query (!3541 (merged)). The body has the Maven shape: the row'sartifacts_count,size_bytesanddownloads_count, pluspackages_count,versions_countandfiles_countfrom the cache. It has nodist_tags_count, because the cache keeps no dist-tag rows, and0would say "no dist-tags". - The mistake this avoids: a remote repository also has an
npm_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 npm, 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 fixes the text once every format serves remote.
S17 criterion 115, for npm:
| Criterion | Evidence |
|---|---|
No dist_tags_count key, and the body matches only the Maven shape |
TestStatisticsNpmRepository_RemoteServesTheMavenShape pins the key set to the Maven shape's required fields. The new contract row validates the body. TestContract_RepositoryStatistics_DiscriminatesFormatPayloads already shows such a body matches only the Maven branch. |
| The counts equal the remote lists | Step 2's integration test checks the query against the remote lists (!3541 (merged)). TestStatisticsNpmRepositoryIntegration_RemoteServesItsCacheThroughTheMux checks the route serves those counts from a seeded cache with real stores. |
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, with a remote repository made by the production create path and a seeded cache.
- Interfaces and data: one API answer changes:
GET .../statisticson a remote npm repository goes from404to200with the existingMavenRepositoryStatisticsshape. No schema change, because theRepositoryStatisticsoneOfalready has that shape. No storage or configuration change. S17 already describes this answer. The API description text changes in Step 8. - Failure: a missing
npm_remote_repositoriesrow, or a failed lookup, answers the logged500the remote list routes already use. A failed count answers a logged500with the repository id and thenpm_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 by
(namespace_id, repository_id)and one count query, the same number as a hosted one. - Database: no new or changed query. The count is Step 2's
AggregateNpmRemoteRepositoryEntityCounts, whose plan evidence is on !3541 (merged). The lookup isFindNpmRemoteRepositoryID, which the remote list routes already call. - Security: no new input, route or permission. The route keeps
read_repository. The namespace comes from the request, and the remote row is found by that namespace and the resolved repository id. - ADRs:
./scripts/adr-freshness.shreports the mirror is current (it cannot count internal ADRs with this token). 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. npm 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. The existing npm statistics interface gets the remote method, and the production store already has it, so the wiring does not change. - No new Go type: the Maven type is the shape.
- The remote failure cases join the existing hosted test tables, rather than copying them.
- No new
Merge order
None needed.
- !3579 (closed) and !3574 (merged) also edit
internal/managementapi/handler.go, in other places. - Step 5 (remote Maven statistics, no MR yet) edits other functions in
statistics_repository.go,handler.goandcontract_test.go. It also editsstatistics_repository_integration_test.go, which holdscreateIntegrationRemoteRepository, the helper this MR's integration test calls. If Step 5 renames it, whichever MR merges second updates the call.
Closes #1672 (closed)
Edited by Dzmitry (Dima) Meshcharakou