You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "kfaraz (via GitHub)" <gi...@apache.org> on 2025/08/30 05:51:04 UTC

[PR] Add builders for Kafka supervisor spec, ioConfig, tuningConfig (druid)

kfaraz opened a new pull request, #18460:
URL: https://github.com/apache/druid/pull/18460

   ### Changes
   
   - Add `KafkaSupervisorSpecBuilder`
   - Add `KafkaTuningConfigBuilder`
   - Add `KafkaIOConfigBuilder`
   
   <hr>
   
   This PR has:
   
   - [ ] been self-reviewed.
      - [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] a release note entry in the PR description.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.
   


-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Add builders for Kafka supervisor spec, ioConfig, tuningConfig (druid)

Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #18460:
URL: https://github.com/apache/druid/pull/18460#discussion_r2312203706


##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/indexing/KafkaDataFormatsTest.java:
##########
@@ -581,70 +578,38 @@
         parser,
         new TypeReference<>() {}
     );
-    return new KafkaSupervisorSpec(
-        supervisorId,
-        null,
-        DataSchema.builder()
-                  .withDataSource(dataSource)
-                  .withTimestamp(new TimestampSpec("timestamp", null, null))
-                  .withDimensions(DimensionsSpec.EMPTY)
-                  .withParserMap(parserMap)
-                  .build(),
-        createTuningConfig(),
-        new KafkaSupervisorIOConfig(
-            topic,
-            null,
-            null,
-            null, null,
-            Period.millis(100),
-            kafkaServer.consumerProperties(),
-            null, null, null,
-            Period.millis(10),
-            Period.millis(10),
-            true,
-            null, null, null, null, null, null, null, null
-        ),
-        null, null, null, null, null, null, null, null, null, null, null
-    );
+    return MoreResources.Supervisor.KAFKA_JSON
+        .get()
+        .withDataSchema(
+            schema -> schema
+                .withTimestamp(new TimestampSpec("timestamp", null, null))
+                .withParserMap(parserMap)

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [Builder.withParserMap](1) should be avoided because it has been deprecated.
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/10261)



-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Add builders for Kafka supervisor spec, ioConfig, tuningConfig (druid)

Posted by "capistrant (via GitHub)" <gi...@apache.org>.
capistrant commented on code in PR #18460:
URL: https://github.com/apache/druid/pull/18460#discussion_r2316393077


##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisorSpecBuilder.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.druid.indexing.kafka.supervisor;
+
+import org.apache.druid.segment.indexing.DataSchema;
+
+import java.util.function.Consumer;
+
+/**
+ * Builder for a {@link KafkaSupervisorSpec}, which can be sent over a POST call
+ * to the Overlord.
+ */
+public class KafkaSupervisorSpecBuilder
+{
+  private String id;
+  private final DataSchema.Builder dataSchema = new DataSchema.Builder();
+  private final KafkaIOConfigBuilder ioConfig = new KafkaIOConfigBuilder();
+  private final KafkaTuningConfigBuilder tuningConfig = new KafkaTuningConfigBuilder();
+
+  public KafkaSupervisorSpecBuilder withDataSchema(Consumer<DataSchema.Builder> updateDataSchema)
+  {
+    updateDataSchema.accept(this.dataSchema);
+    return this;
+  }
+
+  public KafkaSupervisorSpecBuilder withTuningConfig(Consumer<KafkaTuningConfigBuilder> updateTuningConfig)
+  {
+    updateTuningConfig.accept(this.tuningConfig);
+    return this;
+  }
+
+  public KafkaSupervisorSpecBuilder withIoConfig(Consumer<KafkaIOConfigBuilder> updateIOConfig)
+  {
+    updateIOConfig.accept(this.ioConfig);
+    return this;
+  }
+
+  public KafkaSupervisorSpecBuilder withId(String id)
+  {
+    this.id = id;
+    return this;
+  }
+
+  /**
+   * Builds a new {@link KafkaSupervisorSpec} with the specified parameters.
+   */
+  public KafkaSupervisorSpec build(String dataSource, String topic)

Review Comment:
   Am I understanding correctly that if you want to use `topicPattern` in the IOConfig, it must have been explicitly set in the underlying IOConfig for this builder? And when doing taht, you then pass null at the call-site?
   
   This feels a bit confusing and requiring insider knowledge. I think at minimum, we should have a `@param` field for topic in the javadoc calling out the case when you want to use topicPattern. But we should also consider the idea of removing `topic` from this method and requiring caller to have handled setting topic/topicPattern in ioConfig. Was it created this way because it made it the most easy to migrate since a vast majority were using topic and only few things use topicPattern?



-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Add builders for Kafka supervisor spec, ioConfig, tuningConfig (druid)

Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #18460:
URL: https://github.com/apache/druid/pull/18460#discussion_r2315157517


##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/indexing/kafka/KafkaSamplerSpecTest.java:
##########
@@ -357,59 +256,24 @@
     );
     InputRowParser parser = new StringInputRowParser(new JSONParseSpec(timestampSpec, dimensionsSpec, JSONPathSpec.DEFAULT, null, null), "UTF8");
 
-    DataSchema dataSchema = DataSchema.builder()
-                                      .withDataSource("test_ds")
-                                      .withParserMap(
-                                          objectMapper.readValue(objectMapper.writeValueAsBytes(parser), Map.class)
-                                      )
-                                      .withAggregators(
-                                          new DoubleSumAggregatorFactory("met1sum", "met1"),
-                                          new CountAggregatorFactory("rows")
-                                      )
-                                      .withGranularity(new UniformGranularitySpec(Granularities.DAY, Granularities.NONE, null))
-                                      .withObjectMapper(objectMapper)
-                                      .build();
-
-    KafkaSupervisorSpec supervisorSpec = new KafkaSupervisorSpec(
-        null,
-        null,
-        dataSchema,
-        null,
-        new KafkaSupervisorIOConfig(
-            TOPIC,
-            null,
-            null,
-            null,
-            null,
-            null,
-            kafkaServer.consumerProperties(),
-            null,
-            null,
-            null,
-            null,
-            null,
-            true,
-            null,
-            null,
-            null,
-            null,
-            null,
-            null,
-            null,
-            false
-        ),
-        null,
-        null,
-        null,
-        null,
-        null,
-        null,
-        null,
-        null,
-        null,
-        null,
-        null
-    );
+    Consumer<DataSchema.Builder> dataSchema =
+        builder -> builder.withDataSource("test_ds")
+                          .withParserMap(objectMapper.convertValue(parser, Map.class))
+                          .withAggregators(
+                              new DoubleSumAggregatorFactory("met1sum", "met1"),
+                              new CountAggregatorFactory("rows")
+                          )
+                          .withGranularity(new UniformGranularitySpec(Granularities.DAY, Granularities.NONE, null))
+                          .withObjectMapper(objectMapper);

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [Builder.withObjectMapper](1) should be avoided because it has been deprecated.
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/10264)



##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/indexing/kafka/KafkaSamplerSpecTest.java:
##########
@@ -357,59 +256,24 @@
     );
     InputRowParser parser = new StringInputRowParser(new JSONParseSpec(timestampSpec, dimensionsSpec, JSONPathSpec.DEFAULT, null, null), "UTF8");
 
-    DataSchema dataSchema = DataSchema.builder()
-                                      .withDataSource("test_ds")
-                                      .withParserMap(
-                                          objectMapper.readValue(objectMapper.writeValueAsBytes(parser), Map.class)
-                                      )
-                                      .withAggregators(
-                                          new DoubleSumAggregatorFactory("met1sum", "met1"),
-                                          new CountAggregatorFactory("rows")
-                                      )
-                                      .withGranularity(new UniformGranularitySpec(Granularities.DAY, Granularities.NONE, null))
-                                      .withObjectMapper(objectMapper)
-                                      .build();
-
-    KafkaSupervisorSpec supervisorSpec = new KafkaSupervisorSpec(
-        null,
-        null,
-        dataSchema,
-        null,
-        new KafkaSupervisorIOConfig(
-            TOPIC,
-            null,
-            null,
-            null,
-            null,
-            null,
-            kafkaServer.consumerProperties(),
-            null,
-            null,
-            null,
-            null,
-            null,
-            true,
-            null,
-            null,
-            null,
-            null,
-            null,
-            null,
-            null,
-            false
-        ),
-        null,
-        null,
-        null,
-        null,
-        null,
-        null,
-        null,
-        null,
-        null,
-        null,
-        null
-    );
+    Consumer<DataSchema.Builder> dataSchema =
+        builder -> builder.withDataSource("test_ds")
+                          .withParserMap(objectMapper.convertValue(parser, Map.class))

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [Builder.withParserMap](1) should be avoided because it has been deprecated.
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/10265)



-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Add builders for Kafka supervisor spec, ioConfig, tuningConfig (druid)

Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #18460:
URL: https://github.com/apache/druid/pull/18460#discussion_r2316405954


##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisorSpecBuilder.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.druid.indexing.kafka.supervisor;
+
+import org.apache.druid.segment.indexing.DataSchema;
+
+import java.util.function.Consumer;
+
+/**
+ * Builder for a {@link KafkaSupervisorSpec}, which can be sent over a POST call
+ * to the Overlord.
+ */
+public class KafkaSupervisorSpecBuilder
+{
+  private String id;
+  private final DataSchema.Builder dataSchema = new DataSchema.Builder();
+  private final KafkaIOConfigBuilder ioConfig = new KafkaIOConfigBuilder();
+  private final KafkaTuningConfigBuilder tuningConfig = new KafkaTuningConfigBuilder();
+
+  public KafkaSupervisorSpecBuilder withDataSchema(Consumer<DataSchema.Builder> updateDataSchema)
+  {
+    updateDataSchema.accept(this.dataSchema);
+    return this;
+  }
+
+  public KafkaSupervisorSpecBuilder withTuningConfig(Consumer<KafkaTuningConfigBuilder> updateTuningConfig)
+  {
+    updateTuningConfig.accept(this.tuningConfig);
+    return this;
+  }
+
+  public KafkaSupervisorSpecBuilder withIoConfig(Consumer<KafkaIOConfigBuilder> updateIOConfig)
+  {
+    updateIOConfig.accept(this.ioConfig);
+    return this;
+  }
+
+  public KafkaSupervisorSpecBuilder withId(String id)
+  {
+    this.id = id;
+    return this;
+  }
+
+  /**
+   * Builds a new {@link KafkaSupervisorSpec} with the specified parameters.
+   */
+  public KafkaSupervisorSpec build(String dataSource, String topic)

Review Comment:
   It happened to be like this since initially I wanted to force callers to provide a topic name but then later realized that `topicPattern` is an option too.



-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Add builders for Kafka supervisor spec, ioConfig, tuningConfig (druid)

Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #18460:
URL: https://github.com/apache/druid/pull/18460#discussion_r2316402053


##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisorSpecBuilder.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.druid.indexing.kafka.supervisor;
+
+import org.apache.druid.segment.indexing.DataSchema;
+
+import java.util.function.Consumer;
+
+/**
+ * Builder for a {@link KafkaSupervisorSpec}, which can be sent over a POST call
+ * to the Overlord.
+ */
+public class KafkaSupervisorSpecBuilder
+{
+  private String id;
+  private final DataSchema.Builder dataSchema = new DataSchema.Builder();
+  private final KafkaIOConfigBuilder ioConfig = new KafkaIOConfigBuilder();
+  private final KafkaTuningConfigBuilder tuningConfig = new KafkaTuningConfigBuilder();
+
+  public KafkaSupervisorSpecBuilder withDataSchema(Consumer<DataSchema.Builder> updateDataSchema)
+  {
+    updateDataSchema.accept(this.dataSchema);
+    return this;
+  }
+
+  public KafkaSupervisorSpecBuilder withTuningConfig(Consumer<KafkaTuningConfigBuilder> updateTuningConfig)
+  {
+    updateTuningConfig.accept(this.tuningConfig);
+    return this;
+  }
+
+  public KafkaSupervisorSpecBuilder withIoConfig(Consumer<KafkaIOConfigBuilder> updateIOConfig)
+  {
+    updateIOConfig.accept(this.ioConfig);
+    return this;
+  }
+
+  public KafkaSupervisorSpecBuilder withId(String id)
+  {
+    this.id = id;
+    return this;
+  }
+
+  /**
+   * Builds a new {@link KafkaSupervisorSpec} with the specified parameters.
+   */
+  public KafkaSupervisorSpec build(String dataSource, String topic)

Review Comment:
   Thanks for calling this out, @capistrant !
   I feel the same, let me fix this up.



-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Add builders for Kafka supervisor spec, ioConfig, tuningConfig (druid)

Posted by "capistrant (via GitHub)" <gi...@apache.org>.
capistrant commented on PR #18460:
URL: https://github.com/apache/druid/pull/18460#issuecomment-3245975150

   > Thanks for the review, @capistrant ! I have added a separate method to the builder : `buildWithTopicPattern`. Please let me know if this helps resolve the ambiguity.
   
   This looks great, thanks for making the change


-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Add builders for Kafka supervisor spec, ioConfig, tuningConfig (druid)

Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on PR #18460:
URL: https://github.com/apache/druid/pull/18460#issuecomment-3245955732

   Thanks for the review, @capistrant !
   I have added a separate method to the builder : `buildWithTopicPattern`.
   Please let me know if this helps resolve the ambiguity.


-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Add builders for Kafka supervisor spec, ioConfig, tuningConfig (druid)

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


-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org