You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@gobblin.apache.org by "wsarecv (via GitHub)" <gi...@apache.org> on 2023/10/04 18:47:21 UTC

[PR] Add topic validation support in KafkaSource, and TopicNameValidator [gobblin]

wsarecv opened a new pull request, #3793:
URL: https://github.com/apache/gobblin/pull/3793

   Dear Gobblin maintainers,
   
   Please accept this PR. I understand that it will not be reviewed until I have checked off all the steps below!
   
   
   ### JIRA
   - [ ] My PR addresses the following [Gobblin JIRA](https://issues.apache.org/jira/browse/GOBBLIN/) issues and references them in the PR title. For example, "[GOBBLIN-XXX] My Gobblin PR"
       - https://issues.apache.org/jira/browse/GOBBLIN-XXX (To be created due to permission issue)
   
   
   ### Description
   - [ ] Here are some details about my PR, including screenshots (if applicable):
   - Add the topic validation support in `KafkaSource`
   - Add the first validator `TopicNameValidator` into the validator chain, as a refactor of existing codes.
   
   
   ### Tests
   - [ ] My PR adds the following unit tests __OR__ does not need testing for this extremely good reason:
   - Added `TopicValidatorsTest`
   - Enhanced `KafkaSourceTest`
   
   
   ### Commits
   - [ ] My commits all reference JIRA issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)":
       1. Subject is separated from body by a blank line
       2. Subject is limited to 50 characters
       3. Subject does not end with a period
       4. Subject uses the imperative mood ("add", not "adding")
       5. Body wraps at 72 characters
       6. Body explains "what" and "why", not "how"
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@gobblin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GOBBLIN-1927] Add topic validation support in KafkaSource, and add TopicNameValidator [gobblin]

Posted by "ZihanLi58 (via GitHub)" <gi...@apache.org>.
ZihanLi58 merged PR #3793:
URL: https://github.com/apache/gobblin/pull/3793


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@gobblin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GOBBLIN-1927] Add topic validation support in KafkaSource, and TopicNameValidator [gobblin]

Posted by "ZihanLi58 (via GitHub)" <gi...@apache.org>.
ZihanLi58 commented on PR #3793:
URL: https://github.com/apache/gobblin/pull/3793#issuecomment-1758342542

   LGTM after you addressing all the above comments


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@gobblin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GOBBLIN-1927] Add topic validation support in KafkaSource, and add TopicNameValidator [gobblin]

Posted by "wsarecv (via GitHub)" <gi...@apache.org>.
wsarecv commented on code in PR #3793:
URL: https://github.com/apache/gobblin/pull/3793#discussion_r1357845239


##########
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/validator/TopicValidators.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.gobblin.source.extractor.extract.kafka.validator;
+
+import com.google.common.base.Strings;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.gobblin.configuration.SourceState;
+import org.apache.gobblin.source.extractor.extract.kafka.KafkaTopic;
+import org.apache.gobblin.util.reflection.GobblinConstructorUtils;
+
+/**
+ * The TopicValidators contains a list of {@link TopicValidatorBase} that validate topics.
+ * To enable it, add below settings in the config:
+ *   gobblin.kafka.topicValidators=validator1_class_name,validator2_class_name...
+ */
+@Slf4j
+public class TopicValidators {
+  public static final String VALIDATOR_CLASSES_KEY = "gobblin.kafka.topicValidators";
+
+  public static final String VALIDATOR_CLASS_DELIMITER = ",";
+
+  private final List<TopicValidatorBase> validators = new ArrayList<>();
+
+  public TopicValidators(SourceState state) {
+    String validatorClasses = state.getProp(VALIDATOR_CLASSES_KEY);
+    if (Strings.isNullOrEmpty(validatorClasses)) {
+      return;
+    }
+
+    String[] validatorClassNames = validatorClasses.split(VALIDATOR_CLASS_DELIMITER);

Review Comment:
   Fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@gobblin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GOBBLIN-1927] Add topic validation support in KafkaSource, and add TopicNameValidator [gobblin]

Posted by "wsarecv (via GitHub)" <gi...@apache.org>.
wsarecv commented on code in PR #3793:
URL: https://github.com/apache/gobblin/pull/3793#discussion_r1355794417


##########
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/validator/TopicValidators.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.gobblin.source.extractor.extract.kafka.validator;
+
+import com.google.common.base.Strings;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.gobblin.configuration.SourceState;
+import org.apache.gobblin.source.extractor.extract.kafka.KafkaTopic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The TopicValidators contains a list of {@link TopicValidatorBase} that validate topics.
+ * To enable it, add below settings in the config:
+ *   gobblin.kafka.topicValidators=validator1_class_name;validator2_class_name...
+ */
+public class TopicValidators {
+  public static final String VALIDATOR_CLASSES_KEY = "gobblin.kafka.topicValidators";
+
+  public static final String VALIDATOR_CLASS_DELIMITER = ";";
+  private static final Logger LOGGER = LoggerFactory.getLogger(TopicValidators.class);
+
+  private final List<TopicValidatorBase> validators = new ArrayList<>();
+
+  public TopicValidators(SourceState state) {
+    String validatorClasses = state.getProp(VALIDATOR_CLASSES_KEY);
+    if (Strings.isNullOrEmpty(validatorClasses)) {
+      return;
+    }
+
+    String[] validatorClassNames = validatorClasses.split(VALIDATOR_CLASS_DELIMITER);
+    Arrays.stream(validatorClassNames).forEach(validator -> {
+      try {
+        this.validators.add(
+            (TopicValidatorBase) Class.forName(validator).getConstructor(SourceState.class).newInstance(state));
+      } catch (Exception e) {
+        LOGGER.error("Failed to create topic validator: {}, due to {}", validator, e);
+      }
+    });
+  }
+
+  /**
+   * Validate topics with all the internal validators.
+   * Note: the validations for every topic run in parallel.
+   * @param topics the topics to be validated
+   * @return the topics that pass all the validators
+   */
+  public List<KafkaTopic> validate(List<KafkaTopic> topics) {
+    // Validate the topics in parallel
+    return topics.parallelStream()

Review Comment:
   Thanks for the reference of that PR.
   
   Yes, the parallelism is on purpose. Some validator could be slow, validating the topics sequentially would significantly slow down the startup.
   
   For example, there will be [another PR to add an OrcSchemaConversionValidator](https://github.com/apache/gobblin/pull/3794/files#diff-c480e84c1e7ab69ed31e521c5615de4b270ce6da72333a29ec779b47f04e3d0aR45-R48) that queries the remote schema registry for every topic.
   
   If the `parallelStream` is not recommended, we would have to do it in a separate thread pool while trying to avoid the context class loader issue. Any comment on this approach?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@gobblin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GOBBLIN-1927] Add topic validation support in KafkaSource, and TopicNameValidator [gobblin]

Posted by "wsarecv (via GitHub)" <gi...@apache.org>.
wsarecv commented on code in PR #3793:
URL: https://github.com/apache/gobblin/pull/3793#discussion_r1355794417


##########
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/validator/TopicValidators.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.gobblin.source.extractor.extract.kafka.validator;
+
+import com.google.common.base.Strings;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.gobblin.configuration.SourceState;
+import org.apache.gobblin.source.extractor.extract.kafka.KafkaTopic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The TopicValidators contains a list of {@link TopicValidatorBase} that validate topics.
+ * To enable it, add below settings in the config:
+ *   gobblin.kafka.topicValidators=validator1_class_name;validator2_class_name...
+ */
+public class TopicValidators {
+  public static final String VALIDATOR_CLASSES_KEY = "gobblin.kafka.topicValidators";
+
+  public static final String VALIDATOR_CLASS_DELIMITER = ";";
+  private static final Logger LOGGER = LoggerFactory.getLogger(TopicValidators.class);
+
+  private final List<TopicValidatorBase> validators = new ArrayList<>();
+
+  public TopicValidators(SourceState state) {
+    String validatorClasses = state.getProp(VALIDATOR_CLASSES_KEY);
+    if (Strings.isNullOrEmpty(validatorClasses)) {
+      return;
+    }
+
+    String[] validatorClassNames = validatorClasses.split(VALIDATOR_CLASS_DELIMITER);
+    Arrays.stream(validatorClassNames).forEach(validator -> {
+      try {
+        this.validators.add(
+            (TopicValidatorBase) Class.forName(validator).getConstructor(SourceState.class).newInstance(state));
+      } catch (Exception e) {
+        LOGGER.error("Failed to create topic validator: {}, due to {}", validator, e);
+      }
+    });
+  }
+
+  /**
+   * Validate topics with all the internal validators.
+   * Note: the validations for every topic run in parallel.
+   * @param topics the topics to be validated
+   * @return the topics that pass all the validators
+   */
+  public List<KafkaTopic> validate(List<KafkaTopic> topics) {
+    // Validate the topics in parallel
+    return topics.parallelStream()

Review Comment:
   Thanks for the reference of that PR.
   
   Yes, the parallelism is on purpose. Some validator could be slow, validating the topics sequentially would significantly slow down the startup.
   
   For example, there will be [another PR to add an OrcSchemaConversionValidator](https://github.com/apache/gobblin/pull/3794/files#diff-c480e84c1e7ab69ed31e521c5615de4b270ce6da72333a29ec779b47f04e3d0aR45-R48) that queries the remote schema registry for every topic.
   
   If the `parallelStream` is not suggested, we would have to do it in a separate thread pool while trying to avoid the context class loader issue. Any comment on this approach?



##########
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/validator/TopicValidators.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.gobblin.source.extractor.extract.kafka.validator;
+
+import com.google.common.base.Strings;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.gobblin.configuration.SourceState;
+import org.apache.gobblin.source.extractor.extract.kafka.KafkaTopic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The TopicValidators contains a list of {@link TopicValidatorBase} that validate topics.
+ * To enable it, add below settings in the config:
+ *   gobblin.kafka.topicValidators=validator1_class_name;validator2_class_name...
+ */
+public class TopicValidators {
+  public static final String VALIDATOR_CLASSES_KEY = "gobblin.kafka.topicValidators";
+
+  public static final String VALIDATOR_CLASS_DELIMITER = ";";

Review Comment:
   Fixed.



##########
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/validator/TopicValidators.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.gobblin.source.extractor.extract.kafka.validator;
+
+import com.google.common.base.Strings;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.gobblin.configuration.SourceState;
+import org.apache.gobblin.source.extractor.extract.kafka.KafkaTopic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The TopicValidators contains a list of {@link TopicValidatorBase} that validate topics.
+ * To enable it, add below settings in the config:
+ *   gobblin.kafka.topicValidators=validator1_class_name;validator2_class_name...
+ */
+public class TopicValidators {
+  public static final String VALIDATOR_CLASSES_KEY = "gobblin.kafka.topicValidators";
+
+  public static final String VALIDATOR_CLASS_DELIMITER = ";";
+  private static final Logger LOGGER = LoggerFactory.getLogger(TopicValidators.class);

Review Comment:
   Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@gobblin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GOBBLIN-1927] Add topic validation support in KafkaSource, and TopicNameValidator [gobblin]

Posted by "wsarecv (via GitHub)" <gi...@apache.org>.
wsarecv commented on code in PR #3793:
URL: https://github.com/apache/gobblin/pull/3793#discussion_r1355794616


##########
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/validator/TopicValidators.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.gobblin.source.extractor.extract.kafka.validator;
+
+import com.google.common.base.Strings;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.gobblin.configuration.SourceState;
+import org.apache.gobblin.source.extractor.extract.kafka.KafkaTopic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The TopicValidators contains a list of {@link TopicValidatorBase} that validate topics.
+ * To enable it, add below settings in the config:
+ *   gobblin.kafka.topicValidators=validator1_class_name;validator2_class_name...
+ */
+public class TopicValidators {
+  public static final String VALIDATOR_CLASSES_KEY = "gobblin.kafka.topicValidators";
+
+  public static final String VALIDATOR_CLASS_DELIMITER = ";";
+  private static final Logger LOGGER = LoggerFactory.getLogger(TopicValidators.class);
+
+  private final List<TopicValidatorBase> validators = new ArrayList<>();
+
+  public TopicValidators(SourceState state) {
+    String validatorClasses = state.getProp(VALIDATOR_CLASSES_KEY);
+    if (Strings.isNullOrEmpty(validatorClasses)) {
+      return;
+    }
+
+    String[] validatorClassNames = validatorClasses.split(VALIDATOR_CLASS_DELIMITER);
+    Arrays.stream(validatorClassNames).forEach(validator -> {
+      try {
+        this.validators.add(

Review Comment:
   Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@gobblin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GOBBLIN-1927] Add topic validation support in KafkaSource, and add TopicNameValidator [gobblin]

Posted by "ZihanLi58 (via GitHub)" <gi...@apache.org>.
ZihanLi58 commented on code in PR #3793:
URL: https://github.com/apache/gobblin/pull/3793#discussion_r1357723230


##########
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/validator/TopicValidators.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.gobblin.source.extractor.extract.kafka.validator;
+
+import com.google.common.base.Strings;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.gobblin.configuration.SourceState;
+import org.apache.gobblin.source.extractor.extract.kafka.KafkaTopic;
+import org.apache.gobblin.util.reflection.GobblinConstructorUtils;
+
+/**
+ * The TopicValidators contains a list of {@link TopicValidatorBase} that validate topics.
+ * To enable it, add below settings in the config:
+ *   gobblin.kafka.topicValidators=validator1_class_name,validator2_class_name...
+ */
+@Slf4j
+public class TopicValidators {
+  public static final String VALIDATOR_CLASSES_KEY = "gobblin.kafka.topicValidators";
+
+  public static final String VALIDATOR_CLASS_DELIMITER = ",";
+
+  private final List<TopicValidatorBase> validators = new ArrayList<>();
+
+  public TopicValidators(SourceState state) {
+    String validatorClasses = state.getProp(VALIDATOR_CLASSES_KEY);
+    if (Strings.isNullOrEmpty(validatorClasses)) {
+      return;
+    }
+
+    String[] validatorClassNames = validatorClasses.split(VALIDATOR_CLASS_DELIMITER);

Review Comment:
   you should be able to use state.getPropAsList?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@gobblin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GOBBLIN-1927] Add topic validation support in KafkaSource, and add TopicNameValidator [gobblin]

Posted by "wsarecv (via GitHub)" <gi...@apache.org>.
wsarecv commented on code in PR #3793:
URL: https://github.com/apache/gobblin/pull/3793#discussion_r1359177739


##########
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/validator/TopicValidators.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.gobblin.source.extractor.extract.kafka.validator;
+
+import com.google.common.base.Strings;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.gobblin.configuration.SourceState;
+import org.apache.gobblin.source.extractor.extract.kafka.KafkaTopic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The TopicValidators contains a list of {@link TopicValidatorBase} that validate topics.
+ * To enable it, add below settings in the config:
+ *   gobblin.kafka.topicValidators=validator1_class_name;validator2_class_name...
+ */
+public class TopicValidators {
+  public static final String VALIDATOR_CLASSES_KEY = "gobblin.kafka.topicValidators";
+
+  public static final String VALIDATOR_CLASS_DELIMITER = ";";
+  private static final Logger LOGGER = LoggerFactory.getLogger(TopicValidators.class);
+
+  private final List<TopicValidatorBase> validators = new ArrayList<>();
+
+  public TopicValidators(SourceState state) {
+    String validatorClasses = state.getProp(VALIDATOR_CLASSES_KEY);
+    if (Strings.isNullOrEmpty(validatorClasses)) {
+      return;
+    }
+
+    String[] validatorClassNames = validatorClasses.split(VALIDATOR_CLASS_DELIMITER);
+    Arrays.stream(validatorClassNames).forEach(validator -> {
+      try {
+        this.validators.add(
+            (TopicValidatorBase) Class.forName(validator).getConstructor(SourceState.class).newInstance(state));
+      } catch (Exception e) {
+        LOGGER.error("Failed to create topic validator: {}, due to {}", validator, e);
+      }
+    });
+  }
+
+  /**
+   * Validate topics with all the internal validators.
+   * Note: the validations for every topic run in parallel.
+   * @param topics the topics to be validated
+   * @return the topics that pass all the validators
+   */
+  public List<KafkaTopic> validate(List<KafkaTopic> topics) {
+    // Validate the topics in parallel
+    return topics.parallelStream()

Review Comment:
   Ideally, the data from a bad topic should not come to the incremental compaction stage, because:
   1. With static validators, `KafkaSource` can skip the bad topics during the work unit creation.
   2. With dynamic validators, bad topics are detected on the fly and then FastIngest can be restarted to skip those bad topics.
   
   However, the incremental compaction may potentially use a different set of validators, so it still make sense to provide the validation support beyond FastIngest. So let's go for it.
   
   To set the context class loader correctly, in the new iteration the `ExecutorsUtils` is enhanced to help create thread pools where the running tasks can have the same access control and class loader settings as the thread that submits the tasks. Please help take a look.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@gobblin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GOBBLIN-1927] Add topic validation support in KafkaSource, and add TopicNameValidator [gobblin]

Posted by "homatthew (via GitHub)" <gi...@apache.org>.
homatthew commented on code in PR #3793:
URL: https://github.com/apache/gobblin/pull/3793#discussion_r1358329115


##########
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/validator/TopicValidators.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.gobblin.source.extractor.extract.kafka.validator;
+
+import com.google.common.base.Strings;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.gobblin.configuration.SourceState;
+import org.apache.gobblin.source.extractor.extract.kafka.KafkaTopic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The TopicValidators contains a list of {@link TopicValidatorBase} that validate topics.
+ * To enable it, add below settings in the config:
+ *   gobblin.kafka.topicValidators=validator1_class_name;validator2_class_name...
+ */
+public class TopicValidators {
+  public static final String VALIDATOR_CLASSES_KEY = "gobblin.kafka.topicValidators";
+
+  public static final String VALIDATOR_CLASS_DELIMITER = ";";
+  private static final Logger LOGGER = LoggerFactory.getLogger(TopicValidators.class);
+
+  private final List<TopicValidatorBase> validators = new ArrayList<>();
+
+  public TopicValidators(SourceState state) {
+    String validatorClasses = state.getProp(VALIDATOR_CLASSES_KEY);
+    if (Strings.isNullOrEmpty(validatorClasses)) {
+      return;
+    }
+
+    String[] validatorClassNames = validatorClasses.split(VALIDATOR_CLASS_DELIMITER);
+    Arrays.stream(validatorClassNames).forEach(validator -> {
+      try {
+        this.validators.add(
+            (TopicValidatorBase) Class.forName(validator).getConstructor(SourceState.class).newInstance(state));
+      } catch (Exception e) {
+        LOGGER.error("Failed to create topic validator: {}, due to {}", validator, e);
+      }
+    });
+  }
+
+  /**
+   * Validate topics with all the internal validators.
+   * Note: the validations for every topic run in parallel.
+   * @param topics the topics to be validated
+   * @return the topics that pass all the validators
+   */
+  public List<KafkaTopic> validate(List<KafkaTopic> topics) {
+    // Validate the topics in parallel
+    return topics.parallelStream()

Review Comment:
   Do we intend to keep this code limited to Kafka source? i.e. do we see a world where we'd want to use this topic validation in incremental?..
   
   If we do see spark uses cases, could we look into the following comment from that PR that describes an alternative approach that would set the appropriate class loader? This sort of topic validation could make sense since Iceberg does not support some of our weird edge cases (e.g. non optional union schema)
   
   https://github.com/apache/gobblin/pull/3706#issuecomment-1596241791
   
   JFYI, in compaction we do have a similar validation step at the dataset finder level (and the PR I linked previously is a bug fix for that feature). If the intention is to use this topic validation across the board you can consider whether it makes sense to converge these code paths.  
   - https://github.com/apache/gobblin/pull/3632
   - https://github.com/apache/gobblin/pull/3648
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@gobblin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GOBBLIN-1927] Add topic validation support in KafkaSource, and TopicNameValidator [gobblin]

Posted by "homatthew (via GitHub)" <gi...@apache.org>.
homatthew commented on code in PR #3793:
URL: https://github.com/apache/gobblin/pull/3793#discussion_r1355089187


##########
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/validator/TopicValidators.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.gobblin.source.extractor.extract.kafka.validator;
+
+import com.google.common.base.Strings;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.gobblin.configuration.SourceState;
+import org.apache.gobblin.source.extractor.extract.kafka.KafkaTopic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The TopicValidators contains a list of {@link TopicValidatorBase} that validate topics.
+ * To enable it, add below settings in the config:
+ *   gobblin.kafka.topicValidators=validator1_class_name;validator2_class_name...
+ */
+public class TopicValidators {
+  public static final String VALIDATOR_CLASSES_KEY = "gobblin.kafka.topicValidators";
+
+  public static final String VALIDATOR_CLASS_DELIMITER = ";";

Review Comment:
   Normally we delimit with a comma for splitting class names (or really any config).



##########
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/validator/TopicValidators.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.gobblin.source.extractor.extract.kafka.validator;
+
+import com.google.common.base.Strings;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.gobblin.configuration.SourceState;
+import org.apache.gobblin.source.extractor.extract.kafka.KafkaTopic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The TopicValidators contains a list of {@link TopicValidatorBase} that validate topics.
+ * To enable it, add below settings in the config:
+ *   gobblin.kafka.topicValidators=validator1_class_name;validator2_class_name...
+ */
+public class TopicValidators {
+  public static final String VALIDATOR_CLASSES_KEY = "gobblin.kafka.topicValidators";
+
+  public static final String VALIDATOR_CLASS_DELIMITER = ";";
+  private static final Logger LOGGER = LoggerFactory.getLogger(TopicValidators.class);
+
+  private final List<TopicValidatorBase> validators = new ArrayList<>();
+
+  public TopicValidators(SourceState state) {
+    String validatorClasses = state.getProp(VALIDATOR_CLASSES_KEY);
+    if (Strings.isNullOrEmpty(validatorClasses)) {
+      return;
+    }
+
+    String[] validatorClassNames = validatorClasses.split(VALIDATOR_CLASS_DELIMITER);
+    Arrays.stream(validatorClassNames).forEach(validator -> {
+      try {
+        this.validators.add(
+            (TopicValidatorBase) Class.forName(validator).getConstructor(SourceState.class).newInstance(state));
+      } catch (Exception e) {
+        LOGGER.error("Failed to create topic validator: {}, due to {}", validator, e);
+      }
+    });
+  }
+
+  /**
+   * Validate topics with all the internal validators.
+   * Note: the validations for every topic run in parallel.
+   * @param topics the topics to be validated
+   * @return the topics that pass all the validators
+   */
+  public List<KafkaTopic> validate(List<KafkaTopic> topics) {
+    // Validate the topics in parallel
+    return topics.parallelStream()

Review Comment:
   Not that I think this class will be used within Incremental Compute, but just FYI, we have seen in the past where parallelStream has caused some strange bugs related to not picking up dependencies in Spark. In general, I'd suggest always thinking about whether the parallelism is important given that the api has caused issue in the past.
   
   https://github.com/apache/gobblin/pull/3706



##########
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/validator/TopicValidators.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.gobblin.source.extractor.extract.kafka.validator;
+
+import com.google.common.base.Strings;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.gobblin.configuration.SourceState;
+import org.apache.gobblin.source.extractor.extract.kafka.KafkaTopic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The TopicValidators contains a list of {@link TopicValidatorBase} that validate topics.
+ * To enable it, add below settings in the config:
+ *   gobblin.kafka.topicValidators=validator1_class_name;validator2_class_name...
+ */
+public class TopicValidators {
+  public static final String VALIDATOR_CLASSES_KEY = "gobblin.kafka.topicValidators";
+
+  public static final String VALIDATOR_CLASS_DELIMITER = ";";
+  private static final Logger LOGGER = LoggerFactory.getLogger(TopicValidators.class);

Review Comment:
   Most classes use @slf4j annotation, which creates a `log` object for you.



##########
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/source/extractor/extract/kafka/validator/TopicValidators.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.gobblin.source.extractor.extract.kafka.validator;
+
+import com.google.common.base.Strings;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.gobblin.configuration.SourceState;
+import org.apache.gobblin.source.extractor.extract.kafka.KafkaTopic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The TopicValidators contains a list of {@link TopicValidatorBase} that validate topics.
+ * To enable it, add below settings in the config:
+ *   gobblin.kafka.topicValidators=validator1_class_name;validator2_class_name...
+ */
+public class TopicValidators {
+  public static final String VALIDATOR_CLASSES_KEY = "gobblin.kafka.topicValidators";
+
+  public static final String VALIDATOR_CLASS_DELIMITER = ";";
+  private static final Logger LOGGER = LoggerFactory.getLogger(TopicValidators.class);
+
+  private final List<TopicValidatorBase> validators = new ArrayList<>();
+
+  public TopicValidators(SourceState state) {
+    String validatorClasses = state.getProp(VALIDATOR_CLASSES_KEY);
+    if (Strings.isNullOrEmpty(validatorClasses)) {
+      return;
+    }
+
+    String[] validatorClassNames = validatorClasses.split(VALIDATOR_CLASS_DELIMITER);
+    Arrays.stream(validatorClassNames).forEach(validator -> {
+      try {
+        this.validators.add(

Review Comment:
   Any particular reason we don't use the GobblinConstructorUtils here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@gobblin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add topic validation support in KafkaSource, and TopicNameValidator [gobblin]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3793:
URL: https://github.com/apache/gobblin/pull/3793#issuecomment-1749748329

   ## [Codecov](https://app.codecov.io/gh/apache/gobblin/pull/3793?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > Merging [#3793](https://app.codecov.io/gh/apache/gobblin/pull/3793?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (59560f5) into [master](https://app.codecov.io/gh/apache/gobblin/commit/028b85f587e3c1e6afa5d8662fe9ed3f0087568d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (028b85f) will **decrease** coverage by `1.18%`.
   > Report is 2 commits behind head on master.
   > The diff coverage is `n/a`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #3793      +/-   ##
   ============================================
   - Coverage     47.32%   46.14%   -1.18%     
   + Complexity    10955     2181    -8774     
   ============================================
     Files          2152      416    -1736     
     Lines         85114    17965   -67149     
     Branches       9451     2191    -7260     
   ============================================
   - Hits          40279     8290   -31989     
   + Misses        41184     8791   -32393     
   + Partials       3651      884    -2767     
   ```
   
   
   [see 1743 files with indirect coverage changes](https://app.codecov.io/gh/apache/gobblin/pull/3793/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@gobblin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org