KAFKA-17192 Fix MirrorMaker2 worker config does not pass config.provi… (#16678)

Reviewers: Chris Egerton <chrise@aiven.io>
This commit is contained in:
Kondrat Bertalan 2024-07-31 22:50:22 +02:00 committed by GitHub
parent 0eb9ac2bd0
commit 8d8c367066
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 2 deletions

View File

@ -1648,9 +1648,24 @@ public final class Utils {
* @param <V> the type of values stored in the map
*/
public static <V> Map<String, V> entriesWithPrefix(Map<String, V> map, String prefix, boolean strip) {
return entriesWithPrefix(map, prefix, strip, false);
}
/**
* Find all key/value pairs whose keys begin with the given prefix, optionally removing that prefix
* from all resulting keys.
* @param map the map to filter key/value pairs from
* @param prefix the prefix to search keys for
* @param strip whether the keys of the returned map should not include the prefix
* @param allowMatchingLength whether to include keys that are exactly the same length as the prefix
* @return a {@link Map} containing a key/value pair for every key/value pair in the {@code map}
* parameter whose key begins with the given {@code prefix}; may be empty, but never null
* @param <V> the type of values stored in the map
*/
public static <V> Map<String, V> entriesWithPrefix(Map<String, V> map, String prefix, boolean strip, boolean allowMatchingLength) {
Map<String, V> result = new HashMap<>();
for (Map.Entry<String, V> entry : map.entrySet()) {
if (entry.getKey().startsWith(prefix) && entry.getKey().length() > prefix.length()) {
if (entry.getKey().startsWith(prefix) && (allowMatchingLength || entry.getKey().length() > prefix.length())) {
if (strip)
result.put(entry.getKey().substring(prefix.length()), entry.getValue());
else

View File

@ -308,7 +308,7 @@ public class MirrorMakerConfig extends AbstractConfig {
}
private Map<String, String> stringsWithPrefix(String prefix) {
return Utils.entriesWithPrefix(rawProperties, prefix, false);
return Utils.entriesWithPrefix(rawProperties, prefix, false, true);
}
static Map<String, String> clusterConfigsWithPrefix(String prefix, Map<String, String> props) {

View File

@ -257,6 +257,7 @@ public class MirrorMakerConfigTest {
assertEquals("b->a", aProps.get("client.id"));
assertEquals("123", aProps.get("offset.storage.replication.factor"));
assertEquals("__", aProps.get("replication.policy.separator"));
assertEquals("fake", aProps.get("config.providers"));
Map<String, String> bProps = mirrorConfig.workerConfig(b);
assertEquals("a->b", bProps.get("client.id"));
assertEquals("456", bProps.get("status.storage.replication.factor"));