feat(eap): translate OP_REGEXP to ClickHouse match() - #8437
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 96b1da7. Configure here.
| # Needs ClickHouse > 26.8 for matchCaseInsensitive; lower() is a stand-in until then. | ||
| if ignore_case: | ||
| return f.match(f.lower(value), f.lower(pattern)) | ||
| return f.match(value, pattern) |
There was a problem hiding this comment.
Ignore-case regex mangles escape sequences
Medium Severity
ignore_case applies lower() to the regexp pattern as well as the haystack. That is not equivalent to case-insensitive matching: RE2 escapes whose meaning depends on case (\S, \D, \W, \B, \Q, \A, \P) invert or break, so logs searches with ignore_case can silently return the wrong rows.
Reviewed by Cursor Bugbot for commit 96b1da7. Configure here.
There was a problem hiding this comment.
We can fix it when we upgrade our clickhouse to 26.8+ imo. This is fine as a stopgap solution.
7568c58 to
79885e8
Compare
79885e8 to
fdfc2bc
Compare
| raise BadSnubaRPCRequestException( | ||
| f"Unsupported any_attribute_filter op: {AnyAttributeFilter.Op.Name(filter_.op)}" | ||
| ) | ||
|
|
||
|
|
||
| def _any_attribute_filter_to_expression( |
There was a problem hiding this comment.
Bug: The error message for unsupported operators in _any_attribute_op_expression uses the original filter_.op instead of the effective op, which could cause confusing error messages for future negative operators.
Severity: LOW
Suggested Fix
Update the exception logging in the default case of the match statement to use the op parameter instead of filter_.op. Change f"Unsupported any_attribute_filter op: {AnyAttributeFilter.Op.Name(filter_.op)}" to f"Unsupported any_attribute_filter op: {AnyAttributeFilter.Op.Name(op)}". This ensures the error message accurately reflects the operator being processed by the function.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: snuba/web/rpc/common/common.py#L905-L910
Potential issue: In the `_any_attribute_op_expression` function, the error handling for
unsupported operators incorrectly uses the original operator from the filter,
`filter_.op`, to generate the error message. The function logic, however, operates on an
`effective_op` (passed as the `op` parameter), which resolves negative operators (e.g.,
`OP_NOT_LIKE`) to their positive counterparts. If a new, unhandled operator is added in
the future that follows this negative-to-positive mapping, the resulting error message
will be misleading by referencing the original negative operator instead of the positive
one that was actually being processed.
|
|
||
| def _is_valid_regexp_pattern(v: AttributeValue) -> None: | ||
| if v.WhichOneof("value") != "val_str" or v.val_str == "": | ||
| raise BadSnubaRPCRequestException("REGEXP pattern must be a non-empty string") |
There was a problem hiding this comment.
@pbhandari is there more validation we can do here before we send the query to clickhouse (e.g. missing parentheses) ? Maybe doesn't have to be super robust but just anything that is guaranteed to fail we shouldn't send to clickhouse if possible


Problem
EAP RPC comparison filters have no regexp op. Logs search (LOGS-958) is blocked on EAP-739.
Depends on sentry-protos PR 420 (
OP_REGEXPon ComparisonFilter / AnyAttributeFilter).Solution
Translate
OP_REGEXPin the shared EAP filter translator to ClickHousematch()(search-anywhere, RE2).ignore_case→match(lower(value), lower(pattern))CANNOT_COMPILE_REGEXP(36) remapped to RPC 400matchincluding REGEXPValidation
pytest tests/web/rpc/test_common.py::TestTraceItemFiltersRegexpand related LIKE/any-attribute tests.Linear
https://linear.app/getsentry/issue/EAP-739/add-regexp-support-for-eap-rpc