Skip to content

chore: simplify featuregate interface - #4454

Merged
borosr merged 1 commit into
mainfrom
chore/simplify-feature-gate-interface
May 29, 2026
Merged

borosr merged 1 commit into
mainfrom
chore/simplify-feature-gate-interface

Conversation

@borosr

@borosr borosr commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Fixes #(issue)

Notes for reviewer

Summary by CodeRabbit

  • Refactor

    • Updated feature gate validation to require explicit non-nil configuration across billing services
    • Enhanced feature gate evaluation API to support namespace-scoped flag evaluation
    • Simplified credits feature flag evaluation logic
  • Tests

    • Expanded validation tests for missing feature gate configurations

Review Change Stack

@borosr
borosr requested review from rolosp and turip May 28, 2026 22:43
@borosr borosr self-assigned this May 28, 2026
@borosr
borosr requested a review from a team as a code owner May 28, 2026 22:43
@borosr borosr added the release-note/misc Miscellaneous changes label May 28, 2026
@coderabbitai

coderabbitai Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Feature gate's boolean evaluation now requires a namespace parameter alongside the flag name. The patch reconciler integrates this updated API while making feature gate mandatory in config validation, and the pattern cascades through service-level configs to ensure the dependency is always present at initialization.

Changes

Feature gate namespace scoping and configuration validation

Layer / File(s) Summary
Feature gate interface contract update
pkg/featuregate/featuregate.go
Gate.EvaluateBool signature changes from (flag string, defaultValue bool) to (namespace, flag string, defaultValue bool), and Noop.EvaluateBool is updated to conform.
Patch reconciler gate integration and validation
openmeter/billing/worker/subscriptionsync/service/reconciler/patch.go, openmeter/billing/worker/subscriptionsync/service/reconciler/patch_test.go
patchCollectionRouterConfig.Validate now requires non-nil featureGate; isCreditsEnabled calls EvaluateBool directly with namespace instead of creating an org-scoped gate; test verifies nil feature gate produces a validation error.
Service-level config validation enforcement
openmeter/billing/worker/subscriptionsync/service/reconciler/reconciler.go, openmeter/billing/worker/subscriptionsync/service/service.go
Reconciler and service Config.Validate methods add nil-checks for FeatureGate and return a "feature gate is required" error if absent.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • openmeterio/openmeter#4445: Directly related changes to the same patchCollectionRouter credit flag plumbing and feature gate validation logic.

Suggested labels

release-note/feature

Suggested reviewers

  • turip
  • tothandras
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

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.
Title check ❓ Inconclusive The title 'chore: simplify featuregate interface' is vague about the actual changes; while it references featuregate, the PR involves significant refactoring across multiple files that goes beyond just simplification. Consider a more specific title that captures the key change, such as 'refactor: add namespace parameter to featuregate EvaluateBool' or 'refactor: require non-nil FeatureGate in validation flows'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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 chore/simplify-feature-gate-interface

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: 0

🧹 Nitpick comments (2)
openmeter/billing/worker/subscriptionsync/service/reconciler/patch.go (1)

132-143: ⚡ Quick win

Arg order looks spot on — and the nil-gate branch is now dead code you can drop.

EvaluateBool(ns, c.creditsFlag, false) matches the new (namespace, flag, defaultValue) shape, nice. One small thing: now that Validate() guarantees featureGate != nil (and the router is only built via newPatchCollectionRouter), the c.featureGate == nil branch can't be reached anymore. Keeping it also quietly contradicts the new "gate is mandatory" invariant, so I'd remove it.

♻️ Drop the unreachable nil branch
 func (c patchCollectionRouter) isCreditsEnabled(ns string) (bool, error) {
 	if !c.creditsEnabled {
 		return false, nil
 	}
-	if c.featureGate == nil {
-		return true, nil
-	}
 	if c.creditsFlag == "" {
 		return true, nil
 	}
 	return c.featureGate.EvaluateBool(ns, c.creditsFlag, false)
 }
🤖 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/billing/worker/subscriptionsync/service/reconciler/patch.go` around
lines 132 - 143, Remove the now-unreachable nil check in
patchCollectionRouter.isCreditsEnabled: since Validate() and
newPatchCollectionRouter ensure featureGate is non-nil, delete the `if
c.featureGate == nil { return true, nil }` branch and let the method fall
through to the existing credits flag check and the final call to
c.featureGate.EvaluateBool(ns, c.creditsFlag, false); keep the early return for
c.creditsEnabled and the c.creditsFlag == "" case intact.
openmeter/billing/worker/subscriptionsync/service/reconciler/reconciler.go (1)

39-57: ⚡ Quick win

Good to require the gate here — worth switching this to the aggregate-error pattern while you're in it.

This Validate() returns on the first missing field. Per the repo convention, validation methods should collect everything and join. (ApplyInput.Validate in this same file already does this.) You'll need to add the models import (errors is already there).

♻️ Aggregate validation errors
 func (c Config) Validate() error {
-	if c.BillingService == nil {
-		return fmt.Errorf("billing service is required")
-	}
-
-	if c.Logger == nil {
-		return fmt.Errorf("logger is required")
-	}
-
-	if c.EnableCreditThenInvoice && c.ChargesService == nil {
-		return fmt.Errorf("charges service is required when credit then invoice is enabled")
-	}
-
-	if c.FeatureGate == nil {
-		return fmt.Errorf("feature gate is required")
-	}
-
-	return nil
+	var errs []error
+	if c.BillingService == nil {
+		errs = append(errs, fmt.Errorf("billing service is required"))
+	}
+	if c.Logger == nil {
+		errs = append(errs, fmt.Errorf("logger is required"))
+	}
+	if c.EnableCreditThenInvoice && c.ChargesService == nil {
+		errs = append(errs, fmt.Errorf("charges service is required when credit then invoice is enabled"))
+	}
+	if c.FeatureGate == nil {
+		errs = append(errs, fmt.Errorf("feature gate is required"))
+	}
+	return models.NewNillableGenericValidationError(errors.Join(errs...))
 }

As per coding guidelines: "For Validate() error methods, collect all validation issues into var errs []error and return models.NewNillableGenericValidationError(errors.Join(errs...)) instead of returning on the first invalid field".

🤖 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/billing/worker/subscriptionsync/service/reconciler/reconciler.go`
around lines 39 - 57, Update Config.Validate to accumulate all missing-field
errors into var errs []error instead of returning on first error: check
c.BillingService, c.Logger, c.EnableCreditThenInvoice && c.ChargesService, and
c.FeatureGate, append a descriptive fmt.Errorf for each missing field to errs,
then return models.NewNillableGenericValidationError(errors.Join(errs...))
(keeping the existing errors import and adding the models import). Ensure the
function name Config.Validate and the referenced fields BillingService, Logger,
EnableCreditThenInvoice, ChargesService, and FeatureGate are used so callers
remain unchanged.
🤖 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.

Nitpick comments:
In `@openmeter/billing/worker/subscriptionsync/service/reconciler/patch.go`:
- Around line 132-143: Remove the now-unreachable nil check in
patchCollectionRouter.isCreditsEnabled: since Validate() and
newPatchCollectionRouter ensure featureGate is non-nil, delete the `if
c.featureGate == nil { return true, nil }` branch and let the method fall
through to the existing credits flag check and the final call to
c.featureGate.EvaluateBool(ns, c.creditsFlag, false); keep the early return for
c.creditsEnabled and the c.creditsFlag == "" case intact.

In `@openmeter/billing/worker/subscriptionsync/service/reconciler/reconciler.go`:
- Around line 39-57: Update Config.Validate to accumulate all missing-field
errors into var errs []error instead of returning on first error: check
c.BillingService, c.Logger, c.EnableCreditThenInvoice && c.ChargesService, and
c.FeatureGate, append a descriptive fmt.Errorf for each missing field to errs,
then return models.NewNillableGenericValidationError(errors.Join(errs...))
(keeping the existing errors import and adding the models import). Ensure the
function name Config.Validate and the referenced fields BillingService, Logger,
EnableCreditThenInvoice, ChargesService, and FeatureGate are used so callers
remain unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 117dc5df-2aa1-4742-86da-a2771fa24a56

📥 Commits

Reviewing files that changed from the base of the PR and between 0ade1b7 and 16ec500.

📒 Files selected for processing (5)
  • openmeter/billing/worker/subscriptionsync/service/reconciler/patch.go
  • openmeter/billing/worker/subscriptionsync/service/reconciler/patch_test.go
  • openmeter/billing/worker/subscriptionsync/service/reconciler/reconciler.go
  • openmeter/billing/worker/subscriptionsync/service/service.go
  • pkg/featuregate/featuregate.go

@chrisgacsal chrisgacsal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

@borosr
borosr merged commit 819c22b into main May 29, 2026
35 of 37 checks passed
@borosr
borosr deleted the chore/simplify-feature-gate-interface branch May 29, 2026 07:19

This branch was previously deployed

1 inactive deployment
dev — 16ec500e Deployed May 28, 2026 by borosr via Migration Checks #14709
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.

4 participants