-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add allow/deny predicates to MetricFilter
- Loading branch information
1 parent
169d88f
commit 15b57e1
Showing
6 changed files
with
123 additions
and
61 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
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,83 @@ | ||
package io.factorhouse.kpow; | ||
|
||
import org.apache.kafka.common.MetricName; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
public class MetricFilter { | ||
public enum FilterType { | ||
ACCEPT, DENY | ||
} | ||
|
||
public static class FilterCriteria { | ||
private final Predicate<MetricName> predicate; | ||
private final FilterType filterType; | ||
|
||
// Constructor to initialize both fields | ||
private FilterCriteria(Predicate<MetricName> predicate, FilterType filterType) { | ||
this.predicate = predicate; | ||
this.filterType = filterType; | ||
} | ||
|
||
public Predicate<MetricName> getPredicate() { | ||
return predicate; | ||
} | ||
|
||
public FilterType getFilterType() { | ||
return filterType; | ||
} | ||
} | ||
|
||
private final List<FilterCriteria> filters; | ||
|
||
public MetricFilter() { | ||
this.filters = new ArrayList<>(); | ||
} | ||
|
||
public List<FilterCriteria> getFilters() { | ||
return Collections.unmodifiableList(filters); | ||
} | ||
|
||
public MetricFilter accept() { | ||
Predicate<MetricName> acceptPredicate = (_filter) -> { return true; }; | ||
FilterCriteria criteria = new FilterCriteria(acceptPredicate, FilterType.ACCEPT); | ||
this.filters.add(criteria); | ||
return this; | ||
} | ||
|
||
public MetricFilter accept(Predicate<MetricName> acceptFilter) { | ||
FilterCriteria criteria = new FilterCriteria(acceptFilter, FilterType.ACCEPT); | ||
this.filters.add(criteria); | ||
return this; | ||
} | ||
|
||
public MetricFilter deny() { | ||
Predicate<MetricName> denyFilter = (_filter) -> { return true; }; | ||
FilterCriteria criteria = new FilterCriteria(denyFilter, FilterType.DENY); | ||
this.filters.add(criteria); | ||
return this; | ||
} | ||
|
||
public MetricFilter deny(Predicate<MetricName> denyFilter) { | ||
FilterCriteria criteria = new FilterCriteria(denyFilter, FilterType.DENY); | ||
this.filters.add(criteria); | ||
return this; | ||
} | ||
|
||
public MetricFilter acceptNameStartsWith(String prefix) { | ||
Predicate<MetricName> acceptFilter = (metricName) -> { return metricName.name().startsWith(prefix); }; | ||
FilterCriteria criteria = new FilterCriteria(acceptFilter, FilterType.ACCEPT); | ||
this.filters.add(criteria); | ||
return this; | ||
} | ||
|
||
public MetricFilter denyNameStartsWith(String prefix) { | ||
Predicate<MetricName> denyFilter = (metricName) -> { return metricName.name().startsWith(prefix); }; | ||
FilterCriteria criteria = new FilterCriteria(denyFilter, FilterType.DENY); | ||
this.filters.add(criteria); | ||
return this; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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