Repository navigation
refactor(billing): separate ordinary and legacy rating - #5326
Conversation
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
🔇 Additional comments: 25
openmeter/billing/charges/flatfee/service/lineengine_test.go: 1
228-230: LGTM!openmeter/billing/charges/flatfee/service/realizations/rating.go: 1
21-21: LGTM!openmeter/billing/charges/usagebased/rating.go: 1
19-20: LGTM!openmeter/billing/charges/usagebased/service/lineengine_test.go: 1
601-603: LGTM!openmeter/billing/charges/usagebased/service/rating/delta/engine.go: 1
79-79: LGTM!openmeter/billing/charges/usagebased/service/rating/delta/engine_test.go: 1
404-407: LGTM!openmeter/billing/charges/usagebased/service/rating/periodpreserving/engine.go: 1
218-218: LGTM!openmeter/billing/charges/usagebased/service/rating/service_test.go: 1
584-584: LGTM!Also applies to: 606-609
openmeter/billing/charges/usagebased/service/rating/totals.go: 1
69-69: LGTM!openmeter/billing/lineengine/engine_test.go: 1
515-518: LGTM!openmeter/billing/lineengine/rating_test.go: 2
21-21: LGTM!Also applies to: 124-124, 286-292, 487-487, 517-517, 550-550, 587-591
339-477: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.Nice coverage. One small readability tweak is worth a look.
The table pins good contracts: prior billing, deleted history, identity survival, and input immutability. The expected values (
40,60,80,100,10,20) are bare numbers, though. A short comment per case would show how each one is derived. For example, the minimum-spend case is 20 usage plus a 40 prior charge, which gives a 60 total against the 100 minimum.Also,
expectedCharges,ordinaryCharges, and the totals mix several scenarios in one table. This is fine today. If more cases arrive, consider splitting the ordinary and header-only checks into their own subtests.Based on learnings, expected values in table-driven tests should be computed or explained, not bare magic numbers.
Source: Learnings
openmeter/billing/rating/line.go: 1
44-57: LGTM!openmeter/billing/rating/service.go: 1
19-19: LGTM!openmeter/billing/rating/service/standardline.go: 1
1-33: LGTM!openmeter/billing/rating/clampedstandardline.go: 1
14-98: LGTM!openmeter/billing/rating/service/detailedline.go: 1
18-24: LGTM!Also applies to: 47-117
openmeter/billing/rating/service/detailedline_test.go: 1
18-266: LGTM!openmeter/billing/rating/clampedstandardline_test.go: 1
13-164: LGTM!openmeter/billing/rating/service/mutator/forbidunitconfig_test.go: 1
20-20: LGTM!openmeter/billing/rating/service/mutator/unitconfig_test.go: 1
51-51: LGTM!Also applies to: 131-131, 151-151, 170-170
openmeter/billing/README.md: 1
131-138: LGTM!openmeter/billing/lineengine/rating.go: 1
92-92: LGTM!openmeter/billing/rating/service/pricer.go: 1
29-33: LGTM!openmeter/billing/rating/service/testutil/ubptest.go: 1
60-74: LGTM!Also applies to: 117-128, 182-182, 197-208
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository: openmeterio/openmeter/.coderabbit.yaml
- Review profile: CHILL
- Plan: Advanced
- Run ID:
c4226730-12c1-48ed-bfb1-504ec8e60593
📒 Files selected for processing: 32
openmeter/billing/README.mdopenmeter/billing/charges/flatfee/rating.goopenmeter/billing/charges/flatfee/service/lineengine_test.goopenmeter/billing/charges/flatfee/service/realizations/rating.goopenmeter/billing/charges/usagebased/detailedline.goopenmeter/billing/charges/usagebased/rating.goopenmeter/billing/charges/usagebased/service/lineengine_test.goopenmeter/billing/charges/usagebased/service/rating/delta/engine.goopenmeter/billing/charges/usagebased/service/rating/delta/engine_test.goopenmeter/billing/charges/usagebased/service/rating/periodpreserving/engine.goopenmeter/billing/charges/usagebased/service/rating/service_test.goopenmeter/billing/charges/usagebased/service/rating/totals.goopenmeter/billing/lineengine/engine_test.goopenmeter/billing/lineengine/rating.goopenmeter/billing/lineengine/rating_test.goopenmeter/billing/rating/clampedstandardline.goopenmeter/billing/rating/clampedstandardline_test.goopenmeter/billing/rating/detailedline.goopenmeter/billing/rating/line.goopenmeter/billing/rating/service.goopenmeter/billing/rating/service/detailedline.goopenmeter/billing/rating/service/detailedline_test.goopenmeter/billing/rating/service/mutator/credits.goopenmeter/billing/rating/service/mutator/credits_test.goopenmeter/billing/rating/service/mutator/forbidunitconfig_test.goopenmeter/billing/rating/service/mutator/unitconfig_test.goopenmeter/billing/rating/service/options_test.goopenmeter/billing/rating/service/pricer.goopenmeter/billing/rating/service/rate/types.goopenmeter/billing/rating/service/standardline.goopenmeter/billing/rating/service/testutil/ubptest.goopenmeter/billing/stdinvoiceline.go
💤 Files with no reviewable changes: 7
- openmeter/billing/rating/service/mutator/credits_test.go
- openmeter/billing/charges/usagebased/detailedline.go
- openmeter/billing/rating/service/options_test.go
- openmeter/billing/rating/service/mutator/credits.go
- openmeter/billing/stdinvoiceline.go
- openmeter/billing/rating/detailedline.go
- openmeter/billing/charges/flatfee/rating.go
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
Overview
Ordinary charge rating currently has to implement legacy progressive-billing accessors. Split the contract into
StandardLineAccessor/GenerateDetailedLinesfor charges andLegacyProgressivelyBillableLineAccessor/GenerateLegacyProgressiveBilledLinesfor legacy invoice lines, while retaining one pricing pipeline.Remove the unused credit mutator and credit inputs/outputs from rating. Charge engines continue allocating credits and applying them to detailed lines after rating.
Related to #4750; this implements the rating-contract separation only. Hierarchy representation, persistence, and loading remain unchanged.
Notes for reviewer
Validation:
make test-go-sdkpassed.make lint-go-fastscoped to the affected packages passed with zero issues.make test GO_TEST_PACKAGE_PARALLELISM=8reached the default 10-minute timeout intools/migrate; CI will verify the full suite. The notification integration test passed after starting its local Svix dependency.The billing domain README documents the revised rating and credit-application boundary.
Summary by CodeRabbit


Confidence Score: 5/5
The PR appears safe to merge; no actionable issues were found.Summary
Separates ordinary charge rating from legacy progressive rating while keeping one pricing pipeline.
Intentional change:
turipexplicitly describes removing rating-owned credit inputs, outputs, and the unused mutator. Hierarchy storage and loading remain out of scope.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR C[Charge snapshots] --> O[GenerateDetailedLines] O --> A[Adapter supplies zero history] L[Legacy invoice snapshots] --> G[GenerateLegacyProgressiveBilledLines] A --> P[Shared pricing pipeline] G --> P P --> R[Details and totals before credits] R --> E[Charge services apply credits] R --> I[Legacy engine merges rated details]Reviews (1) · Last reviewed commit: "test(billing): adapt rating sanity fixtu..." · Reviewed by Greptile