Skip to content

feat(usagebased-charge): ignore minimum commitment on partial runs - #4219

Merged
turip merged 2 commits into
mainfrom
fix/ignore-minimum-commitment-for-interim-lines
Apr 24, 2026
Merged

turip merged 2 commits into
mainfrom
fix/ignore-minimum-commitment-for-interim-lines

Conversation

@turip

@turip turip commented Apr 24, 2026 •

Copy link
Copy Markdown
Member

Overview

Minimum commitment is accounted for at the end of the billing period.

Notes for reviewer

Summary by CodeRabbit

  • New Features
    • Option to ignore minimum commitment charges for partial invoice runs while preserving them for final realizations.
  • Behavioral Changes
    • Minimum-commitment handling can be toggled through the rating flow so downstream pricing omits minimums when requested.
  • Tests
    • Added unit tests validating ignoring vs. preserving minimum commitment behavior and its propagation through rating.

@turip turip added the release-note/bug-fix Release note: Bug Fixes label Apr 24, 2026
@turip
turip requested a review from a team as a code owner April 24, 2026 07:32
@coderabbitai

coderabbitai Bot commented Apr 24, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Minimum commitment decision
openmeter/billing/charges/usagebased/service/creditheninvoice.go, openmeter/billing/charges/usagebased/service/creditheninvoice_test.go
Adds unexported helper to detect partial vs final realization runs and tests that partial runs suppress minimum-commitment behavior.
Run creation & usage input
openmeter/billing/charges/usagebased/service/run/create.go, openmeter/billing/charges/usagebased/service/rating/details.go
Adds IgnoreMinimumCommitment bool to CreateRatedRunInput and GetDetailedLinesForUsageInput, forwarding the flag into the rating call.
Rating API options
openmeter/billing/rating/service.go, openmeter/billing/rating/service/detailedline.go
Extends GenerateDetailedLines to accept variadic GenerateDetailedLinesOption and adds GenerateDetailedLinesOptions, constructor, and WithMinimumCommitmentIgnored() option.
Pricer behavior & tests
openmeter/billing/rating/service/pricer.go, openmeter/billing/rating/service/service_test.go
Makes pricer construction consume GenerateDetailedLinesOptions and conditionally exclude the minimum-commitment mutator; tests verify propagation and default behavior.
Billable period pricer resolution
openmeter/billing/rating/service/billableperiod.go
Updates pricer resolution to pass explicit empty options into pricer factory to align with the new options-parameterized pricer API.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

release-note/misc

Suggested reviewers

  • tothandras
  • GAlexIHU
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding logic to ignore minimum commitment charges on partial invoice runs, which is the primary feature introduced across the changeset.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 fix/ignore-minimum-commitment-for-interim-lines

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 and usage tips.

@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

🧹 Nitpick comments (1)
openmeter/billing/charges/usagebased/service/rating/service_test.go (1)

157-255: Consider extracting the shared test setup.

TestGetRatingForUsageCanIgnoreMinimumCommitment duplicates nearly all of the charge/customer/feature-meter construction from the existing test. Pulling that into a small helper (e.g. newGetDetailedLinesForUsageFixture(t) returning GetDetailedLinesForUsageInput plus the stub) would make future rating tests much lighter, and makes the intent of this test — "same inputs, just toggling IgnoreMinimumCommitment: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0880fe6 and 9fdcb45.

📒 Files selected for processing (8)
  • openmeter/billing/charges/usagebased/service/creditheninvoice.go
  • openmeter/billing/charges/usagebased/service/creditheninvoice_test.go
  • openmeter/billing/charges/usagebased/service/rating/details.go
  • openmeter/billing/charges/usagebased/service/rating/service_test.go
  • openmeter/billing/charges/usagebased/service/run/create.go
  • openmeter/billing/rating/service.go
  • openmeter/billing/rating/service/detailedline.go
  • openmeter/billing/rating/service/pricer.go

@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.

🧹 Nitpick comments (1)
openmeter/billing/rating/service/billableperiod.go (1)

17-17: LGTM — empty options here is harmless. 👍

Since ResolveBillablePeriod only uses the returned priceMutator to call .ResolveBillablePeriod(...) and never runs the post-calculation mutators, whether MinAmountCommitment is included or not is irrelevant for this path. Passing rating.GenerateDetailedLinesOptions{} (defaulting IgnoreMinimumCommitment=false) is fine.

Tiny optional nit for consistency with GenerateDetailedLines in detailedline.go, which builds options via the constructor: you could write rating.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

📥 Commits

Reviewing files that changed from the base of the PR and between 9fdcb45 and ddd6632.

📒 Files selected for processing (2)
  • openmeter/billing/charges/usagebased/service/rating/service_test.go
  • openmeter/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

@turip
turip merged commit 28edac1 into main Apr 24, 2026
27 of 28 checks passed
@turip
turip deleted the fix/ignore-minimum-commitment-for-interim-lines branch April 24, 2026 11:04
This was referenced Apr 24, 2026

This branch was previously deployed

1 inactive deployment
dev — ddd66324 Deployed Apr 24, 2026 by turip via Migration Checks #13816
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