Skip to content

fix(auth-server): add histogram to disabled StatsD mock#20799

Open
sreecharan-desu wants to merge 1 commit into
mozilla:mainfrom
sreecharan-desu:fix/auth-server-mock-statsd-histogram
Open

fix(auth-server): add histogram to disabled StatsD mock#20799
sreecharan-desu wants to merge 1 commit into
mozilla:mainfrom
sreecharan-desu:fix/auth-server-mock-statsd-histogram

Conversation

@sreecharan-desu

Copy link
Copy Markdown
Contributor

Because

  • When config.statsd.enabled is false, key_server.js registers a no-op StatsD client in the DI container.
  • Redis metrics code calls this.metrics?.histogram(...). Optional chaining skips null/undefined objects, but if metrics exists without a histogram method, the call throws at runtime.
  • Reported in fxa-auth-server mock statsd lacks of function histogram  #16491.

This pull request

  • Adds a createNoopStatsd() helper that implements increment, timing, histogram, and close.
  • Uses the helper when StatsD is disabled in key_server.js.
  • Adds unit tests covering the no-op client method surface.

Issue that this pull request solves

Closes: #16491

Checklist

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).
  • I have manually reviewed all AI generated code.

How to review (Optional)

  • Key files/areas to focus on: packages/fxa-auth-server/lib/noop-statsd.js, packages/fxa-auth-server/bin/key_server.js
  • Suggested review order: read helper + test first, then the one-line call site change in key_server.js
  • Risky or complex parts: none — behavior change is limited to the disabled-StatsD code path

Test plan

  • yarn jest packages/fxa-auth-server/lib/noop-statsd.spec.ts passes
  • Auth server starts with STATSD_ENABLE=false and redis histogram metrics do not throw

Because:

* When StatsD is disabled, key_server uses a no-op metrics client.
* Redis metrics callers invoke histogram via optional chaining, which
  throws if the method is missing on a non-null metrics object.

This commit:

* Extract a shared createNoopStatsd helper with histogram support.
* Use it when config.statsd.enabled is false.
* Add unit tests for the no-op client method surface.

Fixes mozilla#16491
@sreecharan-desu sreecharan-desu requested a review from a team as a code owner June 28, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fxa-auth-server mock statsd lacks of function histogram

1 participant