Copilot commented on code in PR #18708:
URL: https://github.com/apache/iotdb/pull/18708#discussion_r4085278006


##########
iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/prometheus/PrometheusReporter.java:
##########
@@ -189,9 +154,68 @@ public synchronized boolean start() {
     return true;
   }
 
+  private HttpServer createHttpServer() throws Exception {
+    InetSocketAddress address = new 
InetSocketAddress(METRIC_CONFIG.getPrometheusReporterPort());
+    if (!METRIC_CONFIG.isEnableSSL()) {
+      return HttpServer.create(address, 0);
+    }
+
+    SSLContext sslContext =
+        createSslContext(
+            METRIC_CONFIG.getKeyStorePath(),
+            METRIC_CONFIG.getKeyStorePassword(),
+            METRIC_CONFIG.getTrustStorePath(),
+            METRIC_CONFIG.getTrustStorePassword());
+    HttpsServer httpsServer = HttpsServer.create(address, 0);
+    httpsServer.setHttpsConfigurator(
+        new HttpsConfigurator(sslContext) {
+          @Override
+          public void configure(HttpsParameters parameters) {
+            SSLParameters sslParameters = sslContext.getDefaultSSLParameters();
+            sslParameters.setNeedClientAuth(true);
+            parameters.setSSLParameters(sslParameters);
+          }
+        });
+    return httpsServer;
+  }
+
+  private ExecutorService newHttpExecutor() {
+    return Executors.newFixedThreadPool(
+        PROMETHEUS_HTTP_SERVER_WORKER_THREADS,

Review Comment:
   This two-thread pool services both synchronous metric collection and 
blocking socket writes. Two slow/non-reading clients can occupy both workers in 
`OutputStream.write`, while every later Prometheus scrape accumulates in the 
fixed pool's unbounded queue; this regresses the nonblocking Reactor endpoint 
into an easily stalled endpoint. Please use a server/executor strategy with 
bounded queuing and request/write timeouts (and enough isolation for scrapes).



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/concurrent/ThreadName.java:
##########
@@ -192,9 +192,7 @@ public enum ThreadName {
   SYSTEM_SCHEDULE_METRICS("SystemScheduleMetrics"),
   RESOURCE_CONTROL_DISK_STATISTIC("ResourceControl-DataRegionDiskStatistics"),
   PROMETHEUS_REPORTER_SNAPSHOT_UPDATER("PrometheusReporter-Snapshot-Updater"),
-  PROMETHEUS_REACTOR_HTTP_EPOLL("reactor-http-epoll"),
-  PROMETHEUS_REACTOR_HTTP_NIO("reactor-http-nio"),
-  PROMETHEUS_BOUNDED_ELASTIC("boundedElastic-evictor"),
+  PROMETHEUS_REPORTER_HTTP("prometheus-reporter-http"),

Review Comment:
   `HttpServer.start()` also creates an internal thread named 
`HTTP-Dispatcher`; that thread does not use the supplied executor/thread 
factory. Registering only `prometheus-reporter-http` therefore leaves part of 
the new Prometheus server classified as `UNKNOWN` by `ThreadName`, so 
thread-pool/module metrics become incomplete. Please classify the dispatcher 
thread as metrics as well (or provide another way to account for it).



##########
iotdb-core/metrics/interface/src/test/java/org/apache/iotdb/metrics/reporter/prometheus/PrometheusReporterTest.java:
##########
@@ -36,6 +38,31 @@
 
 public class PrometheusReporterTest {
 
+  @Test
+  public void testMetricsEndpoint() throws Exception {
+    MetricConfig metricConfig = 
MetricConfigDescriptor.getInstance().getMetricConfig();
+    boolean originalAsyncUpdate = 
metricConfig.isPrometheusReporterAsyncUpdate();
+    Integer originalPort = metricConfig.getPrometheusReporterPort();
+    metricConfig.setPrometheusReporterAsyncUpdate(false);
+    metricConfig.setPrometheusReporterPort(0);
+
+    PrometheusReporter reporter = new PrometheusReporter(new 
DoNothingMetricManager());
+    try {
+      assertTrue(reporter.start());
+      HttpURLConnection connection =
+          (HttpURLConnection)
+              new URL("http://127.0.0.1:"; + reporter.getListeningPort() + 
"/metrics")
+                  .openConnection();
+      connection.setRequestMethod("GET");
+      assertEquals(200, connection.getResponseCode());
+      assertEquals("text/plain", connection.getHeaderField("Content-Type"));

Review Comment:
   The replacement test covers only unauthenticated plaintext HTTP, although 
this change rewrites the Basic-auth path and the entire TLS/mTLS setup. Add 
endpoint tests for unauthorized/authorized Basic requests and for a trusted 
versus untrusted client certificate so the behaviors called out as preserved 
cannot silently regress.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to