-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-5295: Allow source connectors to specify topic-specific settings for new topics (KIP-158) #8722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
KAFKA-5295: Allow source connectors to specify topic-specific settings for new topics (KIP-158) #8722
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
5d3ca71
KAFKA-5295: Add tests first
kkonstantine 1bab224
KAFKA-5295: Add configuration for topic creation by source connectors
kkonstantine cff6302
KAFKA-5295: Adjust tests to new source connector configs
kkonstantine bf250eb
KAFKA-5295: Implement topic creation by tasks based on configuration …
kkonstantine 11d9e64
KAFKA-5295: Adapt existing tests
kkonstantine 3e25d6d
KAFKA-5295: Adapt existing integration tests
kkonstantine 05b48eb
KAFKA-5295: Adjust checkstyle
kkonstantine 91b6d4e
KAFKA-5295: Tests with topic creation enabled
kkonstantine 435ca34
KAFKA-5295: New tests
kkonstantine 800a40f
KAFKA-5295: Keep connectors that don't use topic creation unaffected
kkonstantine 1e98c70
KAFKA-5295: Upgrade integration test
kkonstantine f58be22
KAFKA-5295: Minor cleanup
kkonstantine 958cbe5
KAFKA-5295: Remove redundant code
kkonstantine 0f90de4
KAFKA-5295: Maximize coverage for WorkerSourceTask
kkonstantine 4840a6b
KAFKA-5295: Unit tests for SourceConnectorConfig
kkonstantine 98f7376
KAFKA-5295: Address Randall's comments
kkonstantine d5b6d26
KAFKA-5295: Adapt tests after the changes of KAFKA-4794/KIP-131
kkonstantine 9fa3e09
Fix doc in WorkerConfig
kkonstantine e73395b
KAFKA-5295: Set the id for the admin client used by the DLQ
kkonstantine 645e2b2
KAFKA-5295: Refactor TopicCreation under the util package
kkonstantine b8da7c5
KAFKA-5295: Refactor TopicCreationGroup under its own class in util p…
kkonstantine a880d6e
KAFKA-5295: Add isTopicCreationRequired and addTopic in TopicCreation…
kkonstantine 79fdf99
KAFKA-5295: Refactor and add TopicCreation unit tests
kkonstantine f57a9d6
Update REPLICATION_FACTOR_DOC
kkonstantine e61a8a4
Apply doc suggestions from code review
kkonstantine 540cd0c
KAFKA-5295: Address minor comments from code review
kkonstantine 83ac913
KAFKA-5295: Fix build and last minor typos
kkonstantine 9850535
KAFKA-5295: Fix test after change in validation error
kkonstantine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
140 changes: 140 additions & 0 deletions
140
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/TopicCreationConfig.java
This file contains hidden or 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,140 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.connect.runtime; | ||
|
|
||
| import org.apache.kafka.common.config.ConfigDef; | ||
| import org.apache.kafka.common.config.ConfigException; | ||
| import org.apache.kafka.connect.util.TopicAdmin; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.regex.Pattern; | ||
| import java.util.regex.PatternSyntaxException; | ||
|
|
||
| public class TopicCreationConfig { | ||
|
|
||
| public static final String DEFAULT_TOPIC_CREATION_PREFIX = "topic.creation.default."; | ||
| public static final String DEFAULT_TOPIC_CREATION_GROUP = "default"; | ||
|
|
||
| public static final String INCLUDE_REGEX_CONFIG = "include"; | ||
| private static final String INCLUDE_REGEX_DOC = "A list of strings that represent regular " | ||
| + "expressions that may match topic names. This list is used to include topics that " | ||
| + "match their values and apply this group's specific configuration to the topics " | ||
| + "that match this inclusion list."; | ||
|
kkonstantine marked this conversation as resolved.
Outdated
|
||
|
|
||
| public static final String EXCLUDE_REGEX_CONFIG = "exclude"; | ||
| private static final String EXCLUDE_REGEX_DOC = "A list of strings that represent regular " | ||
| + "expressions that may match topic names. This list is used to exclude topics that " | ||
| + "match their values and refrain from applying this group's specific configuration " | ||
| + "to the topics that match this exclusion list. Note that exclusion rules have " | ||
| + "precedent and override any inclusion rules for topics. "; | ||
|
kkonstantine marked this conversation as resolved.
Outdated
|
||
|
|
||
| public static final String REPLICATION_FACTOR_CONFIG = "replication.factor"; | ||
| private static final String REPLICATION_FACTOR_DOC = "The replication factor for new topics " | ||
| + "created for this connector. This value must not be larger than the number of " | ||
| + "brokers in the Kafka cluster, or otherwise an error will be thrown when the " | ||
| + "connector will attempt to create a topic. For the default group this configuration" | ||
| + " is required. For any other group defined in topic.creation.groups this config is " | ||
| + "optional and if it's missing it gets the value the default group"; | ||
|
kkonstantine marked this conversation as resolved.
Outdated
|
||
|
|
||
| public static final String PARTITIONS_CONFIG = "partitions"; | ||
| private static final String PARTITIONS_DOC = "The number of partitions new topics created for" | ||
| + " this connector. For the default group this configuration is required. For any " | ||
| + "other group defined in topic.creation.groups this config is optional and if it's " | ||
| + "missing it gets the value the default group"; | ||
|
kkonstantine marked this conversation as resolved.
Outdated
|
||
|
|
||
| public static final ConfigDef.Validator REPLICATION_FACTOR_VALIDATOR = ConfigDef.LambdaValidator.with( | ||
| (name, value) -> validateReplicationFactor(name, (short) value), | ||
| () -> "Positive number, or -1 to use the broker's default" | ||
|
kkonstantine marked this conversation as resolved.
Outdated
|
||
| ); | ||
| public static final ConfigDef.Validator PARTITIONS_VALIDATOR = ConfigDef.LambdaValidator.with( | ||
| (name, value) -> validatePartitions(name, (int) value), | ||
| () -> "Positive number, or -1 to use the broker's default" | ||
| ); | ||
| @SuppressWarnings("unchecked") | ||
| public static final ConfigDef.Validator REGEX_VALIDATOR = ConfigDef.LambdaValidator.with( | ||
| (name, value) -> { | ||
| try { | ||
| ((List<String>) value).forEach(Pattern::compile); | ||
| } catch (PatternSyntaxException e) { | ||
| throw new ConfigException(name, value, "Syntax error in regular expression"); | ||
|
rhauch marked this conversation as resolved.
Outdated
|
||
| } | ||
| }, | ||
| () -> "Positive number, or -1 to use the broker's default" | ||
| ); | ||
|
|
||
| private static void validatePartitions(String configName, int factor) { | ||
| if (factor != TopicAdmin.NO_PARTITIONS && factor < 1) { | ||
| throw new ConfigException(configName, factor, | ||
| "Number of partitions must be positive, or -1 to use the broker's default"); | ||
| } | ||
| } | ||
|
|
||
| private static void validateReplicationFactor(String configName, short factor) { | ||
| if (factor != TopicAdmin.NO_REPLICATION_FACTOR && factor < 1) { | ||
| throw new ConfigException(configName, factor, | ||
| "Replication factor must be positive, or -1 to use the broker's default"); | ||
|
kkonstantine marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
| public static ConfigDef configDef(String group, short defaultReplicationFactor, int defaultParitionCount) { | ||
| int orderInGroup = 0; | ||
| ConfigDef configDef = new ConfigDef(); | ||
| configDef | ||
| .define(INCLUDE_REGEX_CONFIG, ConfigDef.Type.LIST, Collections.emptyList(), | ||
| REGEX_VALIDATOR, ConfigDef.Importance.LOW, | ||
| INCLUDE_REGEX_DOC, group, ++orderInGroup, ConfigDef.Width.LONG, | ||
| "Inclusion Topic Pattern for " + group) | ||
| .define(EXCLUDE_REGEX_CONFIG, ConfigDef.Type.LIST, Collections.emptyList(), | ||
| REGEX_VALIDATOR, ConfigDef.Importance.LOW, | ||
| EXCLUDE_REGEX_DOC, group, ++orderInGroup, ConfigDef.Width.LONG, | ||
| "Exclusion Topic Pattern for " + group) | ||
| .define(REPLICATION_FACTOR_CONFIG, ConfigDef.Type.SHORT, | ||
| defaultReplicationFactor, REPLICATION_FACTOR_VALIDATOR, | ||
| ConfigDef.Importance.LOW, REPLICATION_FACTOR_DOC, group, ++orderInGroup, | ||
| ConfigDef.Width.LONG, "Replication Factor for Topics in " + group) | ||
| .define(PARTITIONS_CONFIG, ConfigDef.Type.INT, | ||
| defaultParitionCount, PARTITIONS_VALIDATOR, | ||
| ConfigDef.Importance.LOW, PARTITIONS_DOC, group, ++orderInGroup, | ||
| ConfigDef.Width.LONG, "Partition Count for Topics in " + group); | ||
| return configDef; | ||
| } | ||
|
|
||
| public static ConfigDef defaultGroupConfigDef() { | ||
| int orderInGroup = 0; | ||
| ConfigDef configDef = new ConfigDef(); | ||
| configDef | ||
| .define(INCLUDE_REGEX_CONFIG, ConfigDef.Type.LIST, ".*", | ||
| new ConfigDef.NonNullValidator(), ConfigDef.Importance.LOW, | ||
| INCLUDE_REGEX_DOC, DEFAULT_TOPIC_CREATION_GROUP, ++orderInGroup, ConfigDef.Width.LONG, | ||
| "Inclusion Topic Pattern for " + DEFAULT_TOPIC_CREATION_GROUP) | ||
| .define(EXCLUDE_REGEX_CONFIG, ConfigDef.Type.LIST, Collections.emptyList(), | ||
| new ConfigDef.NonNullValidator(), ConfigDef.Importance.LOW, | ||
| EXCLUDE_REGEX_DOC, DEFAULT_TOPIC_CREATION_GROUP, ++orderInGroup, ConfigDef.Width.LONG, | ||
| "Exclusion Topic Pattern for " + DEFAULT_TOPIC_CREATION_GROUP) | ||
| .define(REPLICATION_FACTOR_CONFIG, ConfigDef.Type.SHORT, | ||
| ConfigDef.NO_DEFAULT_VALUE, REPLICATION_FACTOR_VALIDATOR, | ||
| ConfigDef.Importance.LOW, REPLICATION_FACTOR_DOC, DEFAULT_TOPIC_CREATION_GROUP, ++orderInGroup, | ||
| ConfigDef.Width.LONG, "Replication Factor for Topics in " + DEFAULT_TOPIC_CREATION_GROUP) | ||
| .define(PARTITIONS_CONFIG, ConfigDef.Type.INT, | ||
| ConfigDef.NO_DEFAULT_VALUE, PARTITIONS_VALIDATOR, | ||
| ConfigDef.Importance.LOW, PARTITIONS_DOC, DEFAULT_TOPIC_CREATION_GROUP, ++orderInGroup, | ||
| ConfigDef.Width.LONG, "Partition Count for Topics in " + DEFAULT_TOPIC_CREATION_GROUP); | ||
| return configDef; | ||
| } | ||
|
rhauch marked this conversation as resolved.
|
||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.