feat(npm): add a caller label to the npm remote metrics, part 1/2

Stacked MRs

Part MR Scope Reviewable LOC Target
1/2 this MR the caller label, and a virtual read's fills and rewrites 660 main
2/2 !3691 (merged) a virtual read's upstream responses and cache events 724 dmeshcharakou/issue-1060-npm-remote-caller-label

Merge this MR first. Part 2 is blocked on it. When this MR merges, GitLab moves part 2's target to main, and part 2 is rebased onto main.

Reviewable LOC is added plus removed lines, measured at 221d841074 (this MR) and 1efcc0c12b (part 2).

Summary

  • Problem: A user runs npm install against a virtual repository. The virtual repository asks its remote upstreams for each package, but no npm_remote_* metric counted those calls. So these metrics showed only direct reads of remote repositories.
  • Impact: Operators only. Clients see no change.
  • Change: The four npm_remote_* traffic metrics get a caller label, direct or virtual. Every direct read books direct. A virtual read now books two of the four under caller="virtual": the cache fill and the rewrite time. S15 says how.
  • Downsides: Up to twice as many series on the two histograms. A query on them without caller now includes virtual calls, so add {caller="direct"} to keep today's numbers. The rewrite-time histogram now shows no series until its first sample. A virtual read's upstream responses and cache events are part 2.

What a virtual read books

Metric Under caller="virtual"
npm_remote_cache_fill_bytes The fill the call's leader committed.
npm_remote_packument_transform_duration_seconds The rewrite the call's leader ran.
npm_remote_upstream_responses_total Nothing in this MR. Part 2 books it.
npm_remote_cache_events_total Nothing in this MR. Part 2 books it.

Merge order

  • !3480 (merged) seeds these families with two labels. Whichever of the two lands second adds caller to InitRemoteMetrics and InitHealthProbeMetrics, or the seeding panics at startup.
  • !3674 (merged) merges cleanly in either order.

Checklist

  • Ran it: Not against a running service. Unit tests drive the new call sites and the tarball handler. A mutation pass over the new lines found five changes no test caught. Each one now fails a test.
  • Interfaces and data: Prometheus only: a new caller label on four families. No dashboard or alert in this repo reads them. S15, S31, docs/dev/observability.md and internal/format/npm/metrics.md are updated, and two stale budgets in the catalog are fixed (outcome = 26, event = 11).
  • Failure: A label value outside its closed set is logged at Error and dropped, as before. The rewrite-time histogram is the exception: it has no context to log on, and every call passes a constant caller.
  • Rollout: Mid-deploy, old pods publish these series without caller and new pods with it. A sum without caller reads both.
  • Hot path: One histogram observation per committed fill or rewrite on a virtual read, as on a direct read.
  • Database: No.
  • Security: No.
  • ADRs: None apply. ADR-012 covers usage data events, not Prometheus metrics.
  • E2E: None. No scenario row checks these metrics.
  • Simplicity: I used a bare caller because its values mean the same in every format, so the Maven twin can reuse it.

Not covered: Maven (#943), and S15's two deadline counters, which get no caller.

The S15 and S31 edits need a Staff+ approval.

Related to #1060 (closed)

Edited by Dzmitry (Dima) Meshcharakou

Merge request reports

Loading
Loading