Skip to content

feat: add credit enabled feature gate for v1 product catalog endpoints - #4459

Merged
rolosp merged 1 commit into
mainfrom
feat/add-credit-ff-check-to-product-catalog
Jun 1, 2026
Merged

rolosp merged 1 commit into
mainfrom
feat/add-credit-ff-check-to-product-catalog

Conversation

@rolosp

@rolosp rolosp commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Integrated feature gates to enable flexible, namespace-level control of credits functionality across deployments.
    • Plans and subscriptions now validate credit-only settlement modes against feature-gated credits settings.
    • Enhanced deployment flexibility with per-namespace credits enablement instead of global configuration.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Plan and subscription HTTP handlers now support namespace-aware credits feature gating. Each handler receives a feature gate, implements isCreditsEnabled(ns) to evaluate optional feature flags per namespace, and uses it to validate settlement-mode requests. The router wires the feature gate through both handlers.

Changes

Feature Gate Integration for Plan and Subscription Credits

Layer / File(s) Summary
Plan HTTP driver feature gate support
openmeter/productcatalog/plan/httpdriver/driver.go, openmeter/productcatalog/plan/httpdriver/featuregate.go, openmeter/productcatalog/plan/httpdriver/plan.go
Plan handler struct gains a featureGate field, New() constructor accepts and stores the feature gate, and isCreditsEnabled(ns) helper checks global enablement, then feature-gate/flag presence, then evaluates the flag for the namespace. CreatePlan and UpdatePlan replace direct h.credits.Enabled checks with calls to isCreditsEnabled(ns).
Subscription HTTP handler feature gate support
openmeter/productcatalog/subscription/http/handler.go, openmeter/productcatalog/subscription/http/featuregate.go, openmeter/productcatalog/subscription/http/create.go, openmeter/productcatalog/subscription/http/change.go
Subscription HandlerConfig adds FeatureGate field, and isCreditsEnabled(ns) helper follows the same evaluation pattern. CreateSubscription and ChangeSubscription call isCreditsEnabled(ns) with error handling instead of checking h.Credits.Enabled directly.
Router wiring
openmeter/server/router/router.go
Plan and subscription handler initialization now includes config.FeatureGate to connect the feature gate from configuration.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • openmeterio/openmeter#4454: New isCreditsEnabled logic relies on the updated featuregate.Gate.EvaluateBool(ns, flag, ...) API introduced here.
  • openmeterio/openmeter#4445: Both PRs update credits enablement logic to be driven by feature-gate evaluation via isCreditsEnabled(ns)-style checks.
  • openmeterio/openmeter#4044: Both PRs update plan/subscription HTTP handlers to reject CreditOnlySettlementMode when credits are disabled.

Suggested labels

release-note/feature, area/billing

Suggested reviewers

  • turip
  • chrisgacsal
  • GAlexIHU
🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding a feature gate to control credit enablement across v1 product catalog endpoints, which matches the changeset's scope and intent.
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 feat/add-credit-ff-check-to-product-catalog

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.

@rolosp
rolosp marked this pull request as ready for review May 29, 2026 15:06
@rolosp
rolosp requested a review from a team as a code owner May 29, 2026 15:06

@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

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 819c22b and 580ebc2.

📒 Files selected for processing (8)
  • openmeter/productcatalog/plan/httpdriver/driver.go
  • openmeter/productcatalog/plan/httpdriver/featuregate.go
  • openmeter/productcatalog/plan/httpdriver/plan.go
  • openmeter/productcatalog/subscription/http/change.go
  • openmeter/productcatalog/subscription/http/create.go
  • openmeter/productcatalog/subscription/http/featuregate.go
  • openmeter/productcatalog/subscription/http/handler.go
  • openmeter/server/router/router.go

Comment on lines +124 to 131
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"))
}

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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

@turip
turip self-requested a review May 29, 2026 15:16
@rolosp
rolosp merged commit dd71baf into main Jun 1, 2026
31 of 32 checks passed
@rolosp
rolosp deleted the feat/add-credit-ff-check-to-product-catalog branch June 1, 2026 08:09
@coderabbitai coderabbitai Bot mentioned this pull request Jun 1, 2026

This branch was previously deployed

1 inactive deployment
dev — 580ebc26 Deployed May 29, 2026 by rolosp via Migration Checks #14718
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants