Loading
refactor(npm): consolidate metric collectors into metrics.go
Follow-up from the review of !794 (merged) (raised by @jdrpereira), tracked in #248 (closed). Behavior-preserving cleanup — not a plan step, no spec change.
♻️ What this MR does
npm's Prometheus metric collectors and RegisterMetrics were spread across five files: RegisterMetrics lived in buffered.go, and each collector sat next to its handler. The sibling formats keep every vector plus RegisterMetrics in one dedicated file (internal/format/oci/metrics.go, internal/storage/metrics.go). This consolidates npm to match, so the full metric surface and its registration wiring stay in one place — the drift that let the wantSeries gap into !794 (merged).
- Consolidated into
internal/format/npm/metrics.go— the eight operational collectors,RegisterMetrics, and the sharedmetricSubsystemNPMconst, joining the request-level metrics the file already held.
| Collector | Moved from |
|---|---|
bufferedCounterUpdates |
buffered.go |
distTagsCacheBlobMissing, distTagsInlineBuildCollapsed |
disttags.go |
packumentRebuildTotal, packumentRebuildDurationSeconds |
packument_cache.go |
packumentInlineBuildCollapsed |
packument_get.go |
gateRejectionsTotal, coherenceFailuresTotal |
publish_stream.go |
- Emitting logic stays put —
bufferedUpdate,writeGateRejection/gateRejectionReason/writeCoherenceError, the inline-build and rebuild helpers, and the rebuild result label-value consts remain in their handler files; only the collector declarations move. The five source files drop their now-unusedprometheus/fmtimports (packument_cache.gokeepsprometheusforNewTimer). - Doc refresh — the
TODO(buffered)no longer says "this file" (it now namesbuffered.go/bufferedUpdateexplicitly), andmetrics.md,metrics_test.go, and the surviving handler comments point at the new location.
Behavior-preserving: no metric names, labels, help text, or registration order change.
✅ Verification
- Full npm unit suite green, including
metrics_test.go's gatherer and label-enumeration coverage. go build ./...andgo vet(incl.-tags integration) clean;golangci-lint(default tags) reports 0 issues.- Diff is exactly the eight npm files; all eleven metric names (3 request + 8 operational) are present with identical labels and help.
📚 References
- Origin: !794 (merged) review thread (
@jdrpereira) - Convention followed:
internal/format/oci/metrics.go,internal/storage/metrics.go
Related to #248 (closed)