Jackie-Jiang commented on a change in pull request #6549:
URL: https://github.com/apache/incubator-pinot/pull/6549#discussion_r572474624



##########
File path: 
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotTaskManager.java
##########
@@ -478,4 +489,34 @@ public void cleanUpTask() {
   public Scheduler getScheduler() {
     return _scheduledExecutorService;
   }
+
+  public synchronized void reportMetrics(String taskType) {
+    Map<String, TaskState> taskStates = 
_helixTaskResourceManager.getTaskStates(taskType);
+    Map<TaskState, Integer> taskStateToCountMap = new HashMap<>();
+    for (String taskName : taskStates.keySet()) {
+      TaskState taskState = taskStates.get(taskName);
+      if (!taskStateToCountMap.containsKey(taskState)) {
+        taskStateToCountMap.put(taskState, 0);
+      }
+      taskStateToCountMap.put(taskState, taskStateToCountMap.get(taskState) + 
1);

Review comment:
       `taskStateToCountMap.merge(taskState, 1, Integer::sum);`

##########
File path: 
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotTaskManager.java
##########
@@ -478,4 +489,34 @@ public void cleanUpTask() {
   public Scheduler getScheduler() {
     return _scheduledExecutorService;
   }
+
+  public synchronized void reportMetrics(String taskType) {
+    Map<String, TaskState> taskStates = 
_helixTaskResourceManager.getTaskStates(taskType);
+    Map<TaskState, Integer> taskStateToCountMap = new HashMap<>();
+    for (String taskName : taskStates.keySet()) {

Review comment:
       Use `taskStates.entrySet()` to avoid the extra lookup

##########
File path: 
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotTaskManager.java
##########
@@ -369,6 +377,7 @@ public void registerTaskGenerator(PinotTaskGenerator 
taskGenerator) {
       String taskType = entry.getKey();
       List<TableConfig> enabledTableConfigs = entry.getValue();
       PinotTaskGenerator taskGenerator = 
_taskGeneratorRegistry.getTaskGenerator(taskType);
+      scheduleTaskTypeMetricsUpdaterIfNeeded(taskType);

Review comment:
       Move this after line 382. We need to ensure the task queue exists before 
setting up the metrics updater. Same for other places

##########
File path: 
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotTaskManager.java
##########
@@ -478,4 +489,34 @@ public void cleanUpTask() {
   public Scheduler getScheduler() {
     return _scheduledExecutorService;
   }
+
+  public synchronized void reportMetrics(String taskType) {
+    Map<String, TaskState> taskStates = 
_helixTaskResourceManager.getTaskStates(taskType);
+    Map<TaskState, Integer> taskStateToCountMap = new HashMap<>();
+    for (String taskName : taskStates.keySet()) {
+      TaskState taskState = taskStates.get(taskName);
+      if (!taskStateToCountMap.containsKey(taskState)) {
+        taskStateToCountMap.put(taskState, 0);
+      }
+      taskStateToCountMap.put(taskState, taskStateToCountMap.get(taskState) + 
1);
+    }
+    // Reset all the status to 0
+    for (TaskState taskState : _taskStateToCountMap.keySet()) {
+      _taskStateToCountMap.put(taskState, 0);
+    }
+    _taskStateToCountMap.putAll(taskStateToCountMap);
+    for (TaskState taskState : _taskStateToCountMap.keySet()) {
+      _controllerMetrics.setValueOfTableGauge(String.format("%s.%s", taskType, 
taskState), ControllerGauge.TASK_STATUS,
+          _taskStateToCountMap.get(taskState));
+    }
+  }
+
+  private synchronized void scheduleTaskTypeMetricsUpdaterIfNeeded(String 
taskType) {

Review comment:
       `addTaskTypeMetricsUpdaterIfNeeded`?

##########
File path: 
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotTaskManager.java
##########
@@ -478,4 +489,34 @@ public void cleanUpTask() {
   public Scheduler getScheduler() {
     return _scheduledExecutorService;
   }
+
+  public synchronized void reportMetrics(String taskType) {
+    Map<String, TaskState> taskStates = 
_helixTaskResourceManager.getTaskStates(taskType);
+    Map<TaskState, Integer> taskStateToCountMap = new HashMap<>();
+    for (String taskName : taskStates.keySet()) {
+      TaskState taskState = taskStates.get(taskName);
+      if (!taskStateToCountMap.containsKey(taskState)) {
+        taskStateToCountMap.put(taskState, 0);
+      }
+      taskStateToCountMap.put(taskState, taskStateToCountMap.get(taskState) + 
1);
+    }
+    // Reset all the status to 0
+    for (TaskState taskState : _taskStateToCountMap.keySet()) {
+      _taskStateToCountMap.put(taskState, 0);
+    }
+    _taskStateToCountMap.putAll(taskStateToCountMap);
+    for (TaskState taskState : _taskStateToCountMap.keySet()) {

Review comment:
       Use `taskStates.entrySet()` to avoid the extra lookup

##########
File path: 
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotTaskManager.java
##########
@@ -478,4 +489,34 @@ public void cleanUpTask() {
   public Scheduler getScheduler() {
     return _scheduledExecutorService;
   }
+
+  public synchronized void reportMetrics(String taskType) {
+    Map<String, TaskState> taskStates = 
_helixTaskResourceManager.getTaskStates(taskType);
+    Map<TaskState, Integer> taskStateToCountMap = new HashMap<>();
+    for (String taskName : taskStates.keySet()) {
+      TaskState taskState = taskStates.get(taskName);
+      if (!taskStateToCountMap.containsKey(taskState)) {
+        taskStateToCountMap.put(taskState, 0);
+      }
+      taskStateToCountMap.put(taskState, taskStateToCountMap.get(taskState) + 
1);
+    }
+    // Reset all the status to 0
+    for (TaskState taskState : _taskStateToCountMap.keySet()) {

Review comment:
       No need to maintain the member `_taskStateToCountMap`, the local map 
should be enough.




----------------------------------------------------------------
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.

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