Skip to content

fix: streaming customer validations - #3643

Merged
GAlexIHU merged 3 commits into
mainfrom
fix/streaming-customer-validations
Nov 27, 2025
Merged

GAlexIHU merged 3 commits into
mainfrom
fix/streaming-customer-validations

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Nov 27, 2025 •

Copy link
Copy Markdown
Contributor

Overview

Fixes #(issue)

Notes for reviewer

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced validation for customer filters with improved error messaging when invalid data is detected.
    • Tightened customer attribution validation to ensure required fields are populated.
  • Tests

    • Updated test fixtures to reflect current customer resource structure.

✏️ Tip: You can customize this high-level summary in your review settings.

@GAlexIHU
GAlexIHU requested a review from a team as a code owner November 27, 2025 14:37
@GAlexIHU GAlexIHU added the release-note/bug-fix Release note: Bug Fixes label Nov 27, 2025
@coderabbitai

coderabbitai Bot commented Nov 27, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

These changes add validation to CustomerUsageAttribution in the ClickHouse query pipeline, requiring either a Key or SubjectKeys to be present. The QueryMeter function now validates filter customers upfront, and test fixtures are updated to reflect the new customer resource structure with IDs and subject keys.

Changes

Cohort / File(s) Summary
Query validation enforcement
openmeter/streaming/clickhouse/connector.go
Adds validation for FilterCustomer in QueryMeter by mapping each customer through GetUsageAttribution().Validate() and returning an error if validation fails, short-circuiting before query construction.
Validation rule tightening
openmeter/streaming/query_params.go
Adds requirement to CustomerUsageAttribution.Validate() that either Key must be non-nil or SubjectKeys must be non-empty, tightening the validation constraint.
Test fixture updates
openmeter/streaming/clickhouse/event_query_v2_test.go
Updates test fixtures in TestQueryEventsTableV2_ToSQL and TestQueryEventsTableV2_ToCountRowSQL to reflect new customer resource structure with updated IDs, Key pointers, and SubjectKeys mappings, and adjusts expected SQL accordingly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Validation logic in connector.go: Straightforward error wrapping and early return; minimal control flow changes
  • Test fixture updates: Repetitive pattern changes across fixtures (consistent ID/key/SubjectKeys updates)
  • Validation rule addition: Single constraint addition in query_params.go; easy to verify

Possibly related PRs

Suggested labels

area/processor

Suggested reviewers

  • tothandras
  • hekike

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: streaming customer validations' directly and accurately captures the main changes: adding customer validation logic to the streaming ClickHouse connector module.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/streaming-customer-validations

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 and usage tips.

@GAlexIHU
GAlexIHU enabled auto-merge (squash) November 27, 2025 14:38

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
openmeter/streaming/clickhouse/connector.go (1)

5-5: FilterCustomer validation is solid; consider a tiny refactor + test

Nice 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.Join for a plain for loop with a []error for slightly clearer control flow, but functionally this is fine either way.
  • It might be worth adding a focused test around QueryMeter that passes a customer with missing key/subject keys and asserts we get the validate filter customer error, 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

📥 Commits

Reviewing files that changed from the base of the PR and between fb16717 and 205bb1b.

📒 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.go
  • openmeter/streaming/clickhouse/connector.go
  • openmeter/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 key

The extra check for Key == nil and empty SubjectKeys is spot on and keeps us from querying with customers that can’t actually be matched to any usage. Error shape (using NewGenericValidationError) 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 model

The updated fixtures (IDs, keys, and subject keys) and the subject_to_customer_id map in wantSQL line up nicely: every key in the map is also present in the IN (?) list, and both customers clearly satisfy the new “key or subject keys” validation rule. This should give good coverage for the new mapping behavior.

@GAlexIHU
GAlexIHU merged commit 5e160e6 into main Nov 27, 2025
@GAlexIHU
GAlexIHU deleted the fix/streaming-customer-validations branch November 27, 2025 14:58
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.

2 participants