Skip to content

feat: snapshot unit config onto subscription - OM-399 - #4662

Merged
rolosp merged 5 commits into
mainfrom
feat/om-399-snapshot-unit-config-to-subscription
Jul 9, 2026
Merged

rolosp merged 5 commits into
mainfrom
feat/om-399-snapshot-unit-config-to-subscription

Conversation

@rolosp

@rolosp rolosp commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Snapshots a rate card's unit_config onto subscription items via a new unit_config column and rejects addon rate cards that carry a divergent unit_config rather than silently dropping it

Summary by CodeRabbit

  • New Features
    • Subscription items can now store an optional unit_config, persisted in the database.
  • Bug Fixes
    • Rate-card add-on overlays now enforce unit_config compatibility during add-on apply and reject mismatches with a 400 validation error.
    • Plan phase and addon rate-card compatibility now also checks unit_config.
  • Tests
    • Added tests covering overlay compatibility, unit_config persistence across subscription create+reload, and E2E invoice quantity conversion using unit_config.
    • Removed an outdated E2E test that expected unit_config plan rejection when a feature flag is disabled.

Greptile Summary

This PR snapshots rate-card unit configuration onto subscription items. The main changes are:

  • Added a nullable subscription item unit_config column and generated Ent mappings.
  • Persisted and reloaded unit configuration through subscription item storage.
  • Rejected addon rate cards when both addon and target carry different unit configs.
  • Kept addon restore independent from unit-config validation.
  • Added unit-config billing and persistence test coverage.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
openmeter/subscription/addon/extend.go Adds unit-config compatibility validation on addon apply and keeps restore free of that check.
openmeter/productcatalog/ratecard.go Adds shared rate-card overlay validation for divergent unit configs.
openmeter/subscription/repo/subscriptionitemrepo.go Stores unit config from rate-card metadata when creating subscription items.
openmeter/subscription/repo/mapping.go Restores persisted unit config onto rate-card metadata when loading subscription items.
openmeter/ent/schema/subscription.go Adds the nullable JSON-backed unit_config field to subscription item schema.

Reviews (5): Last reviewed commit: "test: cover planaddon unit config compat..." | Re-trigger Greptile

Context used (3)

  • Context used - CLAUDE.md (source)
  • Context used - AGENTS.md (source)
  • Context used - api/spec/AGENTS.md (source)

@rolosp
rolosp requested a review from a team as a code owner July 8, 2026 08:32
@rolosp rolosp added the release-note/misc Miscellaneous changes label Jul 8, 2026
@rolosp rolosp changed the title feat: snapshot unit config onto subscription feat: snapshot unit config onto subscription - OM-399 Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds unit_config storage for subscription items, validates addon overlay compatibility for rate cards, threads the value through subscription mapping and creation, and covers the behavior with workflow and end-to-end tests.

Changes

Subscription unit_config support

Layer / File(s) Summary
Schema and migration for unit_config column
openmeter/ent/schema/subscription.go, tools/migrate/migrations/20260707142444_om_399_subscription_unit_config.up.sql, ...down.sql
Adds a nullable jsonb unit_config column to subscription_items via Ent schema and matching up/down SQL migrations.
Overlay compatibility validation and error
openmeter/productcatalog/errors.go, openmeter/productcatalog/ratecard.go, openmeter/subscription/addon/extend.go, openmeter/productcatalog/ratecard_test.go, openmeter/subscription/addon/extend_test.go, openmeter/productcatalog/planaddon_test.go
Adds the unit config must match validation issue and ValidateRateCardsHaveCompatibleUnitConfig, wires the validator into addon Apply, documents Restore behavior, and covers matching/mismatching cases in tests.
Repo persistence and mapping
openmeter/subscription/repo/mapping.go, openmeter/subscription/repo/subscriptionitemrepo.go
Maps UnitConfig from DB rows into RateCardMeta and persists UnitConfig when creating subscription items.
Subscription workflow and E2E coverage
openmeter/subscription/workflow/service/subscription_test.go, e2e/billinginvoice_unitconfig_test.go, e2e/config.yaml, e2e/plans_v3_test.go
Adds tests that verify unit_config survives subscription creation/reload and drives converted invoice quantities, plus the E2E toggle and removed flag-disabled plan test.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Possibly related PRs

  • openmeterio/openmeter#4568: Builds on the same RateCardMeta.UnitConfig domain field and its comparison semantics that this PR uses in subscription persistence and overlay checks.
  • openmeterio/openmeter#4604: Related unit_config authoring and validation work in the same product-catalog layer.
  • openmeterio/openmeter#4616: Covers unit_config-driven billing quantity conversion that this PR exercises in the new invoice E2E test.

Suggested labels: release-note/feature, area/billing, area/subscriptions, area/product-catalog

Suggested reviewers: tothandras, turip, mark-vass-konghq

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: snapshotting unit config onto subscriptions, with the OM-399 reference adding useful context.
✨ 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/om-399-snapshot-unit-config-to-subscription

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.

Comment thread openmeter/subscription/addon/extend.go Resolved
@rolosp
rolosp force-pushed the feat/om-399-snapshot-unit-config-to-subscription branch from b3ad93e to 226dd43 Compare July 8, 2026 09:14

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

sry for the comments on comments :D

Comment thread openmeter/productcatalog/errors.go Resolved
Comment thread openmeter/productcatalog/ratecard.go Resolved
Comment thread openmeter/subscription/addon/extend.go Resolved
Comment thread openmeter/productcatalog/ratecard.go Resolved
@rolosp
rolosp force-pushed the feat/om-399-snapshot-unit-config-to-subscription branch from 22a78be to 7d39547 Compare July 8, 2026 16:20
@rolosp
rolosp force-pushed the feat/om-399-snapshot-unit-config-to-subscription branch from f66b961 to 7cc8026 Compare July 9, 2026 10:15
@rolosp
rolosp merged commit 89a54f5 into main Jul 9, 2026
26 checks passed
@rolosp
rolosp deleted the feat/om-399-snapshot-unit-config-to-subscription branch July 9, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/misc Miscellaneous changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants