Repository navigation
kafka_consumer: prefilter consumer groups before fetching offsets - #25232
Conversation
✅ Dispatcher tests: passed
✅ 6 passed · nothing failed Batches · ✅ batch-01 6/6 Dispatcher finished on |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 59ac06f530
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return [ | ||
| grp | ||
| for grp in self.client.list_consumer_groups() | ||
| if grp and self.config._consumer_groups_compiled_group_regex.match(grp) |
There was a problem hiding this comment.
Require the prefilter to match the complete group ID
re.Pattern.match() accepts prefix matches, while the existing combined expression requires the group pattern to reach the comma separating the group from its topic. For example, consumer_groups_regex: {'orders': {}} should select only orders, but this prefilter also fetches offsets for orders-v2, orders-archive, and every other prefixed group before the later tuple-level filter discards them. On clusters with many similarly named groups—especially when a literal group is paired with a topic regex—this can preserve the large offset-fetch fan-out that the change is intended to eliminate; use a whole-ID or delimiter-aware match.
Useful? React with 👍 / 👎.
| return re.compile("|".join(patterns)) | ||
|
|
||
| @staticmethod | ||
| def _compile_group_regex(consumer_groups_regex, consumer_groups): |
There was a problem hiding this comment.
Should group patterns match across the group/topic delimiter, or only within the group ID? The PR description says topic/partition filtering behavior is unchanged, but it changes for one class of pattern.
With consumer_groups_regex: {'a,.': {}}, group a, topic b,c, partition 0: the tuple filter's pattern (a,.,.+,.+) matches "a,b,c,0", so the old code emitted the offset. The prefilter drops group a — a,. does not match "a" — so no offset request is made and the metric disappears. The divergence survives the fullmatch change suggested on kafka_consumer.py:299.
If patterns should match within the group ID only, note the divergence in the PR description. Otherwise, reject patterns containing an unescaped comma at validation time.
Signed-off-by: namtran1812 <158846154+namtran1812@users.noreply.github.com>
Signed-off-by: namtran1812 <158846154+namtran1812@users.noreply.github.com>
Signed-off-by: namtran1812 <158846154+namtran1812@users.noreply.github.com>
|
Hi @iliakur I just dded a regression test asserting that pattern a,. with discovered group a submits an empty list for offset retrieval, also pdated the changelog to document complete group-ID matching and the change for patterns spanning the group/topic comma |
evalya-impact-summaryevalya impact analysis |
|
Backport evaluation: View Slack thread |
…oordinator-error-recovery Resolve the conflict in kafka_consumer/tests/test_unit.py, where both sides appended tests to the end of the file: keep master's consumer group prefilter tests (#25232), followed by this branch's coordinator error test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What does this PR do?
Filters discovered Kafka consumer groups against
consumer_groups_regexbefore fetching their offsets.Previously, when
consumer_groups_regexwas configured, the check discovered all consumer groups and passed all of them tolist_consumer_group_offsets. Regex filtering happened only afterward at the consumer group/topic/partition level.The prefilter matches the complete discovered group ID. Topic and partition filtering still runs afterward. Patterns that previously matched across the group/topic comma (for example,
a,.matching groupawith a suitable topic) will no longer select that group; configure a pattern matching the group ID instead.Motivation
On clusters with many consumer groups, a narrow
consumer_groups_regexcould still result in offset requests for every discovered group.A regression test verifies that
ordersis submitted for offset retrieval while prefix-sharing groups such asorders-v2andorders-archiveare excluded.monitor_unlisted_consumer_groupscontinues to bypass the prefilter and monitor all discovered groups.Fixes #24911
Testing
consumer_groupsandconsumer_groups_regex.monitor_unlisted_consumer_groupscontinues to fetch all groups.git diff --checkpass.Review checklist (to be filled by reviewers)
qa/requiredif this PR needs QA validation, orqa/skip-qaif it does not. Exactly one of the two is required.backport/<branch-name>label to the PR and it will automatically open a backport PR once this one is merged