fix(npm): book no fetch leg when a virtual winner serves a fresh row

Summary

  • Problem: A tarball read through an npm virtual repository can count an upstream fetch that never happened. Between our lookup and our fetch, the row becomes fresh again: another read filled it, or another read's 304 refreshed it. Our fetch then serves that row and sends nothing upstream.
  • Impact: Operators only. npm_virtual_upstream_requests_total{leg="fetch"} reads a bit high when many cold reads ask for the same tarball at once. Clients see no change.
  • Change: The recorder now skips FreshCacheHit, the same way it already skips coalesced followers. Maven's recorder already does this.
  • Downsides: None. The upstream's own result on npm_virtual_resolve doesn't change.

Checklist

  • Ran it: No. It's one condition on a metric. Two new tests pin it, and both fail on main with 1 instead of 0: the recorder test, and one through the real SingleFlight. A 304 row checks that a real conditional GET still books one leg.
  • Interfaces and data: Only this metric's value. S31 already says the counter counts requests the read sent, so the spec doesn't change. The two metric catalogs now name this case.
  • Failure: n/a, no new error path.
  • Rollout: n/a, no schema or config change.
  • Hot path: No, one more boolean check.
  • Database: No.
  • Security: No.
  • ADRs: None apply. ADR-012 covers usage data events, not Prometheus metrics.
  • E2E: None. No scenario row checks this counter.
  • Simplicity: This is already the smallest fix: one condition, the same one Maven uses.

This merges in either order with !3677 (merged), the #1060 (closed) MR: both edit the same five files (virtual_observe.go, two test files and the two metric catalogs), on different lines. git merge-tree shows no conflict.

Follow-up: #1794 tracks one remote.FetchResult method that says whether a fetch went upstream, so observers stop checking the two fields by hand.

Related to #1060 (closed)

Edited by Dzmitry (Dima) Meshcharakou

Merge request reports

Loading
Loading