feat(managementapi): serve remote npm repository statistics (S17 repository statistics on remote repositories plan: 6/8)

Summary

  • Problem: the repository statistics route answers 404 for 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_repositories row and counts its cache with the Step 2 query (!3541 (merged)). The body has the Maven shape: the row's artifacts_count, size_bytes and downloads_count, plus packages_count, versions_count and files_count from the cache. It has no dist_tags_count, because the cache keeps no dist-tag rows, and 0 would say "no dist-tags".
  • The mistake this avoids: a remote repository also has an npm_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 npm, 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 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 .../statistics on a remote npm repository goes from 404 to 200 with the existing MavenRepositoryStatistics shape. No schema change, because the RepositoryStatistics oneOf already 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_repositories row, or a failed lookup, answers the logged 500 the remote list routes already use. A failed count answers a logged 500 with the repository id and the npm_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 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 is FindNpmRemoteRepositoryID, 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.sh reports 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 Deps field. 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.

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.go and contract_test.go. It also edits statistics_repository_integration_test.go, which holds createIntegrationRemoteRepository, 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

Merge request reports

Loading
Loading