Repository navigation
fix: allow entitlement and subscription creation if customer has no subjects assigned - #3642
Conversation
📝 WalkthroughWalkthroughThis PR adds validation for empty UsageAttribution subject keys and improves how subscriptions handle customers without subject assignments. Changes include a new Validate() method for CustomerUsageAttribution, refactored validation in entitlement logic, and expanded test coverage for subscription creation scenarios. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. 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 (3)
openmeter/entitlement/entitlement.go (1)
197-199: Nice centralization of usage-attribution validationDelegating to
c.UsageAttribution.Validate()keeps the entitlement validation focused and removes the old implicit coupling to non-empty subject keys, which is what was blocking customers with no subjects. This is a clean, future-proof spot to grow any additional attribution rules.Looks good as-is.
e2e/productcatalog_test.go (2)
89-113: customer3 setup correctly models the “no subjects” scenario (one small robustness nit)Creating
customer3withUsageAttribution.SubjectKeys: []string{}is a nice, explicit way to cover the “no subjects assigned” path, and the assertions around the response look solid.One small robustness thought: later in this test you also create another “Test Customer 3” with the same email but different usage attribution. If the backend ever enforces uniqueness on primary email or key semantics change, that could make this e2e flaky. You might consider giving one of them a slightly different key/email (e.g.
[email protected]) to decouple the scenarios.
523-552: New subscription test nicely covers the empty-subjects caseThis subtest does a good job of proving the fix: it uses
customer3(no subjects), goes through the same timing/billing-anchor flow as the existing custom-subscription test, and asserts we still get a 201, an active subscription, and no attached plan. That’s exactly the regression guard you want here.Only minor polish you might consider (optional): the failure message on
require.Nil(t, err, "received the following err: %w", err)could just use%vor a plain string to avoid depending on%wformatting behavior, but functionally the test is fine.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
e2e/productcatalog_test.go(3 hunks)openmeter/entitlement/entitlement.go(1 hunks)openmeter/streaming/query_params.go(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go
⚙️ CodeRabbit configuration file
**/*.go: In general when reviewing the Golang code make readability and maintainability a priority, even potentially suggest restructuring the code to improve them.Performance should be a priority in critical code paths. Anything related to event ingestion, message processing, database operations (regardless of database) should be vetted for potential performance bottlenecks.
Files:
openmeter/entitlement/entitlement.goopenmeter/streaming/query_params.goe2e/productcatalog_test.go
**/*_test.go
⚙️ CodeRabbit configuration file
**/*_test.go: Make sure the tests are comprehensive and cover the changes. Keep a strong focus on unit tests and in-code integration tests.
When appropriate, recommend e2e tests for critical changes.
Files:
e2e/productcatalog_test.go
🧬 Code graph analysis (2)
openmeter/streaming/query_params.go (5)
openmeter/customer/customer.go (1)
CustomerUsageAttribution(200-202)api/api.gen.go (1)
CustomerUsageAttribution(2411-2415)openmeter/billing/invoice.go (1)
CustomerUsageAttribution(609-609)pkg/models/validator.go (1)
Validate(16-26)pkg/models/errors.go (1)
NewGenericValidationError(138-140)
e2e/productcatalog_test.go (2)
api/api.gen.go (7)
CustomerUsageAttribution(2411-2415)SubscriptionTiming(7550-7552)SubscriptionCreate(7266-7268)CustomSubscriptionCreate(2204-2220)CustomerKey(2352-2354)SubscriptionStatusActive(812-812)Plan(5963-6025)openmeter/subscription/state.go (1)
SubscriptionStatusActive(16-16)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: Artifacts / Container image
- GitHub Check: Lint
- GitHub Check: Migration Checks
- GitHub Check: Test
- GitHub Check: Code Generators
- GitHub Check: Build
- GitHub Check: Analyze (go)
🔇 Additional comments (2)
openmeter/streaming/query_params.go (1)
87-93: Validation looks good and matches the “no subjects” requirementCentralizing the check on
IDhere and not enforcing any constraint onSubjectKeyslines up nicely with the API contract that subject keys can be empty while still requiring a concrete customer identifier. The use ofmodels.NewGenericValidationErroralso keeps this consistent with the rest of the validation layer.Nothing to change from my side here.
e2e/productcatalog_test.go (1)
31-31: Comment update matches the new setupThe comment now correctly reflects that you’re working with three customers in this test, which helps keep the long test readable.
Overview
Fixes #(issue)
Notes for reviewer
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.