This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new fd45e1c0a1e2 CAMEL-27990: camel-kafka - dev console bugs and
repository metadata (#31275)
fd45e1c0a1e2 is described below
commit fd45e1c0a1e2164a152e367d944237b4acaa83a2
Author: Guillaume Nodet <[email protected]>
AuthorDate: Wed Dec 2 21:37:01 2026 +0100
CAMEL-27990: camel-kafka - dev console bugs and repository metadata (#31275)
Three bugs fixed in camel-kafka:
1. KafkaDevConsole: epoch field in KafkaTopicPosition is a Kafka leader
epoch (small integer), not a Unix timestamp. The 'Commit Offset Since'
display subtracted it from currentTimeMillis giving a ~56-year duration.
Fixed to show 'Commit Leader Epoch: N' when the epoch is known (> 0).
Removed now-unused TimeUtils import.
2. DefaultMetricsCollector: consumer.committed() returns null values for
partitions that have never had a committed offset. The loop called
e.getValue().offset() unconditionally causing NPE. Additionally the
latch.countDown() was never called on exception, leaving the caller
blocked until timeout. Fixed: skip null OffsetAndMetadata entries, and
always countDown the latch in the catch block.
3. KafkaIdempotentRepository: consumerConfig and producerConfig fields
lacked @Metadata annotations, so they were invisible to the dev console
and the bean introspection tooling. Added @Metadata with description,
label=advanced and javaType. Updated generated JSON descriptors.
Follow-up commits:
- CAMEL-27990: fix epoch display in CLI and add DefaultMetricsCollector
unit tests
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
.../catalog/beans/KafkaIdempotentRepository.json | 2 +-
.../kafka/KafkaIdempotentRepositoryConfigurer.java | 12 ++++
.../camel/bean/KafkaIdempotentRepository.json | 2 +-
.../camel/component/kafka/KafkaDevConsole.java | 5 +-
.../devconsole/DefaultMetricsCollector.java | 10 ++-
.../kafka/KafkaIdempotentRepository.java | 6 ++
.../devconsole/DefaultMetricsCollectorTest.java | 71 ++++++++++++++++++++++
.../dsl/jbang/core/commands/process/ListKafka.java | 3 +-
8 files changed, 102 insertions(+), 9 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/KafkaIdempotentRepository.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/KafkaIdempotentRepository.json
index 5424d2112da1..13b982360194 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/KafkaIdempotentRepository.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/KafkaIdempotentRepository.json
@@ -10,7 +10,7 @@
"groupId": "org.apache.camel",
"artifactId": "camel-kafka",
"version": "4.24.0-SNAPSHOT",
- "properties": { "topic": { "index": 0, "kind": "property", "displayName":
"Topic", "required": true, "type": "string", "javaType": "java.lang.String",
"deprecated": false, "autowired": false, "secret": false, "description": "Name
of the Kafka topic that holds the changes of the repository. Use a different
topic for each repository." }, "bootstrapServers": { "index": 1, "kind":
"property", "displayName": "Bootstrap Servers", "required": true, "type":
"string", "javaType": "java.lang.S [...]
+ "properties": { "producerConfig": { "index": 0, "kind": "property",
"displayName": "Producer Config", "label": "advanced", "required": false,
"type": "object", "javaType": "java.util.Properties", "deprecated": false,
"autowired": false, "secret": false, "description": "Properties to configure
the Kafka producer. When set, overrides bootstrapServers for the producer; must
include bootstrap.servers. Use bootstrapServers for simple setups." },
"consumerConfig": { "index": 1, "kind": "pr [...]
}
}
diff --git
a/components/camel-kafka/src/generated/java/org/apache/camel/processor/idempotent/kafka/KafkaIdempotentRepositoryConfigurer.java
b/components/camel-kafka/src/generated/java/org/apache/camel/processor/idempotent/kafka/KafkaIdempotentRepositoryConfigurer.java
index d3505e0bb4ed..2bcdc3eddb84 100644
---
a/components/camel-kafka/src/generated/java/org/apache/camel/processor/idempotent/kafka/KafkaIdempotentRepositoryConfigurer.java
+++
b/components/camel-kafka/src/generated/java/org/apache/camel/processor/idempotent/kafka/KafkaIdempotentRepositoryConfigurer.java
@@ -26,12 +26,16 @@ public class KafkaIdempotentRepositoryConfigurer extends
org.apache.camel.suppor
switch (ignoreCase ? name.toLowerCase(Locale.ROOT) : name) {
case "bootstrapservers":
case "bootstrapServers":
target.setBootstrapServers(property(camelContext, java.lang.String.class,
value)); return true;
+ case "consumerconfig":
+ case "consumerConfig": target.setConsumerConfig(property(camelContext,
java.util.Properties.class, value)); return true;
case "groupid":
case "groupId": target.setGroupId(property(camelContext,
java.lang.String.class, value)); return true;
case "maxcachesize":
case "maxCacheSize": target.setMaxCacheSize(property(camelContext,
int.class, value)); return true;
case "polldurationms":
case "pollDurationMs": target.setPollDurationMs(property(camelContext,
int.class, value)); return true;
+ case "producerconfig":
+ case "producerConfig": target.setProducerConfig(property(camelContext,
java.util.Properties.class, value)); return true;
case "startuponly":
case "startupOnly": target.setStartupOnly(property(camelContext,
boolean.class, value)); return true;
case "topic": target.setTopic(property(camelContext,
java.lang.String.class, value)); return true;
@@ -44,12 +48,16 @@ public class KafkaIdempotentRepositoryConfigurer extends
org.apache.camel.suppor
switch (ignoreCase ? name.toLowerCase(Locale.ROOT) : name) {
case "bootstrapservers":
case "bootstrapServers": return java.lang.String.class;
+ case "consumerconfig":
+ case "consumerConfig": return java.util.Properties.class;
case "groupid":
case "groupId": return java.lang.String.class;
case "maxcachesize":
case "maxCacheSize": return int.class;
case "polldurationms":
case "pollDurationMs": return int.class;
+ case "producerconfig":
+ case "producerConfig": return java.util.Properties.class;
case "startuponly":
case "startupOnly": return boolean.class;
case "topic": return java.lang.String.class;
@@ -63,12 +71,16 @@ public class KafkaIdempotentRepositoryConfigurer extends
org.apache.camel.suppor
switch (ignoreCase ? name.toLowerCase(Locale.ROOT) : name) {
case "bootstrapservers":
case "bootstrapServers": return target.getBootstrapServers();
+ case "consumerconfig":
+ case "consumerConfig": return target.getConsumerConfig();
case "groupid":
case "groupId": return target.getGroupId();
case "maxcachesize":
case "maxCacheSize": return target.getMaxCacheSize();
case "polldurationms":
case "pollDurationMs": return target.getPollDurationMs();
+ case "producerconfig":
+ case "producerConfig": return target.getProducerConfig();
case "startuponly":
case "startupOnly": return target.isStartupOnly();
case "topic": return target.getTopic();
diff --git
a/components/camel-kafka/src/generated/resources/META-INF/services/org/apache/camel/bean/KafkaIdempotentRepository.json
b/components/camel-kafka/src/generated/resources/META-INF/services/org/apache/camel/bean/KafkaIdempotentRepository.json
index 5424d2112da1..13b982360194 100644
---
a/components/camel-kafka/src/generated/resources/META-INF/services/org/apache/camel/bean/KafkaIdempotentRepository.json
+++
b/components/camel-kafka/src/generated/resources/META-INF/services/org/apache/camel/bean/KafkaIdempotentRepository.json
@@ -10,7 +10,7 @@
"groupId": "org.apache.camel",
"artifactId": "camel-kafka",
"version": "4.24.0-SNAPSHOT",
- "properties": { "topic": { "index": 0, "kind": "property", "displayName":
"Topic", "required": true, "type": "string", "javaType": "java.lang.String",
"deprecated": false, "autowired": false, "secret": false, "description": "Name
of the Kafka topic that holds the changes of the repository. Use a different
topic for each repository." }, "bootstrapServers": { "index": 1, "kind":
"property", "displayName": "Bootstrap Servers", "required": true, "type":
"string", "javaType": "java.lang.S [...]
+ "properties": { "producerConfig": { "index": 0, "kind": "property",
"displayName": "Producer Config", "label": "advanced", "required": false,
"type": "object", "javaType": "java.util.Properties", "deprecated": false,
"autowired": false, "secret": false, "description": "Properties to configure
the Kafka producer. When set, overrides bootstrapServers for the producer; must
include bootstrap.servers. Use bootstrapServers for simple setups." },
"consumerConfig": { "index": 1, "kind": "pr [...]
}
}
diff --git
a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaDevConsole.java
b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaDevConsole.java
index 3255d5aada76..7f10ea4447cd 100644
---
a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaDevConsole.java
+++
b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaDevConsole.java
@@ -29,7 +29,6 @@ import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.annotations.DevConsole;
import org.apache.camel.support.console.AbstractDevConsole;
import org.apache.camel.util.StopWatch;
-import org.apache.camel.util.TimeUtils;
import org.apache.camel.util.json.JsonRecordSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -119,9 +118,7 @@ public class KafkaDevConsole extends AbstractDevConsole {
sb.append(String.format("%n Commit
Partition: %s", r.partition()));
sb.append(String.format("%n Commit
Offset: %s", r.offset()));
if (r.epoch() > 0) {
- long delta = System.currentTimeMillis() -
r.epoch();
- sb.append(String.format("%n Commit
Offset Since: %s",
- TimeUtils.printDuration(delta,
true)));
+ sb.append(String.format("%n Commit
Leader Epoch: %d", r.epoch()));
}
}
}
diff --git
a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/devconsole/DefaultMetricsCollector.java
b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/devconsole/DefaultMetricsCollector.java
index f00367bc9a00..95429458b3e2 100644
---
a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/devconsole/DefaultMetricsCollector.java
+++
b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/consumer/devconsole/DefaultMetricsCollector.java
@@ -75,6 +75,10 @@ public class DefaultMetricsCollector implements
DevConsoleMetricsCollector {
Map<TopicPartition, OffsetAndMetadata> commits =
consumer.committed(consumer.assignment());
commitRecords.clear();
for (var e : commits.entrySet()) {
+ // committed() returns null for partitions with no
committed offset; skip them
+ if (e.getValue() == null) {
+ continue;
+ }
KafkaTopicPosition p
= new KafkaTopicPosition(
e.getKey().topic(),
e.getKey().partition(), e.getValue().offset(),
@@ -86,10 +90,14 @@ public class DefaultMetricsCollector implements
DevConsoleMetricsCollector {
count.countDown();
}
} catch (Exception e) {
- // ignore cannot get last commit details
+ // ignore cannot get last commit details; always release the
latch so callers don't hang
LOG.debug(
"Cannot get last offset committed from Kafka brokers
due to: {}. This exception is ignored.",
e.getMessage(), e);
+ CountDownLatch count = latch.get();
+ if (count != null) {
+ count.countDown();
+ }
}
}
}
diff --git
a/components/camel-kafka/src/main/java/org/apache/camel/processor/idempotent/kafka/KafkaIdempotentRepository.java
b/components/camel-kafka/src/main/java/org/apache/camel/processor/idempotent/kafka/KafkaIdempotentRepository.java
index cc20f330db10..e200f6916f74 100644
---
a/components/camel-kafka/src/main/java/org/apache/camel/processor/idempotent/kafka/KafkaIdempotentRepository.java
+++
b/components/camel-kafka/src/main/java/org/apache/camel/processor/idempotent/kafka/KafkaIdempotentRepository.java
@@ -85,7 +85,13 @@ public class KafkaIdempotentRepository extends
ServiceSupport implements Idempot
// guards the local changes of the cache against the records applied by
the poller, never held while sending
private final Lock lock = new ReentrantLock();
+ @Metadata(description = "Properties to configure the Kafka producer. When
set, overrides bootstrapServers for the"
+ + " producer; must include bootstrap.servers. Use
bootstrapServers for simple setups.",
+ label = "advanced", javaType = "java.util.Properties")
private Properties producerConfig;
+ @Metadata(description = "Properties to configure the Kafka consumer. When
set, overrides bootstrapServers and groupId"
+ + " for the consumer; must include
bootstrap.servers. Use bootstrapServers for simple setups.",
+ label = "advanced", javaType = "java.util.Properties")
private Properties consumerConfig;
// configurable
diff --git
a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/consumer/devconsole/DefaultMetricsCollectorTest.java
b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/consumer/devconsole/DefaultMetricsCollectorTest.java
new file mode 100644
index 000000000000..150cf78a614e
--- /dev/null
+++
b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/consumer/devconsole/DefaultMetricsCollectorTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.camel.component.kafka.consumer.devconsole;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+
+import org.apache.kafka.clients.consumer.Consumer;
+import org.apache.kafka.clients.consumer.OffsetAndMetadata;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.errors.TimeoutException;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.anySet;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class DefaultMetricsCollectorTest {
+
+ @Test
+ void skipsPartitionsWithoutCommittedOffsetAndReleasesLatch() {
+ Consumer<String, String> consumer = mock(Consumer.class);
+ TopicPartition p0 = new TopicPartition("t", 0);
+ TopicPartition p1 = new TopicPartition("t", 1);
+ when(consumer.assignment()).thenReturn(Set.of(p0, p1));
+ Map<TopicPartition, OffsetAndMetadata> committed = new HashMap<>();
+ committed.put(p0, new OffsetAndMetadata(5));
+ committed.put(p1, null);
+ when(consumer.committed(anySet())).thenReturn(committed);
+
+ DefaultMetricsCollector collector = new DefaultMetricsCollector("t1");
+ CountDownLatch latch = collector.fetchCommitRecords();
+ collector.collectCommitMetrics(consumer);
+
+ assertEquals(0, latch.getCount());
+ assertEquals(1, collector.getCommitRecords().size());
+ assertEquals(5, collector.getCommitRecords().get(0).offset());
+ }
+
+ @Test
+ void releasesLatchWhenCommittedThrows() {
+ Consumer<String, String> consumer = mock(Consumer.class);
+ TopicPartition p0 = new TopicPartition("t", 0);
+ when(consumer.assignment()).thenReturn(Set.of(p0));
+ when(consumer.committed(anySet())).thenThrow(new
TimeoutException("broker unreachable"));
+
+ DefaultMetricsCollector collector = new DefaultMetricsCollector("t1");
+ CountDownLatch latch = collector.fetchCommitRecords();
+ collector.collectCommitMetrics(consumer);
+
+ assertEquals(0, latch.getCount());
+ assertEquals(0, collector.getCommitRecords().size());
+ }
+}
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListKafka.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListKafka.java
index 25e2ce945d8e..4944f12a84c3 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListKafka.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListKafka.java
@@ -260,8 +260,7 @@ public class ListKafka extends ProcessWatchCommand {
private String getCommitted(Row r) {
if (r.committedEpoch > 0) {
- String age = TimeUtils.printSince(r.committedEpoch);
- return r.committedOffset + " (" + age + ")";
+ return r.committedOffset + " (epoch " + r.committedEpoch + ")";
} else {
return "" + r.committedOffset;
}