Skip to content

feat: add async invoice collection event - #4625

Merged
turip merged 3 commits into
mainfrom
feat/async-invoice-collection-event
Jul 1, 2026
Merged

turip merged 3 commits into
mainfrom
feat/async-invoice-collection-event

Conversation

@turip

@turip turip commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds an OSS billing command event for customer-scoped invoice collection and wires the billing worker to consume it through the existing invoice collector path.

This keeps OSS collection triggering unchanged while allowing external scanners, such as Cloud Temporal workflows, to publish billing.invoice.collect.v1 events for due customers.

Changes

  • Add billing.CollectCustomerInvoicesEvent with customer resource metadata and validation.
  • Add an async collect handler that maps the event to InvoiceCollector.CollectCustomerInvoice.
  • Register the event in the billing worker and wire the collector into the worker DI graph.
  • Add focused event and handler tests.

Validation

  • make generate
  • go test ./openmeter/billing ./openmeter/billing/worker/collect
  • go test ./openmeter/billing/worker/...
  • go test ./app/common/...
  • go vet ./openmeter/billing ./openmeter/billing/worker/... ./app/common
  • go test ./openmeter/billing/...

Summary by CodeRabbit

  • New Features
    • Added customer invoice collection to the billing worker, including a new invoice.collect event with validation and standardized event metadata.
    • Extended worker setup to include the invoice collector and handle the new event type.
  • Bug Fixes
    • Added safe handling for nil/invalid invoice-collection events and ensured AsOf is forwarded when collecting pending invoice lines.
    • Event handling now skips processing for restricted namespaces.
  • Tests
    • Added unit tests covering event validation/metadata and invoice-collector event handling.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 938d36c4-2bfe-411d-9e18-da88098fdb41

📥 Commits

Reviewing files that changed from the base of the PR and between cbf3cd5 and 91a3c48.

📒 Files selected for processing (1)
  • openmeter/billing/eventscollection.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • openmeter/billing/eventscollection.go

📝 Walkthrough

Walkthrough

This PR adds a customer invoice collection event, wires it through the billing worker, and updates dependency injection to construct and pass the new billing collector. It also forwards AsOf into invoice pending-line collection.

Changes

Billing Invoice Collection Event

Layer / File(s) Summary
Event type, validation, and tests
openmeter/billing/eventscollection.go, openmeter/billing/eventscollection_test.go
Adds CollectCustomerInvoicesEvent with EventName(), EventMetadata(), and Validate(), plus tests covering valid input and missing-field validation errors.
InvoiceCollector event handler
openmeter/billing/worker/collect/asynccollect.go, openmeter/billing/worker/collect/asynccollect_test.go, openmeter/billing/worker/collect/collect.go
Adds HandleCollectCustomerInvoicesEvent, which validates the event and calls CollectCustomerInvoice, tested for nil and invalid event cases, and now passes AsOf into pending-line input.
Worker registration of BillingCollector
openmeter/billing/worker/worker.go
Adds BillingCollector to WorkerOptions (validated non-nil), stores it as invoiceCollector on Worker, and registers a new group event handler that skips lockdown namespaces and delegates to the collector.
Dependency injection updates
app/common/openmeter_billingworker.go, cmd/billing-worker/wire_gen.go
Adds NewBillingCollector to the Wire set, extends NewBillingWorkerOptions with a billingCollector parameter, and updates wire_gen.go to construct and pass the collector.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

Suggested labels: release-note/feature

Suggested reviewers: tothandras, GAlexIHU

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: adding an async invoice collection event and related processing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/async-invoice-collection-event

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 area/billing release-note/misc Miscellaneous changes labels Jul 1, 2026
@greptile-apps

greptile-apps Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds an async customer invoice collection event for the billing worker. The main changes are:

  • New billing.invoice.collect.v1 event type with validation and customer metadata.
  • New async handler that maps collection events into the invoice collector.
  • Billing worker wiring for the invoice collector dependency and event handler.
  • Cutoff forwarding from customer collection into pending-line lookup.
  • Focused tests for event validation and handler behavior.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • The event cutoff now reaches pending-line collection instead of falling back to the current clock.

Important Files Changed

Filename Overview
openmeter/billing/eventscollection.go Adds the customer invoice collection event with required namespace, customer, and cutoff validation.
openmeter/billing/worker/collect/asynccollect.go Adds the async collect-event handler and forwards the validated cutoff into customer invoice collection.
openmeter/billing/worker/collect/collect.go Passes the customer collection cutoff into pending-line collection.
openmeter/billing/worker/worker.go Registers the new collect event handler and requires the invoice collector in worker options.
app/common/openmeter_billingworker.go Wires the invoice collector into billing worker options.
cmd/billing-worker/wire_gen.go Regenerates billing-worker dependency wiring for the invoice collector.

Reviews (3): Last reviewed commit: "Wrap collect event validation errors" | Re-trigger Greptile

@turip
turip marked this pull request as ready for review July 1, 2026 10:38
@turip
turip requested a review from a team as a code owner July 1, 2026 10:38
@turip turip changed the title Add async invoice collection event feat: add async invoice collection event Jul 1, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@openmeter/billing/eventscollection.go`:
- Around line 32-48: The Validate method on CollectCustomerInvoicesEvent
currently returns errors.Join(errs...) directly; update this to wrap the joined
result with models.NewNillableGenericValidationError so the validation error
type is preserved while keeping the combined message intact. Add the pkg/models
import, and make the return in CollectCustomerInvoicesEvent.Validate use
models.NewNillableGenericValidationError(errors.Join(errs...)) after collecting
namespace, customer_id, and as_of validation failures.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 275a3063-8d68-48e1-898c-7a82d318ebe8

📥 Commits

Reviewing files that changed from the base of the PR and between 32ac526 and cb2b131.

📒 Files selected for processing (7)
  • app/common/openmeter_billingworker.go
  • cmd/billing-worker/wire_gen.go
  • openmeter/billing/eventscollection.go
  • openmeter/billing/eventscollection_test.go
  • openmeter/billing/worker/collect/asynccollect.go
  • openmeter/billing/worker/collect/asynccollect_test.go
  • openmeter/billing/worker/worker.go

Comment thread openmeter/billing/eventscollection.go Resolved
@turip
turip enabled auto-merge (squash) July 1, 2026 10:54
@turip
turip merged commit 10cdf05 into main Jul 1, 2026
26 checks passed
@turip
turip deleted the feat/async-invoice-collection-event branch July 1, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants