gianm closed pull request #6508: fix KafkaSupervisor stats report error
URL: https://github.com/apache/incubator-druid/pull/6508
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisor.java
b/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisor.java
index da33d3db94a..fedc77f5e89 100644
---
a/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisor.java
+++
b/extensions-core/kafka-indexing-service/src/main/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisor.java
@@ -2416,21 +2416,21 @@ Runnable updateCurrentAndLatestOffsets()
}
for (int groupId : pendingCompletionTaskGroups.keySet()) {
- TaskGroup group = taskGroups.get(groupId);
- for (String taskId : group.taskIds()) {
- futures.add(
- Futures.transform(
- taskClient.getMovingAveragesAsync(taskId),
- (Function<Map<String, Object>, StatsFromTaskResult>)
(currentStats) -> {
- return new StatsFromTaskResult(
+ List<TaskGroup> pendingGroups = pendingCompletionTaskGroups.get(groupId);
+ for (TaskGroup pendingGroup : pendingGroups) {
+ for (String taskId : pendingGroup.taskIds()) {
+ futures.add(
+ Futures.transform(
+ taskClient.getMovingAveragesAsync(taskId),
+ (Function<Map<String, Object>, StatsFromTaskResult>)
(currentStats) -> new StatsFromTaskResult(
groupId,
taskId,
currentStats
- );
- }
- )
- );
- groupAndTaskIds.add(new Pair<>(groupId, taskId));
+ )
+ )
+ );
+ groupAndTaskIds.add(new Pair<>(groupId, taskId));
+ }
}
}
@@ -2449,6 +2449,50 @@ Runnable updateCurrentAndLatestOffsets()
return allStats;
}
+ @VisibleForTesting
+ void addTaskGroupToActivelyReadingTaskGroup(
+ int taskGroupId,
+ ImmutableMap<Integer, Long> partitionOffsets,
+ Optional<DateTime> minMsgTime,
+ Optional<DateTime> maxMsgTime,
+ Set<String> tasks
+ )
+ {
+ TaskGroup group = new TaskGroup(
+ taskGroupId,
+ partitionOffsets,
+ minMsgTime,
+ maxMsgTime
+ );
+ group.tasks.putAll(tasks.stream().collect(Collectors.toMap(x -> x, x ->
new TaskData())));
+ if (taskGroups.putIfAbsent(taskGroupId, group) != null) {
+ throw new ISE(
+ "trying to add taskGroup with ID [%s] to actively reading task
groups, but group already exists.",
+ taskGroupId
+ );
+ }
+ }
+
+ @VisibleForTesting
+ void addTaskGroupToPendingCompletionTaskGroup(
+ int taskGroupId,
+ ImmutableMap<Integer, Long> partitionOffsets,
+ Optional<DateTime> minMsgTime,
+ Optional<DateTime> maxMsgTime,
+ Set<String> tasks
+ )
+ {
+ TaskGroup group = new TaskGroup(
+ taskGroupId,
+ partitionOffsets,
+ minMsgTime,
+ maxMsgTime
+ );
+ group.tasks.putAll(tasks.stream().collect(Collectors.toMap(x -> x, x ->
new TaskData())));
+ pendingCompletionTaskGroups.computeIfAbsent(taskGroupId, x -> new
CopyOnWriteArrayList<>())
+ .add(group);
+ }
+
@VisibleForTesting
@Nullable
TaskGroup removeTaskGroup(int taskGroupId)
diff --git
a/extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisorTest.java
b/extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisorTest.java
index 084696d7ab9..237912346ec 100644
---
a/extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisorTest.java
+++
b/extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/indexing/kafka/supervisor/KafkaSupervisorTest.java
@@ -24,6 +24,7 @@
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import kafka.admin.AdminUtils;
@@ -2546,6 +2547,48 @@ public void testFailedInitializationAndRecovery() throws
Exception
Assert.assertEquals(Long.MAX_VALUE, (long)
taskConfig.getEndPartitions().getPartitionOffsetMap().get(2));
}
+ @Test
+ public void testGetCurrentTotalStats() throws Exception
+ {
+ supervisor = getSupervisor(1, 2, true, "PT1H", null, null, false);
+ supervisor.addTaskGroupToActivelyReadingTaskGroup(
+ supervisor.getTaskGroupIdForPartition(0),
+ ImmutableMap.of(0, 0L),
+ Optional.absent(),
+ Optional.absent(),
+ ImmutableSet.of("task1")
+ );
+
+ supervisor.addTaskGroupToPendingCompletionTaskGroup(
+ supervisor.getTaskGroupIdForPartition(1),
+ ImmutableMap.of(0, 0L),
+ Optional.absent(),
+ Optional.absent(),
+ ImmutableSet.of("task2")
+ );
+
+
expect(taskClient.getMovingAveragesAsync("task1")).andReturn(Futures.immediateFuture(ImmutableMap.of(
+ "prop1",
+ "val1"
+ ))).times(1);
+
+
expect(taskClient.getMovingAveragesAsync("task2")).andReturn(Futures.immediateFuture(ImmutableMap.of(
+ "prop2",
+ "val2"
+ ))).times(1);
+
+ replayAll();
+
+ Map<String, Map<String, Object>> stats = supervisor.getStats();
+
+ verifyAll();
+
+ Assert.assertEquals(2, stats.size());
+ Assert.assertEquals(ImmutableSet.of("0", "1"), stats.keySet());
+ Assert.assertEquals(ImmutableMap.of("task1", ImmutableMap.of("prop1",
"val1")), stats.get("0"));
+ Assert.assertEquals(ImmutableMap.of("task2", ImmutableMap.of("prop2",
"val2")), stats.get("1"));
+ }
+
private void addSomeEvents(int numEventsPerPartition) throws Exception
{
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]