Skip to content

fix(e2e): wait for worker Kafka subscriptions before tests - #5382

Merged
turip merged 2 commits into
openmeterio:mainfrom
turip:feat/worker-subscription-readiness
Oct 27, 2026
Merged

turip merged 2 commits into
openmeterio:mainfrom
turip:feat/worker-subscription-readiness

Conversation

@turip

@turip turip commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Overview

A fresh test stack can accept a subscription request after /healthz succeeds but before the billing consumer selects its starting offsets. With the existing newest-offset policy, that event can be skipped and invoice polling times out.

Expose /healthz/subscriptions on the billing, balance, and notification workers, and wait for it before quickstart and E2E fixtures run. Readiness follows consumer-group sessions and initialized partition claims, including all three balance-worker topic subscriptions. TelemetryServer.Handle provides the route registration API.

Notes for reviewer

The existing Kubernetes health endpoints and Kafka offset policy keep their behavior. This endpoint reports subscription initialization independently of backlog processing and becomes unready when sessions or claims stop. Sink consumer readiness is outside this change; its generated wiring is refreshed for the shared telemetry type.

Validation:

  • Affected Go package tests with race detection passed.
  • Scoped make lint-go-fast passed.
  • A fresh quickstart → full base E2E (including HTTP error checks) → credits-disabled E2E → repeated credits-disabled E2E sequence passed locally against the updated main branch.
  • The same isolated Compose project was reused across all four phases. No project containers, networks, or volumes remained after each teardown.
  • The originally timing-out flat-fee invoice scenario passed in both credits-disabled runs.

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 8239676 and 8cf3c49.

Files selected for processing: 17
  • .github/scripts/run-e2e.sh
  • .github/scripts/run-quickstart.sh
  • app/common/openmeter_balanceworker.go
  • app/common/openmeter_billingworker.go
  • app/common/openmeter_billingworker_test.go
  • app/common/telemetry.go
  • cmd/balance-worker/wire_gen.go
  • cmd/billing-worker/wire_gen.go
  • cmd/notification-service/main.go
  • cmd/notification-service/wire_gen.go
  • cmd/server/wire_gen.go
  • cmd/sink-worker/wire_gen.go
  • e2e/Makefile
  • openmeter/watermill/driver/kafka/README.md
  • openmeter/watermill/driver/kafka/subscriber.go
  • openmeter/watermill/driver/kafka/subscriptions.go
  • openmeter/watermill/driver/kafka/subscriptions_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

Walkthrough

The change adds Kafka subscription readiness tracking, exposes /healthz/subscriptions for worker services, and updates E2E and Quickstart startup checks to wait for that endpoint.

Changes: Subscription readiness

Layer / File(s) Summary
Track Kafka subscription initialization
openmeter/watermill/driver/kafka/subscriber.go, openmeter/watermill/driver/kafka/subscriptions.go, openmeter/watermill/driver/kafka/subscriptions_test.go
SubscriberOptions can accept a status tracker. The tracker reports configured topics, active sessions, assigned partitions, and initialized partitions. Its HTTP handler returns 503 when the status is not ready. Tests cover readiness and session and claim lifecycle changes.
Expose readiness from worker services
app/common/telemetry.go, app/common/openmeter_*worker.go, app/common/openmeter_billingworker_test.go, cmd/balance-worker/wire_gen.go, cmd/billing-worker/wire_gen.go, cmd/notification-service/*, cmd/server/wire_gen.go, cmd/sink-worker/wire_gen.go
TelemetryServer supports additional routes. Billing, balance, and notification services register /healthz/subscriptions and pass status trackers to their Kafka subscribers. Generated wiring passes the new dependencies. A test checks that existing health responses remain unchanged.
Wait for readiness during startup
.github/scripts/run-e2e.sh, .github/scripts/run-quickstart.sh, e2e/Makefile, openmeter/watermill/driver/kafka/README.md
E2E and Quickstart scripts wait for subscriptions endpoints before running tests. The README describes the endpoint’s readiness conditions and response fields.

Priority: Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Worker
  participant NewSubscriber
  participant ConsumerGroupHandler
  participant SubscriptionStatus
  participant HealthClient
  Worker->>NewSubscriber: Supplies SubscriptionStatus
  NewSubscriber->>ConsumerGroupHandler: Installs observer for consumer-group events
  ConsumerGroupHandler->>SubscriptionStatus: Records sessions and initialized claims
  HealthClient->>SubscriptionStatus: Requests GET /healthz/subscriptions
  SubscriptionStatus-->>HealthClient: Returns readiness snapshot with 200 or 503
Loading

Possibly related PRs

  • openmeterio/openmeter#5355: Both changes update Quickstart startup synchronization; this PR adds waits for Kafka subscription health endpoints.

Suggested reviewers: galexihu, chrisgacsal

Merge Risk: Minimal · up to 8cf3c

The subscription-readiness change has no established blocker in the supplied evidence and is mergeable after normal checks.

Pre-merge checks: Passed 4
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: E2E tests now wait for worker Kafka subscriptions before running.
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.
Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@turip turip added the kind/bug Something isn't working label Oct 27, 2026
@turip
turip marked this pull request as ready for review October 27, 2026 13:19
@turip
turip requested a review from a team as a code owner October 27, 2026 13:19
@turip turip added the release-note/misc Miscellaneous changes label Oct 27, 2026
@turip
turip merged commit 9a85bc9 into openmeterio:main Oct 27, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working release-note/misc Miscellaneous changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants