Repository navigation
feat: add credit enabled feature gate for v1 product catalog endpoints - #4459
Conversation
📝 WalkthroughWalkthroughPlan and subscription HTTP handlers now support namespace-aware credits feature gating. Each handler receives a feature gate, implements ChangesFeature Gate Integration for Plan and Subscription Credits
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 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
🤖 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/plan/httpdriver/plan.go`:
- Around line 124-131: In CreatePlan, don't call h.isCreditsEnabled(ns)
unconditionally; instead, first check if req.SettlementMode ==
productcatalog.CreditOnlySettlementMode and only then call
h.isCreditsEnabled(ns) and propagate any error; if credits are not enabled
return the models.NewGenericValidationError as before. Apply the same
short-circuit pattern to UpdatePlan, CreateSubscription, and ChangeSubscription
so feature-gate evaluation (h.isCreditsEnabled) only runs when settlement mode
equals productcatalog.CreditOnlySettlementMode.
🪄 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: 9c4e88f7-b447-46b0-afea-d498fd555427
📒 Files selected for processing (8)
openmeter/productcatalog/plan/httpdriver/driver.goopenmeter/productcatalog/plan/httpdriver/featuregate.goopenmeter/productcatalog/plan/httpdriver/plan.goopenmeter/productcatalog/subscription/http/change.goopenmeter/productcatalog/subscription/http/create.goopenmeter/productcatalog/subscription/http/featuregate.goopenmeter/productcatalog/subscription/http/handler.goopenmeter/server/router/router.go
| creditEnabled, err := h.isCreditsEnabled(ns) | ||
| if err != nil { | ||
| return CreatePlanRequest{}, fmt.Errorf("failed to create plan request: %w", err) | ||
| } | ||
|
|
||
| if !creditEnabled && req.SettlementMode == productcatalog.CreditOnlySettlementMode { | ||
| return CreatePlanRequest{}, models.NewGenericValidationError(fmt.Errorf("credits are not enabled on this deployment of OpenMeter")) | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Find the Gate interface / EvaluateBool definition to confirm it returns an error
ast-grep --pattern 'EvaluateBool($$$) (bool, error)'
rg -nP --type=go -C3 '\bEvaluateBool\b' -g '!**/*_test.go'Repository: openmeterio/openmeter
Length of output: 2288
Short-circuit isCreditsEnabled so gate errors don’t block all plan requests.
EvaluateBool returns (bool, error) (pkg/featuregate/featuregate.go), so the unconditional h.isCreditsEnabled(ns) call in openmeter/productcatalog/plan/httpdriver/plan.go (CreatePlan, lines 124–131) can fail the request even when req.SettlementMode isn’t CreditOnlySettlementMode. Gate the feature-eval behind the settlement-mode check to keep the blast radius tight.
🛡️ Proposed short-circuit
- creditEnabled, err := h.isCreditsEnabled(ns)
- if err != nil {
- return CreatePlanRequest{}, fmt.Errorf("failed to create plan request: %w", err)
- }
-
- if !creditEnabled && req.SettlementMode == productcatalog.CreditOnlySettlementMode {
- return CreatePlanRequest{}, models.NewGenericValidationError(fmt.Errorf("credits are not enabled on this deployment of OpenMeter"))
- }
+ if req.SettlementMode == productcatalog.CreditOnlySettlementMode {
+ creditEnabled, err := h.isCreditsEnabled(ns)
+ if err != nil {
+ return CreatePlanRequest{}, fmt.Errorf("failed to create plan request: %w", err)
+ }
+
+ if !creditEnabled {
+ return CreatePlanRequest{}, models.NewGenericValidationError(fmt.Errorf("credits are not enabled on this deployment of OpenMeter"))
+ }
+ }Also check UpdatePlan, CreateSubscription, and ChangeSubscription for the same unconditional pattern and apply the same guard if present.
🤖 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/plan/httpdriver/plan.go` around lines 124 - 131, In
CreatePlan, don't call h.isCreditsEnabled(ns) unconditionally; instead, first
check if req.SettlementMode == productcatalog.CreditOnlySettlementMode and only
then call h.isCreditsEnabled(ns) and propagate any error; if credits are not
enabled return the models.NewGenericValidationError as before. Apply the same
short-circuit pattern to UpdatePlan, CreateSubscription, and ChangeSubscription
so feature-gate evaluation (h.isCreditsEnabled) only runs when settlement mode
equals productcatalog.CreditOnlySettlementMode.
Summary by CodeRabbit