perf(governance): resolve customer keys in one bulk query [OM-387]#4522
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
💤 Files with no reviewable changes (2)
🚧 Files skipped from review as they are similar to previous changes (7)
📝 WalkthroughWalkthroughThis PR adds bulk customer resolution by usage attribution keys. A new multi-key input and lookup path are wired through the customer service and adapter, governance now resolves keys in one bulk call, and tests plus mocks cover the new flow. ChangesBulk customer resolution by usage attribution keys
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
resolveCustomers looped GetCustomerByUsageAttribution once per key (N serial DB round trips over the full key set, before pagination). Add customer.GetCustomersByUsageAttribution — one query matching customer.key or subject_key IN keys — and reconstruct matched[]/not-found in memory. Collapses N queries to 1; biggest win at high customer / low feature counts.
e816893 to
3fc5025
Compare
What
Optimize the governance access query (
POST /api/v3/openmeter/governance/query) by resolving customer keys in a single bulk query instead of one DB round trip per key.Why
resolveCustomersloopedGetCustomerByUsageAttributiononce per customer key — N serial DB round trips over the full key set (before pagination, so page size didn't help). The e2e benchmark showed this made the customers axis linear; it was the dominant cost at high customer counts.How
customer.GetCustomersByUsageAttribution(ctx, {Namespace, Keys})on the customerService+Adapter: one query matchingcustomer.key IN keys OR subject_key IN keys(mirrors the single-keyGetCustomerByUsageAttributionsemantics), subjects eager-loaded, soft-deleted rows filtered. Returns[]Customer— multi-get-by-set convention, not paginated.resolveCustomersto call it once and reconstructmatched[]/ customer-not-found errors in memory from each customer's key + subject keys. Result shape unchanged → sort → paginate →resolveAccessuntouched; behavior preserved.Collapses N customer-resolution queries to 1.
Benchmark (p50, baseline → new):
100×10−21%, wholeC=10row −17…−29%. High-feature cells flat (100×100≈0) — bounded by the still-serialresolveAccessGetAccessloop, a deliberate follow-up.Summary by CodeRabbit