diff --git a/clients/src/main/java/org/apache/kafka/common/utils/Utils.java b/clients/src/main/java/org/apache/kafka/common/utils/Utils.java index f2961a8f282..b23a9d72a4f 100644 --- a/clients/src/main/java/org/apache/kafka/common/utils/Utils.java +++ b/clients/src/main/java/org/apache/kafka/common/utils/Utils.java @@ -1648,9 +1648,24 @@ public final class Utils { * @param the type of values stored in the map */ public static Map entriesWithPrefix(Map 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 the type of values stored in the map + */ + public static Map entriesWithPrefix(Map map, String prefix, boolean strip, boolean allowMatchingLength) { Map result = new HashMap<>(); for (Map.Entry 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 diff --git a/connect/mirror/src/main/java/org/apache/kafka/connect/mirror/MirrorMakerConfig.java b/connect/mirror/src/main/java/org/apache/kafka/connect/mirror/MirrorMakerConfig.java index 8f9f06f058e..014d9767288 100644 --- a/connect/mirror/src/main/java/org/apache/kafka/connect/mirror/MirrorMakerConfig.java +++ b/connect/mirror/src/main/java/org/apache/kafka/connect/mirror/MirrorMakerConfig.java @@ -308,7 +308,7 @@ public class MirrorMakerConfig extends AbstractConfig { } private Map stringsWithPrefix(String prefix) { - return Utils.entriesWithPrefix(rawProperties, prefix, false); + return Utils.entriesWithPrefix(rawProperties, prefix, false, true); } static Map clusterConfigsWithPrefix(String prefix, Map props) { diff --git a/connect/mirror/src/test/java/org/apache/kafka/connect/mirror/MirrorMakerConfigTest.java b/connect/mirror/src/test/java/org/apache/kafka/connect/mirror/MirrorMakerConfigTest.java index 163ebdd4b7b..03f3bd6aaa8 100644 --- a/connect/mirror/src/test/java/org/apache/kafka/connect/mirror/MirrorMakerConfigTest.java +++ b/connect/mirror/src/test/java/org/apache/kafka/connect/mirror/MirrorMakerConfigTest.java @@ -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 bProps = mirrorConfig.workerConfig(b); assertEquals("a->b", bProps.get("client.id")); assertEquals("456", bProps.get("status.storage.replication.factor"));