Repository navigation
feat(usagebased-charge): ignore minimum commitment on partial runs - #4219
Conversation
📝 WalkthroughWalkthroughAdds an IgnoreMinimumCommitment flag and propagates it through rated-run creation and the rating pipeline; the rating engine gains variadic GenerateDetailedLines options to conditionally suppress minimum-commitment mutators for partial invoice runs. Changes
Sequence Diagram(s)sequenceDiagram
actor Caller
participant RunCreator as Run Creator
participant RatingSvc as Rating Service
participant Pricer as Pricer
Caller->>RunCreator: CreateRatedRun (IgnoreMinimumCommitment? )
RunCreator->>RatingSvc: GetDetailedLinesForUsage(..., IgnoreMinimumCommitment)
RatingSvc->>Pricer: getPricerFor(line, GenerateDetailedLinesOptions)
alt IgnoreMinimumCommitment == true
Pricer->>Pricer: build mutators without MinAmountCommitment
else
Pricer->>Pricer: build mutators including MinAmountCommitment
end
Pricer-->>RatingSvc: priced lines
RatingSvc-->>RunCreator: detailed lines
RunCreator-->>Caller: finalized run
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
openmeter/billing/charges/usagebased/service/rating/service_test.go (1)
157-255: Consider extracting the shared test setup.
TestGetRatingForUsageCanIgnoreMinimumCommitmentduplicates nearly all of the charge/customer/feature-meter construction from the existing test. Pulling that into a small helper (e.g.newGetDetailedLinesForUsageFixture(t)returningGetDetailedLinesForUsageInputplus the stub) would make future rating tests much lighter, and makes the intent of this test — "same inputs, just togglingIgnoreMinimumCommitment: true" — jump out immediately.Not blocking, just a readability win.
As per coding guidelines: "when reviewing the Golang code make readability and maintainability a priority, even potentially suggest restructuring the code to improve them."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/billing/charges/usagebased/service/rating/service_test.go` around lines 157 - 255, The test TestGetRatingForUsageCanIgnoreMinimumCommitment repeats nearly the entire setup for the charge/customer/feature-meter and stubRatingService; extract that shared setup into a helper (e.g. newGetDetailedLinesForUsageFixture(t) that returns a ready GetDetailedLinesForUsageInput and a *stubRatingService or Config) and update TestGetRatingForUsageCanIgnoreMinimumCommitment to call the helper, set IgnoreMinimumCommitment = true on the returned input, create the service with New(Config{...}) using the returned pieces, invoke GetDetailedLinesForUsage, and assert ratingService.lastOpts.IgnoreMinimumCommitment; keep references to TestGetRatingForUsageCanIgnoreMinimumCommitment, GetDetailedLinesForUsageInput, stubRatingService, and New so reviewers can locate and replace the duplicated construction.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@openmeter/billing/rating/service/pricer.go`:
- Line 14: Resolve the build break by updating the call site in
ResolveBillablePeriod to pass the new second parameter to getPricerFor: locate
the call to getPricerFor(in.Line) inside ResolveBillablePeriod in
billableperiod.go and change it to call getPricerFor(in.Line, opts) (or
construct/derive a rating.GenerateDetailedLinesOptions instance appropriate for
the current context) so the signature getPricerFor(line rating.PriceAccessor,
opts rating.GenerateDetailedLinesOptions) is satisfied; ensure the options value
you pass is consistent with how GenerateDetailedLinesOptions is used in
detailedline.go.
---
Nitpick comments:
In `@openmeter/billing/charges/usagebased/service/rating/service_test.go`:
- Around line 157-255: The test TestGetRatingForUsageCanIgnoreMinimumCommitment
repeats nearly the entire setup for the charge/customer/feature-meter and
stubRatingService; extract that shared setup into a helper (e.g.
newGetDetailedLinesForUsageFixture(t) that returns a ready
GetDetailedLinesForUsageInput and a *stubRatingService or Config) and update
TestGetRatingForUsageCanIgnoreMinimumCommitment to call the helper, set
IgnoreMinimumCommitment = true on the returned input, create the service with
New(Config{...}) using the returned pieces, invoke GetDetailedLinesForUsage, and
assert ratingService.lastOpts.IgnoreMinimumCommitment; keep references to
TestGetRatingForUsageCanIgnoreMinimumCommitment, GetDetailedLinesForUsageInput,
stubRatingService, and New so reviewers can locate and replace the duplicated
construction.
🪄 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: f6d9e983-e15a-4aea-b1a5-5e6d83b74dc1
📒 Files selected for processing (8)
openmeter/billing/charges/usagebased/service/creditheninvoice.goopenmeter/billing/charges/usagebased/service/creditheninvoice_test.goopenmeter/billing/charges/usagebased/service/rating/details.goopenmeter/billing/charges/usagebased/service/rating/service_test.goopenmeter/billing/charges/usagebased/service/run/create.goopenmeter/billing/rating/service.goopenmeter/billing/rating/service/detailedline.goopenmeter/billing/rating/service/pricer.go
There was a problem hiding this comment.
🧹 Nitpick comments (1)
openmeter/billing/rating/service/billableperiod.go (1)
17-17: LGTM — empty options here is harmless. 👍Since
ResolveBillablePeriodonly uses the returnedpriceMutatorto call.ResolveBillablePeriod(...)and never runs the post-calculation mutators, whetherMinAmountCommitmentis included or not is irrelevant for this path. Passingrating.GenerateDetailedLinesOptions{}(defaultingIgnoreMinimumCommitment=false) is fine.Tiny optional nit for consistency with
GenerateDetailedLinesindetailedline.go, which builds options via the constructor: you could writerating.NewGenerateDetailedLinesOptions()instead of the zero-value struct literal. Totally a taste call — feel free to ignore.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/billing/rating/service/billableperiod.go` at line 17, Replace the zero-value struct literal passed to getPricerFor with the canonical constructor for consistency: instead of rating.GenerateDetailedLinesOptions{} call rating.NewGenerateDetailedLinesOptions() when invoking getPricerFor(in.Line, ...); update the call site in ResolveBillablePeriod that currently uses getPricerFor(in.Line, rating.GenerateDetailedLinesOptions{}) to use rating.NewGenerateDetailedLinesOptions() so it matches the pattern used in GenerateDetailedLines in detailedline.go.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@openmeter/billing/rating/service/billableperiod.go`:
- Line 17: Replace the zero-value struct literal passed to getPricerFor with the
canonical constructor for consistency: instead of
rating.GenerateDetailedLinesOptions{} call
rating.NewGenerateDetailedLinesOptions() when invoking getPricerFor(in.Line,
...); update the call site in ResolveBillablePeriod that currently uses
getPricerFor(in.Line, rating.GenerateDetailedLinesOptions{}) to use
rating.NewGenerateDetailedLinesOptions() so it matches the pattern used in
GenerateDetailedLines in detailedline.go.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a000b3ee-2cbe-4339-9714-ce3038905c81
📒 Files selected for processing (2)
openmeter/billing/charges/usagebased/service/rating/service_test.goopenmeter/billing/rating/service/billableperiod.go
🚧 Files skipped from review as they are similar to previous changes (1)
- openmeter/billing/charges/usagebased/service/rating/service_test.go
Overview
Minimum commitment is accounted for at the end of the billing period.
Notes for reviewer
Summary by CodeRabbit