-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Limit consumer group API calls to page, add log end offset to describe (
#279) Also support consumer group ID (name) and state filtering on list operation Signed-off-by: Michael Edgar <[email protected]>
- Loading branch information
Showing
12 changed files
with
254 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
api/src/main/java/com/github/eyefloaters/console/api/model/ConsumerGroupFilterParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.github.eyefloaters.console.api.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import jakarta.ws.rs.QueryParam; | ||
|
||
import org.eclipse.microprofile.openapi.annotations.enums.Explode; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; | ||
|
||
import com.github.eyefloaters.console.api.support.ErrorCategory; | ||
import com.github.eyefloaters.console.api.support.FetchFilterPredicate; | ||
|
||
import io.xlate.validation.constraints.Expression; | ||
import io.xlate.validation.constraints.Expression.ExceptionalValue; | ||
|
||
public class ConsumerGroupFilterParams { | ||
|
||
@QueryParam("filter[id]") | ||
@Parameter( | ||
description = "Retrieve only consumer groups with an ID matching this parameter", | ||
schema = @Schema(implementation = String[].class, minItems = 2), | ||
explode = Explode.FALSE) | ||
@Expression( | ||
when = "self != null", | ||
value = "self.operator == 'eq' || self.operator == 'in' || self.operator == 'like'", | ||
message = "unsupported filter operator, supported values: [ 'eq', 'in', 'like' ]", | ||
payload = ErrorCategory.InvalidQueryParameter.class, | ||
node = "filter[id]") | ||
@Expression( | ||
when = "self != null", | ||
value = "self.operands.size() >= 1", | ||
message = "at least 1 operand is required", | ||
payload = ErrorCategory.InvalidQueryParameter.class, | ||
node = "filter[id]") | ||
FetchFilter idFilter; | ||
|
||
@QueryParam("filter[state]") | ||
@Parameter( | ||
description = "Retrieve only consumer groups matching the state identified by this parameter", | ||
schema = @Schema(implementation = String[].class, minItems = 2), | ||
explode = Explode.FALSE) | ||
@Expression( | ||
when = "self != null", | ||
value = "self.operator == 'eq' || self.operator == 'in'", | ||
message = "unsupported filter operator, supported values: [ 'eq', 'in' ]", | ||
payload = ErrorCategory.InvalidQueryParameter.class, | ||
node = "filter[state]") | ||
@Expression( | ||
when = "self != null", | ||
value = "self.operands.size() >= 1", | ||
message = "at least 1 operand is required", | ||
payload = ErrorCategory.InvalidQueryParameter.class, | ||
node = "filter[state]") | ||
@Expression( | ||
when = "self != null && self.operands.size() >= 1", | ||
classImports = "org.apache.kafka.common.ConsumerGroupState", | ||
value = """ | ||
self.operands.stream() | ||
.map(state -> ConsumerGroupState.valueOf(state)) | ||
.noneMatch(state -> state == ConsumerGroupState.UNKNOWN) | ||
""", | ||
exceptionalValue = ExceptionalValue.UNSET, | ||
message = "operands list contains an invalid consumer group state", | ||
payload = ErrorCategory.InvalidQueryParameter.class, | ||
node = "filter[state]") | ||
FetchFilter stateFilter; | ||
|
||
public List<Predicate<ConsumerGroup>> buildPredicates() { | ||
List<Predicate<ConsumerGroup>> predicates = new ArrayList<>(2); | ||
|
||
if (idFilter != null) { | ||
predicates.add(new FetchFilterPredicate<>(idFilter, ConsumerGroup::getGroupId)); | ||
} | ||
|
||
if (stateFilter != null) { | ||
predicates.add(new FetchFilterPredicate<>("filter[state]", stateFilter, ConsumerGroup::getState)); | ||
} | ||
|
||
return predicates; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.