cryptoe commented on code in PR #18525:
URL: https://github.com/apache/druid/pull/18525#discussion_r2448040730


##########
extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/KafkaRecordSupplier.java:
##########
@@ -172,16 +198,35 @@ public Set<StreamPartition<KafkaTopicPartition>> 
getAssignment()
   public List<OrderedPartitionableRecord<KafkaTopicPartition, Long, 
KafkaRecordEntity>> poll(long timeout)
   {
     List<OrderedPartitionableRecord<KafkaTopicPartition, Long, 
KafkaRecordEntity>> polledRecords = new ArrayList<>();
+
     for (ConsumerRecord<byte[], byte[]> record : 
consumer.poll(Duration.ofMillis(timeout))) {
+      KafkaTopicPartition kafkaPartition = new KafkaTopicPartition(multiTopic, 
record.topic(), record.partition());
+
+      // Apply header filter if configured
+      if (headerFilterEvaluator != null && 
!headerFilterEvaluator.shouldIncludeRecord(record)) {
+        // Create filtered record for offset advancement with filtered=true 
flag
+        polledRecords.add(new OrderedPartitionableRecord<>(
+            record.topic(),
+            kafkaPartition,
+            record.offset(),
+            Collections.emptyList(), // Empty list for filtered records
+            record.timestamp(),
+            true // Mark as filtered
+        ));
+        continue;

Review Comment:
   This should be an if else block. 
   ```
   boolean shouldInclude=true;
   If (header!=null) {
   shouldInclude=headerFilterEvaluator.shouldIncludeRecord(record)
   }
   polledRecords.add(new OrderedPartitionableRecord<>(
               record.topic(),
               kafkaPartition,
               record.offset(),
               Collections.emptyList(), // Empty list for filtered records
               record.timestamp(),
             shouldInclude
           ));
           
    ```
    
    Also we are switching between inclusion and filtering in the naming. Please 
stick to one convention. I guess filtering seems better. 



##########
extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/supervisor/KafkaHeaderBasedInclusionConfig.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * 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 com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+import org.apache.druid.error.InvalidInput;
+import org.apache.druid.query.filter.DimFilter;
+import org.apache.druid.query.filter.InDimFilter;
+
+import javax.annotation.Nullable;
+
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * Kafka-specific implementation of header-based filtering.
+ * Allows filtering Kafka records based on message headers before 
deserialization.
+ */
+public class KafkaHeaderBasedInclusionConfig

Review Comment:
   ```suggestion
   public class KafkaHeaderBasedFilterConfig
   ```



##########
extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/supervisor/KafkaHeaderBasedInclusionConfig.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * 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 com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+import org.apache.druid.error.InvalidInput;
+import org.apache.druid.query.filter.DimFilter;
+import org.apache.druid.query.filter.InDimFilter;
+
+import javax.annotation.Nullable;
+
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * Kafka-specific implementation of header-based filtering.
+ * Allows filtering Kafka records based on message headers before 
deserialization.
+ */
+public class KafkaHeaderBasedInclusionConfig
+{
+  private static final ImmutableSet<Class<? extends DimFilter>> 
SUPPORTED_FILTER_TYPES = ImmutableSet.of(
+      InDimFilter.class
+  );
+
+  private final DimFilter filter;
+  private final String encoding;
+  private final int stringDecodingCacheSize;
+
+  @JsonCreator
+  public KafkaHeaderBasedInclusionConfig(
+      @JsonProperty("filter") DimFilter filter,
+      @JsonProperty("encoding") @Nullable String encoding,
+      @JsonProperty("stringDecodingCacheSize") @Nullable Integer 
stringDecodingCacheSize

Review Comment:
   I understand you need to cache because of performance issues. 
   The cache should have limit based on size in memory since that is more 
useful. 
   I think its not a blocker for this PR but make this cache size automatically 
set lets say 1/20 of the jvm by default. Having such static overrides makes it 
hard for cluster operators when peon sizes changes makes of new instance types. 



##########
docs/ingestion/kafka-ingestion.md:
##########
@@ -125,6 +125,7 @@ For configuration properties shared across all streaming 
ingestion methods, refe
 |`consumerProperties`|String, Object|A map of properties to pass to the Kafka 
consumer. See [Consumer properties](#consumer-properties) for details.|Yes. At 
the minimum, you must set the `bootstrap.servers` property to establish the 
initial connection to the Kafka cluster.||
 |`pollTimeout`|Long|The length of time to wait for the Kafka consumer to poll 
records, in milliseconds.|No|100|
 |`useEarliestOffset`|Boolean|If a supervisor is managing a datasource for the 
first time, it obtains a set of starting offsets from Kafka. This flag 
determines whether the supervisor retrieves the earliest or latest offsets in 
Kafka. Under normal circumstances, subsequent tasks start from where the 
previous segments ended so this flag is only used on the first run.|No|`false`|
+|`headerBasedInclusionConfig`|Object|Configuration for including Kafka records 
based on their headers before ingestion. See [Header-based inclusion 
filtering](#header-based-inclusion-filtering) for more details.|No|null|

Review Comment:
   `headerFilter` ?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to