Repository navigation
fix: use sorted first tier for zero-usage graduated pricing - #5347
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Sorted tier calculation and regression test openmeter/billing/rating/service/rate/tieredgraduated.go, openmeter/billing/rating/service/rate/tieredgraduated_test.go |
The calculator uses the sorted tier list to select the zero-quantity flat-price range. The test checks that reversing the tier order still produces a total of 100. |
Priority:
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix · Severity of issue fixed: Low
Suggested labels: kind/bug, release-note/bug-fix
Suggested reviewers: galexihu, chrisgacsal, mark-vass-konghq
Merge Risk: 
Minimal · up to 22e9f
-
The change includes regression coverage for both ascending and reversed tier orders.
Pre-merge checks: 
4
Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
🧪 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.
Comment @coderabbitai help to get the list of available commands.
turip
left a comment
There was a problem hiding this comment.
Thank you for the contribution! I took the liberty to consolidate the tests, but it's a nice catch!
Problem
GraduatedTiered.TieredPriceCalculatorwalks sorted tiers but selects the zero-usage fallback from the unsorted input.TieredPrice.Validate()accepts reversed tiers, so a mandatory first-bucket flat fee can be missed when usage is zero.The new test uses the same tiers in ascending and reverse storage order. Before the fix, both prices validate, but the reverse-order case returns 0 instead of 100. The fix reads both paths from one sorted view. This matches the first-bucket flat-fee behavior described in #2119; that PR is context for intended behavior, not the source of this defect.
Verification
go test ./openmeter/billing/rating/service/rate/ -run TestTieredOrderIndependence -vexited 1; ascending case passed, reversed case failed (expected 100, actual 0).go test ./openmeter/billing/rating/service/rate/exited 0.Found by reading the two tier access paths, then tested against current source. This is a rating-package reproduction; I did not run an end-to-end invoice flow.
Summary by CodeRabbit


Confidence Score: 5/5
The PR appears safe to merge.Summary
The calculator now uses the same sorted tiers for the normal tier walk and the zero-usage fallback.
Reviews (2) · Last reviewed commit: "test: consolidate graduated tier order r..." · Reviewed by Greptile