Repository navigation
fix: streaming customer validations - #3643
Conversation
📝 WalkthroughWalkthroughThese changes add validation to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 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 |
Signed-off-by: Alex Goth <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
openmeter/streaming/clickhouse/connector.go (1)
5-5: FilterCustomer validation is solid; consider a tiny refactor + testNice addition to validate every filter customer’s usage attribution before building the meter query – that should prevent some very confusing runtime behavior.
A couple of small, non-blocking thoughts:
- You could trade the
lo.Map + errors.Joinfor a plainforloop with a[]errorfor slightly clearer control flow, but functionally this is fine either way.- It might be worth adding a focused test around
QueryMeterthat passes a customer with missing key/subject keys and asserts we get thevalidate filter customererror, just to lock in this behavior.Also applies to: 13-13, 148-152
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
openmeter/streaming/clickhouse/connector.go(2 hunks)openmeter/streaming/clickhouse/event_query_v2_test.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/streaming/query_params.goopenmeter/streaming/clickhouse/connector.goopenmeter/streaming/clickhouse/event_query_v2_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:
openmeter/streaming/clickhouse/event_query_v2_test.go
🧠 Learnings (2)
📚 Learning: 2025-10-09T13:59:12.012Z
Learnt from: chrisgacsal
Repo: openmeterio/openmeter PR: 3486
File: openmeter/ingest/kafkaingest/serializer/serializer.go:105-107
Timestamp: 2025-10-09T13:59:12.012Z
Learning: In OpenMeter, the CloudEvents `subject` field is mandatory for the application's business logic, even though it's optional in the CloudEvents specification. The `ValidateKafkaPayloadToCloudEvent` function in `openmeter/ingest/kafkaingest/serializer/serializer.go` intentionally enforces this requirement.
Applied to files:
openmeter/streaming/query_params.go
📚 Learning: 2025-03-07T12:17:43.129Z
Learnt from: GAlexIHU
Repo: openmeterio/openmeter PR: 2383
File: openmeter/entitlement/metered/lateevents_test.go:37-45
Timestamp: 2025-03-07T12:17:43.129Z
Learning: In the OpenMeter codebase, test files like `openmeter/entitlement/metered/lateevents_test.go` may use variables like `meterSlug` and `namespace` without explicit declarations visible in the same file. This appears to be an accepted pattern in their test structure.
Applied to files:
openmeter/streaming/clickhouse/connector.go
🧬 Code graph analysis (3)
openmeter/streaming/query_params.go (1)
pkg/models/errors.go (1)
NewGenericValidationError(138-140)
openmeter/streaming/clickhouse/connector.go (4)
openmeter/streaming/query_params.go (1)
Customer(76-78)openmeter/customer/customer.go (1)
Customer(41-53)api/api.gen.go (1)
Customer(2223-2273)pkg/models/validator.go (1)
Validate(16-26)
openmeter/streaming/clickhouse/event_query_v2_test.go (2)
openmeter/streaming/query_params.go (2)
CustomerUsageAttribution(81-85)Customer(76-78)api/api.gen.go (2)
CustomerUsageAttribution(2411-2415)Customer(2223-2273)
⏰ 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). (6)
- GitHub Check: E2E
- GitHub Check: Quickstart
- GitHub Check: Lint
- GitHub Check: Test
- GitHub Check: Code Generators
- GitHub Check: Analyze (go)
🔇 Additional comments (2)
openmeter/streaming/query_params.go (1)
87-95: UsageAttribution validation now enforces a usable attribution keyThe extra check for
Key == niland emptySubjectKeysis spot on and keeps us from querying with customers that can’t actually be matched to any usage. Error shape (usingNewGenericValidationError) is consistent with the rest of the validation helpers.openmeter/streaming/clickhouse/event_query_v2_test.go (1)
119-155: Customer filter SQL expectations look consistent with the new attribution modelThe updated fixtures (IDs, keys, and subject keys) and the
subject_to_customer_idmap inwantSQLline up nicely: every key in the map is also present in theIN (?)list, and both customers clearly satisfy the new “key or subject keys” validation rule. This should give good coverage for the new mapping behavior.
Overview
Fixes #(issue)
Notes for reviewer
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.