Skip to content

Add X-Request-ID header to member publisher messages#268

Merged
mliu33 merged 4 commits into
mainfrom
claude/zealous-mccarthy-Wt1vU
Jun 4, 2026
Merged

Add X-Request-ID header to member publisher messages#268
mliu33 merged 4 commits into
mainfrom
claude/zealous-mccarthy-Wt1vU

Conversation

@hmchangw
Copy link
Copy Markdown
Owner

@hmchangw hmchangw commented Jun 3, 2026

Summary

Propagate correlation IDs as X-Request-ID headers in both canonical and frontdoor member publisher messages to enable end-to-end request tracing across the pipeline.

Changes

  • canonicalMemberPublisher.Publish: Now uses PublishMsg with a nats.Msg that includes the X-Request-ID header set to the corrID parameter. Previously the corrID was ignored.
  • frontdoorMemberPublisher.Publish: Now uses PublishMsg with a nats.Msg that includes the X-Request-ID header set to the corrID parameter. Previously used PublishRequest without headers.
  • Test coverage: Added two new tests:
    • TestCanonicalMemberPublisher_SetsRequestIDHeader: Verifies canonical publishes carry the correlation ID as the X-Request-ID header
    • TestFrontdoorMemberPublisher_SetsRequestIDHeader: Verifies frontdoor publishes carry the correlation ID as the X-Request-ID header
  • Imports: Added "github.com/hmchangw/chat/pkg/natsutil" to both files to access RequestIDHeader constant

Implementation Details

Both publishers now construct a nats.Msg with headers before publishing, allowing the correlation ID to flow through downstream services (room-worker and room-service) that require or validate the X-Request-ID header. This ensures request tracing is consistent across the entire member addition pipeline.

https://claude.ai/code/session_014eeLP8ENEQxFhC4SjaAY27

Summary by CodeRabbit

  • Bug Fixes

    • Correlation IDs are now propagated in request headers for published member messages (canonical and frontdoor).
  • New Features

    • Sustained-members workload now performs a preflight capacity check and will refuse to start if requested rate/duration exceeds capacity, reporting achievable limits.
  • Documentation

    • Updated members workload docs and adjusted the members-medium candidate pool size.
  • Tests

    • Added tests for request-ID headers and sustained-capacity validation.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

Warning

Review limit reached

@hmchangw, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 53 minutes and 32 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fdb59330-0a86-45fc-8766-505c7fc9bd81

📥 Commits

Reviewing files that changed from the base of the PR and between 045542d and 785e8bd.

📒 Files selected for processing (8)
  • tools/loadgen/README.md
  • tools/loadgen/main.go
  • tools/loadgen/members.go
  • tools/loadgen/members_capacity_test.go
  • tools/loadgen/members_generator.go
  • tools/loadgen/members_publisher.go
  • tools/loadgen/members_publisher_test.go
  • tools/loadgen/members_test.go
📝 Walkthrough

Walkthrough

Adds NATS request-id header propagation to canonical and frontdoor member publishers and tests that verify the header; introduces sustained-capacity helpers and a preflight validation that runs before NATS setup, updates the members-medium preset and README, and adds unit/integration tests for capacity logic.

Changes

Member Publisher Request ID Headers

Layer / File(s) Summary
Request ID header propagation in publishers
tools/loadgen/members_publisher.go
Imports natsutil and updates canonical and frontdoor publishers to build nats.Msg with natsutil.RequestIDHeader set to corrID; frontdoor messages set Reply and both use PublishMsg.
Request ID header verification tests
tools/loadgen/members_publisher_test.go
Adds tests TestCanonicalMemberPublisher_SetsRequestIDHeader and TestFrontdoorMemberPublisher_SetsRequestIDHeader that subscribe, publish with a correlation ID, and assert the received message header matches.

Sustained Capacity Preflight

Layer / File(s) Summary
Capacity contract & helpers
tools/loadgen/members_generator.go
Add ErrInsufficientPool, SustainableOps, and ValidateSustainedCapacity to compute sustained add-member capacity and return wrapped, actionable errors when insufficient.
Preflight wiring in CLI/runtime
tools/loadgen/main.go
Build sustained fixtures/pools before connecting to NATS, call ValidateSustainedCapacity(...), and abort with exit code 2 on failure; remove duplicate later fixture build.
Preset & README updates
tools/loadgen/members.go, tools/loadgen/README.md
Increase members-medium CandidatePool to 900 and update README to document new pool sizing and the changed sustained-mode behavior (refuse to start and report achievable max).
Capacity unit & preset tests
tools/loadgen/members_capacity_test.go
Add tests for SustainableOps and ValidateSustainedCapacity (within budget, at boundary, oversubscribed, too small, zero usersPerAdd) and a preset integration test verifying members-medium default invocation is satisfiable.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • hmchangw/chat#203: Adds the original loadgen member-add publishers with frontdoor request/reply correlation; this PR extends those publishers with request-id header propagation.

Suggested reviewers

  • mliu33
  • Joey0538

Poem

🐰 I hopped through headers, small and spry,
I set corrIDs for messages flying by.
I checked the pools before the run began,
Now publishers and tests all follow the plan.
Hip-hop hooray — payloads and IDs align!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main change: adding the X-Request-ID header to member publisher messages, which is the primary focus of the code modifications.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/zealous-mccarthy-Wt1vU

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

claude added 4 commits June 4, 2026 05:12
The members-sustained (and members-capacity) generators mint a corrID via
idgen.GenerateRequestID() but the canonical and frontdoor member publishers
never put it on the NATS message. Backend services require the header:
room-worker rejects canonical events with no X-Request-ID as a permanent
error, and room-service requires it on the frontdoor request. Stamp corrID
as the X-Request-ID header on both publish paths so requests are accepted
and trace end-to-end, matching the daily scenario's pattern.

https://claude.ai/code/session_014eeLP8ENEQxFhC4SjaAY27
…nfig

Candidate accounts are single-use (once added they're room members and
can't be re-added; baseline+pool is capped at MAX_ROOM_SIZE), so a sustained
run can make at most rooms × floor(pool/usersPerAdd) publishes. The default
invocation (rate=100, duration=60s, users-per-add=10 = 6000 ops) exceeded
every preset's budget, so the run always aborted with ErrPoolsExhausted —
members-medium ran ~50s before failing, smaller presets exhausted during
warmup.

- Add a preflight capacity guard (SustainableOps + ValidateSustainedCapacity)
  that fails fast with exit 2 before any NATS/store work, printing the
  achievable max --rate/--duration for the preset (or steering to a larger
  preset when it's too small to sustain any sensible run).
- Right-size members-medium's candidate pool 500 -> 900 (baseline 100 + 900
  = 1000 = MAX_ROOM_SIZE) so the documented default command completes with
  margin (9000-op budget vs 6000-op demand).
- Update README preset table and the over-capacity guidance.

https://claude.ai/code/session_014eeLP8ENEQxFhC4SjaAY27
700 rooms x baseline 10 x candidate pool 990 yields 69,300 add-member ops,
enough to sustain rate=1000/60s (60,000 ops) at the default users-per-add=10.
Pool stays capped at MAX_ROOM_SIZE; capacity scales via room count.

https://claude.ai/code/session_014eeLP8ENEQxFhC4SjaAY27
Capacity mode grows each room to --target-size from its single-use pool and
never sends a partial batch, so a room with pool P reaches at most
baseline + floor(P/users-per-add)*users-per-add. ValidateCapacityTarget rejects
an unreachable target before any NATS/store work, naming how many rooms fall
short and the reachable ceiling, instead of silently under-filling rooms.

https://claude.ai/code/session_014eeLP8ENEQxFhC4SjaAY27
@hmchangw hmchangw force-pushed the claude/zealous-mccarthy-Wt1vU branch from f4afb27 to 785e8bd Compare June 4, 2026 05:12
Copy link
Copy Markdown
Collaborator

@mliu33 mliu33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@mliu33 mliu33 merged commit c8048eb into main Jun 4, 2026
6 checks passed
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.

3 participants