Skip to content

fix: validating metered feature for ubp ratecard#4502

Merged
chrisgacsal merged 1 commit into
mainfrom
fix/feature-meter
Jun 11, 2026
Merged

fix: validating metered feature for ubp ratecard#4502
chrisgacsal merged 1 commit into
mainfrom
fix/feature-meter

Conversation

@chrisgacsal

@chrisgacsal chrisgacsal commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Overview

Ensure that ratecards with usage-based pricing have metered feature.

Summary by CodeRabbit

  • Bug Fixes

    • Enforcement: usage-based rate cards that reference a feature now require an associated meter (returns a validation error).
    • Improved feature resolution with nil-safety and clearer validation errors when features are missing.
    • Fixed plan update error message text.
  • Refactor

    • Internal restructuring of rate card and feature handling for more consistent behavior and safer eager-loading/backfilling of feature metadata.

@chrisgacsal chrisgacsal self-assigned this Jun 10, 2026
@chrisgacsal
chrisgacsal requested a review from a team as a code owner June 10, 2026 12:49
@chrisgacsal chrisgacsal added the release-note/bug-fix Release note: Bug Fixes label Jun 10, 2026
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5e9b3250-0da4-4067-be6b-f74a2d75426d

📥 Commits

Reviewing files that changed from the base of the PR and between 3794b49 and c77ac56.

📒 Files selected for processing (13)
  • openmeter/productcatalog/addon/adapter/addon.go
  • openmeter/productcatalog/addon/adapter/mapping.go
  • openmeter/productcatalog/errors.go
  • openmeter/productcatalog/featureresolver/ratecard.go
  • openmeter/productcatalog/featureresolver/resolver_test.go
  • openmeter/productcatalog/plan/adapter/mapping.go
  • openmeter/productcatalog/plan/adapter/plan.go
  • openmeter/productcatalog/plan/repository.go
  • openmeter/productcatalog/plan/service/plan.go
  • openmeter/productcatalog/ratecard.go
  • openmeter/subscription/addon/diff/apply_test.go
  • openmeter/subscription/addon/extend_test.go
  • openmeter/subscription/workflow/service/addon_test.go
💤 Files with no reviewable changes (1)
  • openmeter/productcatalog/plan/repository.go
✅ Files skipped from review due to trivial changes (2)
  • openmeter/productcatalog/plan/adapter/plan.go
  • openmeter/productcatalog/plan/service/plan.go
🚧 Files skipped from review as they are similar to previous changes (9)
  • openmeter/productcatalog/featureresolver/ratecard.go
  • openmeter/productcatalog/addon/adapter/mapping.go
  • openmeter/subscription/workflow/service/addon_test.go
  • openmeter/productcatalog/errors.go
  • openmeter/subscription/addon/diff/apply_test.go
  • openmeter/productcatalog/plan/adapter/mapping.go
  • openmeter/productcatalog/ratecard.go
  • openmeter/productcatalog/featureresolver/resolver_test.go
  • openmeter/productcatalog/addon/adapter/addon.go

📝 Walkthrough

Walkthrough

Refactors rate-card feature handling into a RateCardFeature interface; updates adapters to eager-load and backfill features when referenced; enforces that usage-based rate cards with a feature have a MeterID; updates related tests and adds a Plan Repository interface plus minor cleanups.

Changes

RateCard Feature Refactoring with Meter Validation

Layer / File(s) Summary
RateCard interface refactoring
openmeter/productcatalog/ratecard.go
RateCardFeature interface introduced and embedded into RateCard; feature methods moved to the new interface.
Feature validation error definitions
openmeter/productcatalog/errors.go
New validation error ErrRateCardUsageBasedPriceWithFeatureAndNoMeter added (targets featureKey, HTTP 400).
Feature eager-loading and mapping in adapters
openmeter/productcatalog/addon/adapter/addon.go, openmeter/productcatalog/addon/adapter/mapping.go, openmeter/productcatalog/plan/adapter/mapping.go
Addon eager-load split into helpers; addon/plan mapping now loads feature when FeatureID or FeatureKey is present and sets both via SetFeature().
Feature resolver nil-guard and validation
openmeter/productcatalog/featureresolver/ratecard.go, openmeter/productcatalog/ratecard.go
Resolver skips setting feature when resolved *feature.Feature is nil and appends a feature-not-found error; validator requires MeterID for usage-based (non-flat) rate cards and appends the new error when missing.
Feature resolver test updates
openmeter/productcatalog/featureresolver/resolver_test.go
Batch/Resolve tests switched to map expected values to *feature.Feature pointers and assert nil vs populated results and ID/Key equality.
Subscription addon test compatibility
openmeter/subscription/addon/diff/apply_test.go, openmeter/subscription/addon/extend_test.go, openmeter/subscription/workflow/service/addon_test.go
Tests updated to use typed rate cards, clear features with SetFeature(nil, key), and adjust compile-time conformance checks.
Plan repository interface and cleanup
openmeter/productcatalog/plan/repository.go, openmeter/productcatalog/plan/service/plan.go, openmeter/productcatalog/plan/adapter/plan.go
Added Repository interface for plans, removed TODO, fixed typo in UpdatePlan error message, and reformatted plan eager-load predicate.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

area/product-catalog, area/subscriptions

Suggested reviewers

  • gergely-kurucz-konghq
  • turip
  • borbelyr-kong
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% 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 accurately describes the main change: adding validation to ensure metered features are used with usage-based pricing ratecards.
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/feature-meter

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/productcatalog/addon/adapter/addon.go (1)

555-561: ⚡ Quick win

Inline these tiny eager-load wrappers.

On Line 555 and Line 559, these helpers only wrap one query call each, so they add indirection without adding domain meaning. Inlining both calls back into AddonEagerLoadRateCardsFn keeps this path easier to scan.

As per coding guidelines, "**/*.go: In Go code, do not extract helper functions only to hide a couple of simple operations or short guard checks; prefer inline code when the helper would only wrap 2-4 lines and its name does not add meaningful domain intent."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openmeter/productcatalog/addon/adapter/addon.go` around lines 555 - 561,
Remove the tiny wrappers rateCardEagerLoadFeaturesFn and
rateCardEagerLoadTaxCodesFn and inline their single calls into
AddonEagerLoadRateCardsFn: replace usages of those helper vars with direct
q.WithFeatures() and q.WithTaxCode() inside the AddonEagerLoadRateCardsFn
implementation, and delete the now-unused variables to eliminate unnecessary
indirection.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@openmeter/productcatalog/featureresolver/resolver_test.go`:
- Around line 166-167: The test is dereferencing potentially nil values (`f` and
entries in `resolved`) after non-fatal asserts which can cause panics; add
explicit nil guards using require.NotNil before any field access. Concretely,
before calls that use lo.FromPtr(f.MeterID) / lo.FromPtr(f.MeterSlug) insert
require.NotNil(t, f) (or require.NotNil(t, resolved[k]) where applicable), then
keep the assert.Equalf checks; apply the same change to the other block that
inspects resolved[k] (the assertions using lo.FromPtr on MeterID/MeterSlug).

---

Nitpick comments:
In `@openmeter/productcatalog/addon/adapter/addon.go`:
- Around line 555-561: Remove the tiny wrappers rateCardEagerLoadFeaturesFn and
rateCardEagerLoadTaxCodesFn and inline their single calls into
AddonEagerLoadRateCardsFn: replace usages of those helper vars with direct
q.WithFeatures() and q.WithTaxCode() inside the AddonEagerLoadRateCardsFn
implementation, and delete the now-unused variables to eliminate unnecessary
indirection.
🪄 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: cf5cbaac-5e63-4195-861b-335c5984e29c

📥 Commits

Reviewing files that changed from the base of the PR and between dc07897 and d52c1e0.

📒 Files selected for processing (13)
  • openmeter/productcatalog/addon/adapter/addon.go
  • openmeter/productcatalog/addon/adapter/mapping.go
  • openmeter/productcatalog/errors.go
  • openmeter/productcatalog/featureresolver/ratecard.go
  • openmeter/productcatalog/featureresolver/resolver_test.go
  • openmeter/productcatalog/plan/adapter/mapping.go
  • openmeter/productcatalog/plan/adapter/plan.go
  • openmeter/productcatalog/plan/repository.go
  • openmeter/productcatalog/plan/service/plan.go
  • openmeter/productcatalog/ratecard.go
  • openmeter/subscription/addon/diff/apply_test.go
  • openmeter/subscription/addon/extend_test.go
  • openmeter/subscription/workflow/service/addon_test.go
💤 Files with no reviewable changes (1)
  • openmeter/productcatalog/plan/repository.go

Comment thread openmeter/productcatalog/featureresolver/resolver_test.go Outdated
@chrisgacsal
chrisgacsal merged commit 9b08c32 into main Jun 11, 2026
26 of 27 checks passed
@chrisgacsal
chrisgacsal deleted the fix/feature-meter branch June 11, 2026 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants