Skip to content

refactor(streaming): group by filters in args - #3431

Merged
hekike merged 1 commit into
mainfrom
refactor/group-by-filter-arguments
Sep 25, 2025
Merged

hekike merged 1 commit into
mainfrom
refactor/group-by-filter-arguments

Conversation

@hekike

@hekike hekike commented Sep 25, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of metric filtering when using group values, preventing issues with special characters and ensuring consistent results across scenarios.
  • Refactor

    • Enhanced query construction for filter conditions to be more resilient and efficient.
  • Tests

    • Updated test coverage to validate filtering with various group configurations, customer/subject contexts, and timezone variations.

@hekike
hekike requested a review from a team as a code owner September 25, 2025 18:12
@hekike hekike added area/processor release-note/ignore Ignore this change when generating release notes labels Sep 25, 2025
@coderabbitai

coderabbitai Bot commented Sep 25, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Switches SQL filter construction in queryMeter.toSQL from inline quoted strings to parameterized variables, and updates tests to expect parameter placeholders with corresponding argument lists. No method signatures change; overall query structure remains the same.

Changes

Cohort / File(s) Summary
ClickHouse meter query construction
openmeter/streaming/clickhouse/meter_query.go
Changed WHERE-clause filter formatting from "%s = '%s'" with inline quoting to "%s = %s" using query.Var(...) for parameter binding in toSQL().
ClickHouse meter query tests
openmeter/streaming/clickhouse/meter_query_test.go
Updated expected SQL to use parameter placeholders (e.g., JSON_VALUE(...)= ?) and adjusted wantArgs to include corresponding group values across multiple test cases, including prewhere and timezone variants.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

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 concisely summarizes the key refactoring in the streaming module, indicating that group-by filter values are now passed as arguments. It follows conventional commit conventions with a clear scope and concise description. It accurately captures the main change regarding parameterizing filters without extraneous detail.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/group-by-filter-arguments

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.

@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/meter_query.go (1)

275-276: Good move to parameterize group-by filters; simplify with builder Equal

Using query.Var binds args safely. You can further simplify and avoid relying on Var’s side-effect by using the builder’s Equal helper, which also binds args:

-				return fmt.Sprintf("%s = %s", column, query.Var((value)))
+				return query.Equal(column, value)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b8dab9 and 9f44fb2.

📒 Files selected for processing (2)
  • openmeter/streaming/clickhouse/meter_query.go (1 hunks)
  • openmeter/streaming/clickhouse/meter_query_test.go (4 hunks)
⏰ 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: Migration Checks
  • GitHub Check: Artifacts / Container image
  • GitHub Check: Lint
  • GitHub Check: Build
  • GitHub Check: Test
  • GitHub Check: Code Generators
  • GitHub Check: Analyze (go)
🔇 Additional comments (4)
openmeter/streaming/clickhouse/meter_query_test.go (4)

399-401: Tests aligned to parameter binding

Expecting placeholders and args for group filters is correct and improves safety.


420-422: LGTM: multiple values bound as params

Matching two placeholders and args for OR conditions is correct.


441-443: LGTM: multiple groups and values

Placeholders and args ordering looks consistent with query construction.


484-486: LGTM: PREWHERE + parameterized filters

The PREWHERE restructuring and parameterized WHERE conditions match the builder behavior and settings.

@hekike
hekike merged commit 7cf71f2 into main Sep 25, 2025
@hekike
hekike deleted the refactor/group-by-filter-arguments branch September 25, 2025 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/processor release-note/ignore Ignore this change when generating release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants