Skip to content

[codex] Exclude locked namespaces from invoice collection - #4630

Merged
turip merged 1 commit into
mainfrom
codex/exclude-locked-namespaces-from-collection
Jul 1, 2026
Merged

turip merged 1 commit into
mainfrom
codex/exclude-locked-namespaces-from-collection

Conversation

@turip

@turip turip commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add an excluded-namespace filter to gathering invoice listing
  • apply the collector lockdown namespaces when listing collectible invoices

Impact

Locked namespaces are skipped by collection discovery without blocking explicit namespace/customer filtering for the remaining collection path.

Validation

  • go test ./openmeter/billing/worker/collect ./openmeter/billing/adapter

Summary by CodeRabbit

  • New Features
    • Added support for excluding specific namespaces when listing gathering invoices.
    • Invoice collection now respects locked namespaces and leaves them out of eligible invoice results.
  • Bug Fixes
    • Improved invoice filtering so results are narrowed by both included and excluded namespaces, reducing incorrect invoice selection.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds an ExcludedNamespaces field to ListGatheringInvoicesInput, applies it as a NamespaceNotIn filter in the adapter's ListGatheringInvoices query, and updates the invoice collector to populate this field with locked namespaces so they are excluded from collectable invoice listings.

Changes

Excluded Namespaces Filtering

Layer / File(s) Summary
Input contract and query filter
openmeter/billing/gatheringinvoice.go, openmeter/billing/adapter/gatheringinvoice.go
Adds ExcludedNamespaces []string field to ListGatheringInvoicesInput and applies a conditional NamespaceNotIn(...) constraint in the adapter query when the field is non-empty.
Collector wiring
openmeter/billing/worker/collect/collect.go
ListCollectableInvoices now sets ExcludedNamespaces to lockedNamespaces on the query input, alongside existing Namespaces and Customers.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

Suggested labels: area/billing, release-note/feature

Suggested reviewers: tothandras, GAlexIHU

Nice tidy little change here — one new field ripples cleanly from input struct to query filter to caller, keeping locked namespaces out of the invoice party! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: excluding locked namespaces from invoice collection.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 codex/exclude-locked-namespaces-from-collection

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.

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR skips locked namespaces during collectable invoice discovery. The main changes are:

  • Adds an ExcludedNamespaces field to gathering invoice list inputs.
  • Applies the exclusion as a namespace NOT IN filter in the billing invoice adapter.
  • Passes collector lockdown namespaces into collectable invoice listing.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • Existing listing callers keep the previous behavior unless they set the new exclusion field.
  • The collector still has downstream namespace-lock checks before invoice mutation work.

Important Files Changed

Filename Overview
openmeter/billing/gatheringinvoice.go Adds the optional excluded namespace list to the gathering invoice listing input.
openmeter/billing/adapter/gatheringinvoice.go Adds an adapter filter that excludes namespaces when the new input field is populated.
openmeter/billing/worker/collect/collect.go Wires collector lockdown namespaces into collectable invoice discovery.

Reviews (1): Last reviewed commit: "feat(billing): exclude locked namespaces..." | Re-trigger Greptile

@turip
turip marked this pull request as ready for review July 1, 2026 12:47
@turip
turip requested a review from a team as a code owner July 1, 2026 12:47
@turip turip added the release-note/bug-fix Release note: Bug Fixes label Jul 1, 2026
@turip
turip enabled auto-merge (squash) July 1, 2026 12:48

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

🧹 Nitpick comments (1)
openmeter/billing/worker/collect/collect.go (1)

145-167: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant locked-namespace filter now that the query already excludes them.

Since ListCollectableInvoices now passes ExcludedNamespaces: a.lockedNamespaces down to the adapter query, the returned invoices should already have locked namespaces filtered out. The subsequent customerIDs filter at Line 165-167 re-checking !slices.Contains(a.lockedNamespaces, id.Namespace) is now dead weight — worth trimming for clarity.

♻️ Suggested cleanup
-	customerIDs := lo.Map(invoices, func(i billing.GatheringInvoice, _ int) customer.CustomerID {
-		return customer.CustomerID{
-			Namespace: i.Namespace,
-			ID:        i.CustomerID,
-		}
-	})
-
-	customerIDs = lo.Filter(lo.Uniq(customerIDs), func(id customer.CustomerID, _ int) bool {
-		return !slices.Contains(a.lockedNamespaces, id.Namespace)
-	})
+	customerIDs := lo.Uniq(lo.Map(invoices, func(i billing.GatheringInvoice, _ int) customer.CustomerID {
+		return customer.CustomerID{
+			Namespace: i.Namespace,
+			ID:        i.CustomerID,
+		}
+	}))

If there's a reason to keep the defense-in-depth check (e.g., distrust of the adapter layer), a short comment explaining that intent would help future readers.

🤖 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/collect/collect.go` around lines 145 - 167, Remove
the redundant locked-namespace check from the customer ID post-processing in
collect.go: ListCollectableInvoices already excludes a.lockedNamespaces, so the
extra lo.Filter over customerIDs that re-applies
!slices.Contains(a.lockedNamespaces, id.Namespace) is unnecessary. Update the
collect flow around ListCollectableInvoices and customerIDs to keep only the
unique mapping, or add a brief comment near that filter if you intentionally
want defense-in-depth.
🤖 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/collect/collect.go`:
- Around line 145-167: Remove the redundant locked-namespace check from the
customer ID post-processing in collect.go: ListCollectableInvoices already
excludes a.lockedNamespaces, so the extra lo.Filter over customerIDs that
re-applies !slices.Contains(a.lockedNamespaces, id.Namespace) is unnecessary.
Update the collect flow around ListCollectableInvoices and customerIDs to keep
only the unique mapping, or add a brief comment near that filter if you
intentionally want defense-in-depth.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: be31d6c1-6d2e-4bd0-ab1e-62eea908f076

📥 Commits

Reviewing files that changed from the base of the PR and between 0b2b1d3 and 9908422.

📒 Files selected for processing (3)
  • openmeter/billing/adapter/gatheringinvoice.go
  • openmeter/billing/gatheringinvoice.go
  • openmeter/billing/worker/collect/collect.go

@turip
turip merged commit 91f1e5a into main Jul 1, 2026
27 of 28 checks passed
@turip
turip deleted the codex/exclude-locked-namespaces-from-collection branch July 1, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants