Repository navigation
chore: simplify featuregate interface - #4454
Conversation
📝 WalkthroughWalkthroughFeature 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. ChangesFeature gate namespace scoping and configuration validation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 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: 0
🧹 Nitpick comments (2)
openmeter/billing/worker/subscriptionsync/service/reconciler/patch.go (1)
132-143: ⚡ Quick winArg 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 thatValidate()guaranteesfeatureGate != nil(and the router is only built vianewPatchCollectionRouter), thec.featureGate == nilbranch 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 winGood 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.Validatein this same file already does this.) You'll need to add themodelsimport (errorsis 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() errormethods, collect all validation issues intovar errs []errorand returnmodels.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
📒 Files selected for processing (5)
openmeter/billing/worker/subscriptionsync/service/reconciler/patch.goopenmeter/billing/worker/subscriptionsync/service/reconciler/patch_test.goopenmeter/billing/worker/subscriptionsync/service/reconciler/reconciler.goopenmeter/billing/worker/subscriptionsync/service/service.gopkg/featuregate/featuregate.go
Overview
Fixes #(issue)
Notes for reviewer
Summary by CodeRabbit
Refactor
Tests