Repository navigation
chore: noop init - #4070
chore: noop init#4070
Conversation
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughAdds credits-gating across ledger and customer-balance components: when Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant Config as CreditsConfiguration
participant Wire as Wiring
participant RW as LedgerReadWriter
participant Querier as LedgerQuerier
participant Provisioner as CustomerLedgerProvisioner
participant Real as Real Ledger Stack
participant Noop as No-op Ledger Stack
participant Service as CustomerBalance / Hooks
App->>Config: read credits.enabled
App->>Wire: initialize components with creditsConfig
alt credits.enabled == true
Wire->>RW: NewLedgerHistoricalLedger(..., creditsConfig)
RW->>Querier: NewLedgerQuerier(RW)
RW->>Real: NewLedgerService(RW)
Wire->>Provisioner: NewLedgerResolversService(creditsConfig,...)
Provisioner->>Service: construct real balance service and ledger hooks
Service-->>App: functional ledger + balance handlers
else credits.enabled == false
Wire->>Noop: return noop Ledger, noop AccountResolver
Wire->>Service: NewNoopService() / NoopCustomerLedgerHook
Service-->>App: no-op ledger + balance handlers
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 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.
🧹 Nitpick comments (2)
openmeter/ledger/noop/noop.go (1)
208-228: Consider logging or adding a comment about silently swallowing errors.When
ledgeraccount.NewAccountFromDatafails, you return an empty&ledgeraccount.Account{}. This is probably fine for a noop implementation, but it could make debugging tricky if someone is trying to figure out why things aren't working as expected.Maybe a brief comment explaining this is intentional for the noop case would help future readers.
💡 Optional: Add a comment clarifying the error handling strategy
func newAccount(namespace string, accountType ledger.AccountType, id string) *ledgeraccount.Account { if accountType == "" { accountType = ledger.AccountTypeCustomerAccrued } account, err := ledgeraccount.NewAccountFromData(ledgeraccount.AccountData{ ID: models.NamespacedID{ Namespace: normalizeNamespace(namespace), ID: normalizeID(id, "noop-account"), }, AccountType: accountType, }, ledgeraccount.AccountLiveServices{ Querier: Ledger{}, SubAccountService: AccountService{}, }) if err != nil { + // Noop implementation: return empty account on construction error + // since this is only used when credits are disabled. return &ledgeraccount.Account{} } return account }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/ledger/noop/noop.go` around lines 208 - 228, The newAccount function currently swallows errors from ledgeraccount.NewAccountFromData and returns an empty &ledgeraccount.Account{} which can confuse future debuggers; update the newAccount function to either log the error or add a clear comment explaining that swallowing the error and returning an empty account is intentional for the noop implementation (reference newAccount, ledgeraccount.NewAccountFromData, and the error return path), so maintainers know this behavior is deliberate rather than a bug.app/common/customerbalance.go (1)
50-52: Could we add a quick regression test for the disabled branch?This is the main behavior change in the PR, and a focused test around
NewCustomerBalanceService(... Enabled: false ...)would protect against future refactors accidentally constructing the DB-backed adapters before returning the noop service.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/common/customerbalance.go` around lines 50 - 52, Add a focused unit test that constructs the creditsConfig with Enabled: false and calls NewCustomerBalanceService to verify it returns the noop implementation (customerbalance.NewNoopService) and does not instantiate any DB-backed adapters; implement this by creating mocks/spies around the database/adapter constructors used by NewCustomerBalanceService (or by injecting a fake factory) and assert those constructors were not called, and assert the returned service is the NoopService type or behaves like it.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@app/common/customerbalance.go`:
- Around line 50-52: Add a focused unit test that constructs the creditsConfig
with Enabled: false and calls NewCustomerBalanceService to verify it returns the
noop implementation (customerbalance.NewNoopService) and does not instantiate
any DB-backed adapters; implement this by creating mocks/spies around the
database/adapter constructors used by NewCustomerBalanceService (or by injecting
a fake factory) and assert those constructors were not called, and assert the
returned service is the NoopService type or behaves like it.
In `@openmeter/ledger/noop/noop.go`:
- Around line 208-228: The newAccount function currently swallows errors from
ledgeraccount.NewAccountFromData and returns an empty &ledgeraccount.Account{}
which can confuse future debuggers; update the newAccount function to either log
the error or add a clear comment explaining that swallowing the error and
returning an empty account is intentional for the noop implementation (reference
newAccount, ledgeraccount.NewAccountFromData, and the error return path), so
maintainers know this behavior is deliberate rather than a bug.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7ae9d3d0-5797-4525-bfbb-fa808f21c922
📒 Files selected for processing (10)
AGENTS.mdapp/common/customer.goapp/common/customerbalance.goapp/common/ledger.gocmd/billing-worker/wire_gen.gocmd/jobs/internal/wire_gen.gocmd/server/wire_gen.goopenmeter/ledger/customerbalance/facade.goopenmeter/ledger/customerbalance/noop.goopenmeter/ledger/noop/noop.go
Overview
Safe noop init when disabled
Fixes #(issue)
Notes for reviewer
Summary by CodeRabbit
New Features
Documentation