praveenc7 commented on code in PR #15716:
URL: https://github.com/apache/pinot/pull/15716#discussion_r2080645156


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/ControllerAdminApiApplication.java:
##########
@@ -130,4 +140,54 @@ public void filter(ContainerRequestContext 
containerRequestContext,
   public HttpServer getHttpServer() {
     return _httpServer;
   }
+
+  /**
+    * Registers a gauge that tracks HTTP thread pool utilization without using 
reflection.
+    * Instead, it uses a custom ThreadPoolProbe to count active threads.
+   */
+  public void registerHttpThreadUtilizationGauge(ControllerMetrics metrics) {
+    NetworkListener listener = _httpServer.getListeners().iterator().next();
+    ExecutorService executor = listener.getTransport().getWorkerThreadPool();
+    ThreadPoolConfig poolCfg = 
listener.getTransport().getWorkerThreadPoolConfig();
+
+    ActiveThreadProbe probe = new ActiveThreadProbe();
+    // Try to attach probe to the executor if it supports monitoring
+    if (executor instanceof MonitoringAware) {
+      @SuppressWarnings("unchecked")
+      MonitoringConfig<ThreadPoolProbe> mc = 
((MonitoringAware<ThreadPoolProbe>) executor).getMonitoringConfig();
+      mc.addProbes(probe);
+    }
+
+    
metrics.setOrUpdateGauge(ControllerGauge.HTTP_THREAD_UTILIZATION_PERCENT.getGaugeName(),
 () -> {
+      int max = poolCfg.getMaxPoolSize();
+      if (max <= 0) {
+        return 0L;
+      }
+      return Math.round(probe.getActiveCount() * 100.0 / max);
+    });
+  }
+
+  /**
+   * Custom probe to track busy threads in Grizzly thread pools without using 
reflection.
+   */
+  public static final class ActiveThreadProbe extends ThreadPoolProbe.Adapter {

Review Comment:
   The JVM reports the current number of active threads, but I haven’t found a 
reliable way to translate that into actual thread‑pool utilization. In 
addition, the metric aggregates all pools—Grizzly, Jetty, and others—so we 
can’t isolate Grizzly’s load, even though it is the pool that mostly handles 
schema and table operations on the controller for upstream clients.



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to