This is an automated email from the ASF dual-hosted git repository.
xiangfu0 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new c6fe9fc1890 Emit a minion subtask queue-stall gauge that a long but
draining job does not trip (#20039)
c6fe9fc1890 is described below
commit c6fe9fc1890432c2ae50db8b7e35764968875ed8
Author: RAGHVENDRA KUMAR YADAV <[email protected]>
AuthorDate: Wed Nov 18 11:19:51 2026 -0800
Emit a minion subtask queue-stall gauge that a long but draining job does
not trip (#20039)
* Emit a minion subtask queue-stall gauge that a long but draining job does
not trip
* Clarify when the queue stall time is set
* Count a running subtask as progress in the queue stall gauge
A subtask that runs for hours with siblings queued behind it (e.g. a job
that
runs one subtask at a time) grew the stall like a stuck queue, the false
alarm
this gauge is meant to remove. The stall is now 0 while a subtask is running
or starting; MAX_SUBTASK_RUNNING_TIME_MS still catches one that hangs.
---
.../configs/controller.yml | 2 +-
.../pinot/common/metrics/ControllerGauge.java | 4 ++
.../core/minion/PinotHelixTaskResourceManager.java | 33 ++++++++++-
.../helix/core/minion/TaskMetricsEmitter.java | 7 +++
.../minion/PinotHelixTaskResourceManagerTest.java | 66 ++++++++++++++++++++++
.../helix/core/minion/TaskMetricsEmitterTest.java | 24 ++++++--
6 files changed, 128 insertions(+), 8 deletions(-)
diff --git
a/docker/images/pinot/etc/jmx_prometheus_javaagent/configs/controller.yml
b/docker/images/pinot/etc/jmx_prometheus_javaagent/configs/controller.yml
index 23e9c5b0c49..a10e3eaf2d2 100644
--- a/docker/images/pinot/etc/jmx_prometheus_javaagent/configs/controller.yml
+++ b/docker/images/pinot/etc/jmx_prometheus_javaagent/configs/controller.yml
@@ -37,7 +37,7 @@ rules:
labels:
taskType: "$2"
# Gauges that accept tableNameWithType + controller taskType
-- pattern:
"\"org\\.apache\\.pinot\\.common\\.metrics\"<type=\"ControllerMetrics\",
name=\"pinot\\.controller\\.(numMinionSubtasksRunning|numMinionSubtasksWaiting|numMinionSubtasksError|numMinionSubtasksUnknown|numMinionSubtasksDropped|numMinionSubtasksTimedOut|numMinionSubtasksAborted|percentMinionSubtasksInQueue|percentMinionSubtasksInError|maxSubtaskWaitTimeMs|maxSubtaskRunningTimeMs)\\.(([^.]+)\\.)?([^.]*)_(OFFLINE|REALTIME)\\.(\\w+)\"><>(\\w+)"
+- pattern:
"\"org\\.apache\\.pinot\\.common\\.metrics\"<type=\"ControllerMetrics\",
name=\"pinot\\.controller\\.(numMinionSubtasksRunning|numMinionSubtasksWaiting|numMinionSubtasksError|numMinionSubtasksUnknown|numMinionSubtasksDropped|numMinionSubtasksTimedOut|numMinionSubtasksAborted|percentMinionSubtasksInQueue|percentMinionSubtasksInError|maxSubtaskWaitTimeMs|maxSubtaskRunningTimeMs|maxSubtaskQueueStallTimeMs)\\.(([^.]+)\\.)?([^.]*)_(OFFLINE|REALTIME)\\.(\\w+)\"><>(\\w+)"
name: "pinot_controller_$1_$7"
cache: true
labels:
diff --git
a/pinot-common/src/main/java/org/apache/pinot/common/metrics/ControllerGauge.java
b/pinot-common/src/main/java/org/apache/pinot/common/metrics/ControllerGauge.java
index 75d629dd3d7..020720513bf 100644
---
a/pinot-common/src/main/java/org/apache/pinot/common/metrics/ControllerGauge.java
+++
b/pinot-common/src/main/java/org/apache/pinot/common/metrics/ControllerGauge.java
@@ -70,6 +70,10 @@ public enum ControllerGauge implements AbstractMetrics.Gauge
{
NUM_MINION_TASKS_IN_PROGRESS("NumMinionTasksInProgress", true),
NUM_MINION_SUBTASKS_WAITING("NumMinionSubtasksWaiting", true),
MAX_SUBTASK_WAIT_TIME_MS("MaxSubtaskWaitTimeMs", false),
+ // Time since the job last made progress, while the table still has subtasks
waiting: 0 while a subtask runs,
+ // otherwise the time since a subtask last started or finished. Unlike
MAX_SUBTASK_WAIT_TIME_MS (the age of the job),
+ // it stays low while a long job keeps draining.
+ MAX_SUBTASK_QUEUE_STALL_TIME_MS("MaxSubtaskQueueStallTimeMs", false),
NUM_MINION_SUBTASKS_RUNNING("NumMinionSubtasksRunning", true),
MAX_SUBTASK_RUNNING_TIME_MS("MaxSubtaskRunningTimeMs", false),
NUM_MINION_SUBTASKS_ERROR("NumMinionSubtasksError", true),
diff --git
a/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotHelixTaskResourceManager.java
b/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotHelixTaskResourceManager.java
index bc512171f01..cdc9d9f8ec5 100644
---
a/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotHelixTaskResourceManager.java
+++
b/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotHelixTaskResourceManager.java
@@ -542,7 +542,9 @@ public class PinotHelixTaskResourceManager {
}
/// This method returns a map of table name to count of sub-tasks in various
states, given the top-level task name.
- /// It also collects waiting times for subtasks with null state and running
times for subtasks in RUNNING state.
+ /// It also collects waiting times for subtasks with null state and running
times for subtasks in RUNNING state, and
+ /// for tables with waiting subtasks, the time since the job last made
progress (queue stall): 0 while a subtask is
+ /// running, otherwise the time since a subtask last started or finished.
///
/// @param taskName in the form "Task\_<taskType>\_<uuid>\_<timestamp>"
/// @return a map of table name to [TaskStatusSummary]
@@ -565,6 +567,7 @@ public class PinotHelixTaskResourceManager {
}
long jobStartTime = jobContext.getStartTime();
long currentTime = System.currentTimeMillis();
+ long lastProgressTime = jobStartTime;
Map<String, Integer> taskIdPartitionMap =
jobContext.getTaskIdPartitionMap();
for (Map.Entry<String, TaskConfig> entry : taskConfigMap.entrySet()) {
String taskId = entry.getKey();
@@ -574,6 +577,14 @@ public class PinotHelixTaskResourceManager {
if (partition != null) {
state = jobContext.getPartitionState(partition);
executionStartTime = jobContext.getPartitionStartTime(partition);
+ if (state == TaskPartitionState.RUNNING || state ==
TaskPartitionState.INIT) {
+ // A subtask in flight is progress: a long one must not read as a
stuck queue (MAX_SUBTASK_RUNNING_TIME_MS
+ // catches one that hangs)
+ lastProgressTime = currentTime;
+ } else {
+ lastProgressTime =
+ Math.max(lastProgressTime, Math.max(executionStartTime,
jobContext.getPartitionFinishTime(partition)));
+ }
}
TaskConfig taskConfig = entry.getValue();
String tableName =
taskConfig.getConfigMap().getOrDefault(MinionConstants.TABLE_NAME_KEY,
UNKNOWN_TABLE_NAME);
@@ -594,6 +605,16 @@ public class PinotHelixTaskResourceManager {
taskStatusSummary.getSubtaskRunningTimes().put(taskId,
runningTimeMillis);
}
}
+ // A job whose subtasks keep starting or finishing is draining, however
old it is: only the time since the last
+ // such progress tells a stuck queue apart from a long one
+ if (jobStartTime > 0) {
+ long queueStallTimeMillis = currentTime - lastProgressTime;
+ for (TaskStatusSummary taskStatusSummary :
taskStatusSummaryMap.values()) {
+ if (!taskStatusSummary.getSubtaskWaitingTimes().isEmpty()) {
+ taskStatusSummary.setQueueStallTimeMs(queueStallTimeMillis);
+ }
+ }
+ }
return taskStatusSummaryMap;
}
@@ -1848,6 +1869,8 @@ public class PinotHelixTaskResourceManager {
private TaskCount _taskCount = new TaskCount();
private Map<String, Long> _subtaskWaitingTimes = new HashMap<>(); //
subtask ID -> waiting time in milliseconds
private Map<String, Long> _subtaskRunningTimes = new HashMap<>(); //
subtask ID -> running time in milliseconds
+ // Time since the job last made progress (0 while a subtask runs); left at
0 unless the table has a waiting subtask
+ private long _queueStallTimeMs;
public TaskCount getTaskCount() {
return _taskCount;
@@ -1872,6 +1895,14 @@ public class PinotHelixTaskResourceManager {
public void setSubtaskRunningTimes(Map<String, Long> subtaskRunningTimes) {
_subtaskRunningTimes = subtaskRunningTimes;
}
+
+ public long getQueueStallTimeMs() {
+ return _queueStallTimeMs;
+ }
+
+ public void setQueueStallTimeMs(long queueStallTimeMs) {
+ _queueStallTimeMs = queueStallTimeMs;
+ }
}
/// Response model for the `GET /tasks/summary` endpoint.
diff --git
a/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/TaskMetricsEmitter.java
b/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/TaskMetricsEmitter.java
index f513e864c41..54f57565f96 100644
---
a/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/TaskMetricsEmitter.java
+++
b/pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/TaskMetricsEmitter.java
@@ -106,6 +106,7 @@ public class TaskMetricsEmitter extends BasePeriodicTask {
Map<String, TaskCount> tableAccumulatedCount = new HashMap<>();
Map<String, Long> tableMaxWaitTimeMs = new HashMap<>();
Map<String, Long> tableMaxRunningTimeMs = new HashMap<>();
+ Map<String, Long> tableMaxQueueStallTimeMs = new HashMap<>();
try {
// Capture the current execution timestamp for this task type
collection cycle
long currentExecutionTimestamp = System.currentTimeMillis();
@@ -149,6 +150,7 @@ public class TaskMetricsEmitter extends BasePeriodicTask {
taskStatusSummary.getSubtaskRunningTimes().values().forEach(subtaskRunningTime
-> {
tableMaxRunningTimeMs.merge(tableNameWithType,
subtaskRunningTime, Math::max);
});
+ tableMaxQueueStallTimeMs.merge(tableNameWithType,
taskStatusSummary.getQueueStallTimeMs(), Math::max);
return count;
});
});
@@ -214,6 +216,9 @@ public class TaskMetricsEmitter extends BasePeriodicTask {
_controllerMetrics.setOrUpdateTableGauge(tableNameWithType, taskType,
ControllerGauge.MAX_SUBTASK_RUNNING_TIME_MS,
tableMaxRunningTimeMs.getOrDefault(tableNameWithType, 0L));
+ _controllerMetrics.setOrUpdateTableGauge(tableNameWithType, taskType,
+ ControllerGauge.MAX_SUBTASK_QUEUE_STALL_TIME_MS,
+ tableMaxQueueStallTimeMs.getOrDefault(tableNameWithType, 0L));
});
if (_preReportedTables.containsKey(taskType)) {
@@ -293,6 +298,8 @@ public class TaskMetricsEmitter extends BasePeriodicTask {
ControllerGauge.PERCENT_MINION_SUBTASKS_IN_ERROR);
_controllerMetrics.removeTableGauge(tableNameWithType, taskType,
ControllerGauge.MAX_SUBTASK_WAIT_TIME_MS);
_controllerMetrics.removeTableGauge(tableNameWithType, taskType,
ControllerGauge.MAX_SUBTASK_RUNNING_TIME_MS);
+ _controllerMetrics.removeTableGauge(tableNameWithType, taskType,
+ ControllerGauge.MAX_SUBTASK_QUEUE_STALL_TIME_MS);
});
}
}
diff --git
a/pinot-controller/src/test/java/org/apache/pinot/controller/helix/core/minion/PinotHelixTaskResourceManagerTest.java
b/pinot-controller/src/test/java/org/apache/pinot/controller/helix/core/minion/PinotHelixTaskResourceManagerTest.java
index 2ed398a5169..44d69b86126 100644
---
a/pinot-controller/src/test/java/org/apache/pinot/controller/helix/core/minion/PinotHelixTaskResourceManagerTest.java
+++
b/pinot-controller/src/test/java/org/apache/pinot/controller/helix/core/minion/PinotHelixTaskResourceManagerTest.java
@@ -421,6 +421,72 @@ public class PinotHelixTaskResourceManagerTest {
// Waiting time should be approximately 600000 ms (10 minutes)
long waitingTime = waitingTimes.get("taskId1");
assertTrue(waitingTime >= 595000 && waitingTime <= 605000);
+
+ // taskId0 is running, so the queue is not stalled however long it runs
+ assertEquals(taskStatusSummary.getQueueStallTimeMs(), 0L);
+ }
+
+ /// A job whose subtasks have never started reports the job's age as its
queue stall.
+ @Test
+ public void testGetTableTaskStatusSummaryQueueStallTimeNeverStarted() {
+ String taskName = "Task_TestTask_24680";
+ String helixJobName =
PinotHelixTaskResourceManager.getHelixJobName(taskName);
+ TaskDriver taskDriver = mock(TaskDriver.class);
+ JobConfig jobConfig = mock(JobConfig.class);
+ when(taskDriver.getJobConfig(anyString())).thenReturn(jobConfig);
+ when(jobConfig.getTaskConfigMap()).thenReturn(Map.of(
+ "taskId0", new TaskConfig("", new HashMap<>(Map.of("tableName",
"table1_OFFLINE"))),
+ "taskId1", new TaskConfig("", new HashMap<>(Map.of("tableName",
"table1_OFFLINE")))));
+ JobContext jobContext = mock(JobContext.class);
+ when(taskDriver.getJobContext(helixJobName)).thenReturn(jobContext);
+ when(jobContext.getTaskIdPartitionMap()).thenReturn(Map.of());
+ long jobStartTime = System.currentTimeMillis() - 600000; // 10 minutes ago
+ when(jobContext.getStartTime()).thenReturn(jobStartTime);
+
+ PinotHelixTaskResourceManager mgr =
+ new
PinotHelixTaskResourceManager(mock(PinotHelixResourceManager.class),
taskDriver);
+ long queueStallTime =
mgr.getTableTaskStatusSummary(taskName).get("table1_OFFLINE").getQueueStallTimeMs();
+ assertTrue(queueStallTime >= 595000 && queueStallTime <= 605000,
String.valueOf(queueStallTime));
+ }
+
+ @Test
+ public void testGetTableTaskStatusSummaryQueueStallTime() {
+ String taskName = "Task_TestTask_QueueStall";
+ String helixJobName =
PinotHelixTaskResourceManager.getHelixJobName(taskName);
+ TaskDriver taskDriver = mock(TaskDriver.class);
+ JobConfig jobConfig = mock(JobConfig.class);
+ when(taskDriver.getJobConfig(anyString())).thenReturn(jobConfig);
+ Map<String, TaskConfig> taskConfigMap = new HashMap<>();
+ taskConfigMap.put("taskId0", new TaskConfig("", new
HashMap<>(Map.of("tableName", "table1_OFFLINE"))));
+ taskConfigMap.put("taskId1", new TaskConfig("", new
HashMap<>(Map.of("tableName", "table2_OFFLINE"))));
+ taskConfigMap.put("taskId2", new TaskConfig("", new
HashMap<>(Map.of("tableName", "table1_OFFLINE"))));
+ when(jobConfig.getTaskConfigMap()).thenReturn(taskConfigMap);
+ JobContext jobContext = mock(JobContext.class);
+ when(taskDriver.getJobContext(helixJobName)).thenReturn(jobContext);
+ // taskId0 (table1) started 5h ago and finished 1 minute ago; taskId1
(table2) ran from 2h to 1h ago;
+ // taskId2 (table1) is still waiting
+ when(jobContext.getTaskIdPartitionMap()).thenReturn(Map.of("taskId0", 0,
"taskId1", 1));
+ long now = System.currentTimeMillis();
+
when(jobContext.getPartitionState(0)).thenReturn(TaskPartitionState.COMPLETED);
+ when(jobContext.getPartitionStartTime(0)).thenReturn(now - 18_000_000L);
+ when(jobContext.getPartitionFinishTime(0)).thenReturn(now - 60_000L);
+
when(jobContext.getPartitionState(1)).thenReturn(TaskPartitionState.COMPLETED);
+ when(jobContext.getPartitionStartTime(1)).thenReturn(now - 7_200_000L);
+ when(jobContext.getPartitionFinishTime(1)).thenReturn(now - 3_600_000L);
+ when(jobContext.getStartTime()).thenReturn(now - 21_600_000L);
+
+ PinotHelixTaskResourceManager mgr =
+ new
PinotHelixTaskResourceManager(mock(PinotHelixResourceManager.class),
taskDriver);
+ Map<String, TaskStatusSummary> tableTaskStatusSummary =
mgr.getTableTaskStatusSummary(taskName);
+
+ // The job is 6h old, so the waiting subtask reports 6h of waiting, but a
subtask finished a minute ago
+ TaskStatusSummary table1Summary =
tableTaskStatusSummary.get("table1_OFFLINE");
+ long waitingTime = table1Summary.getSubtaskWaitingTimes().get("taskId2");
+ assertTrue(waitingTime >= 21_595_000L && waitingTime <= 21_605_000L);
+ long queueStallTime = table1Summary.getQueueStallTimeMs();
+ assertTrue(queueStallTime >= 55_000L && queueStallTime <= 65_000L);
+ // table2 has nothing waiting, so it has no stall
+
assertEquals(tableTaskStatusSummary.get("table2_OFFLINE").getQueueStallTimeMs(),
0L);
}
@Test
diff --git
a/pinot-controller/src/test/java/org/apache/pinot/controller/helix/core/minion/TaskMetricsEmitterTest.java
b/pinot-controller/src/test/java/org/apache/pinot/controller/helix/core/minion/TaskMetricsEmitterTest.java
index 6d723e65fd6..e0894549aa4 100644
---
a/pinot-controller/src/test/java/org/apache/pinot/controller/helix/core/minion/TaskMetricsEmitterTest.java
+++
b/pinot-controller/src/test/java/org/apache/pinot/controller/helix/core/minion/TaskMetricsEmitterTest.java
@@ -154,6 +154,7 @@ public class TaskMetricsEmitterTest {
timing1.setTaskCount(taskCount1);
// Add waiting time for null-state subtask to exercise timing metrics
emission
timing1.getSubtaskWaitingTimes().put("subtask2", 3000L);
+ timing1.setQueueStallTimeMs(1000L);
taskCount2 = new PinotHelixTaskResourceManager.TaskCount();
taskCount2.addTaskState(TaskPartitionState.TASK_ERROR);
timing2 = new PinotHelixTaskResourceManager.TaskStatusSummary();
@@ -174,9 +175,9 @@ public class TaskMetricsEmitterTest {
private void runAndAssertForTaskType1WithTwoTables() {
PinotMetricsRegistry metricsRegistry =
_controllerMetrics.getMetricsRegistry();
_taskMetricsEmitter.runTask(null);
- // Expected 33 metrics: 29 original + MAX_SUBTASK_WAIT_TIME_MS gauge (x2
tables)
- // + MAX_SUBTASK_RUNNING_TIME_MS gauge (x2 tables)
- Assert.assertEquals(metricsRegistry.allMetrics().size(), 33);
+ // Expected 35 metrics: 29 original + MAX_SUBTASK_WAIT_TIME_MS gauge (x2
tables)
+ // + MAX_SUBTASK_RUNNING_TIME_MS gauge (x2 tables) +
MAX_SUBTASK_QUEUE_STALL_TIME_MS gauge (x2 tables)
+ Assert.assertEquals(metricsRegistry.allMetrics().size(), 35);
Assert.assertTrue(metricsRegistry.allMetrics().containsKey(
new YammerMetricName(ControllerMetrics.class,
"pinot.controller.onlineMinionInstances")));
@@ -271,6 +272,16 @@ public class TaskMetricsEmitterTest {
new YammerMetricName(ControllerMetrics.class,
"pinot.controller.maxSubtaskRunningTimeMs.table2_OFFLINE.taskType1"))
.getMetric()).value(), 5000L);
+
+ // table1's waiting subtask belongs to a job that last made progress
1000ms ago; table2 has nothing waiting
+ Assert.assertEquals(((YammerSettableGauge<?>)
metricsRegistry.allMetrics().get(
+ new YammerMetricName(ControllerMetrics.class,
+
"pinot.controller.maxSubtaskQueueStallTimeMs.table1_OFFLINE.taskType1"))
+ .getMetric()).value(), 1000L);
+ Assert.assertEquals(((YammerSettableGauge<?>)
metricsRegistry.allMetrics().get(
+ new YammerMetricName(ControllerMetrics.class,
+
"pinot.controller.maxSubtaskQueueStallTimeMs.table2_OFFLINE.taskType1"))
+ .getMetric()).value(), 0L);
}
@Test
@@ -302,9 +313,10 @@ public class TaskMetricsEmitterTest {
PinotMetricsRegistry metricsRegistry =
_controllerMetrics.getMetricsRegistry();
_taskMetricsEmitter.runTask(null);
- // Expected at least 22 metrics: 20 original + MAX_SUBTASK_WAIT_TIME_MS
gauge (x1 table)
- // + MAX_SUBTASK_RUNNING_TIME_MS gauge (x1 table). Count may vary based on
test execution order.
- Assert.assertTrue(metricsRegistry.allMetrics().size() >= 22);
+ // Expected at least 23 metrics: 20 original + MAX_SUBTASK_WAIT_TIME_MS
gauge (x1 table)
+ // + MAX_SUBTASK_RUNNING_TIME_MS gauge (x1 table) +
MAX_SUBTASK_QUEUE_STALL_TIME_MS gauge (x1 table).
+ // Count may vary based on test execution order.
+ Assert.assertTrue(metricsRegistry.allMetrics().size() >= 23);
Assert.assertTrue(metricsRegistry.allMetrics().containsKey(
new YammerMetricName(ControllerMetrics.class,
"pinot.controller.onlineMinionInstances")));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]