Skip to content

Comments

BE: Add CG filter by state#1693

Open
Haarolean wants to merge 2 commits intomainfrom
issues/1476
Open

BE: Add CG filter by state#1693
Haarolean wants to merge 2 commits intomainfrom
issues/1476

Conversation

@Haarolean
Copy link
Member

  • Breaking change? (if so, please describe the impact and migration path for existing application instances)

What changes did you make? (Give an overview)
Added backend filters for consumers by their states. backend for #1476

Is there anything you'd like reviewers to focus on?

How Has This Been Tested? (put an "x" (case-sensitive!) next to an item)

  • No need to
  • Manually (please, describe, if necessary)
  • Unit checks
  • Integration checks
  • Covered by existing automation

Checklist (put an "x" (case-sensitive!) next to all the items, otherwise the build will fail)

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (e.g. ENVIRONMENT VARIABLES)
  • My changes generate no new warnings (e.g. Sonar is happy)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged

Check out Contributing and Code of Conduct

A picture of a cute animal (not mandatory but encouraged)

@Haarolean Haarolean requested a review from Vixtir February 18, 2026 16:59
@Haarolean Haarolean self-assigned this Feb 18, 2026
@Haarolean Haarolean requested a review from a team as a code owner February 18, 2026 16:59
@Haarolean Haarolean added type/enhancement En enhancement/improvement to an already existing feature scope/backend Related to backend changes area/ux User experiense issues area/consumers labels Feb 18, 2026
@kapybro kapybro bot added status/triage Issues pending maintainers triage status/triage/completed Automatic triage completed and removed status/triage Issues pending maintainers triage labels Feb 18, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds backend support for filtering consumer groups by their Kafka state (e.g., STABLE, EMPTY) in the paged list and CSV export endpoints, aligning with issue #1476.

Changes:

  • Extended the Consumer Groups API contract to accept a state query parameter (multi-value).
  • Wired the new state query parameter through the controller into ConsumerGroupService.
  • Added unit and integration tests covering state-based filtering scenarios.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
contract-typespec/api/consumer-groups.tsp Adds state query param to paged + CSV consumer-group endpoints in the API contract.
api/src/main/java/io/kafbat/ui/controller/ConsumerGroupsController.java Plumbs the new state query param into service calls for paged + CSV endpoints.
api/src/main/java/io/kafbat/ui/service/ConsumerGroupService.java Implements state filtering logic for consumer group listings.
api/src/test/java/io/kafbat/ui/service/ConsumerGroupServiceTest.java Adds unit test validating filtering behavior for single/multi state selections.
api/src/test/java/io/kafbat/ui/KafkaConsumerGroupTests.java Adds integration test validating HTTP query-param filtering by state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

.map(this::mapToKafkaState)
.collect(Collectors.toSet());
return groups.stream()
.filter(cg -> kafkaStates.contains(cg.state().orElse(ConsumerGroupState.UNKNOWN)))
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State filtering relies on ConsumerGroupListing.state() which is optional and may be empty depending on broker/client capabilities. When state() is empty, this code treats it as UNKNOWN, causing valid groups (e.g., STABLE/EMPTY) to be incorrectly excluded whenever a state filter is applied. Consider filtering based on ConsumerGroupDescription.state() (you already fetch descriptions in loadSortedDescriptions) or otherwise ensuring the listing state is populated before filtering.

Suggested change
.filter(cg -> kafkaStates.contains(cg.state().orElse(ConsumerGroupState.UNKNOWN)))
.filter(cg -> cg.state().map(kafkaStates::contains).orElse(true))

Copilot uses AI. Check for mistakes.
Comment on lines +263 to +271
// Create consumers, poll, then close to create EMPTY groups
try (val consumer1 = createTestConsumerWithGroupId(emptyGroup1)) {
consumer1.subscribe(List.of(topicName));
consumer1.poll(Duration.ofMillis(100));
}
try (val consumer2 = createTestConsumerWithGroupId(emptyGroup2)) {
consumer2.subscribe(List.of(topicName));
consumer2.poll(Duration.ofMillis(100));
}
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test assumes consumer groups will immediately appear in the expected state after poll()/close. Consumer group creation and state transitions are asynchronous and can take time, so the immediate assertions can be flaky. Consider using Awaitility (already used in other integration tests) to wait until the expected groups are visible (and in the expected state) before asserting, and/or explicitly committing offsets/unsubscribing to ensure the groups reliably end up in EMPTY state.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Copy link

Copilot AI commented Feb 18, 2026

@germanosin I've opened a new pull request, #1694, to work on those changes. Once the pull request is ready, I'll request review from you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/consumers area/ux User experiense issues scope/backend Related to backend changes status/triage/completed Automatic triage completed type/enhancement En enhancement/improvement to an already existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants