jt2594838 commented on code in PR #18562:
URL: https://github.com/apache/iotdb/pull/18562#discussion_r3902819315


##########
iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/config/MetricConfig.java:
##########
@@ -52,6 +52,9 @@ public class MetricConfig {
   /** The export port for prometheus to get metrics. */
   private Integer prometheusReporterPort = 9091;
 
+  /** Whether Prometheus metrics are collected asynchronously into a cached 
snapshot. */
+  private boolean prometheusReporterAsyncUpdate = true;

Review Comment:
   Adds the default-on feature flag to the shared metric configuration so async 
snapshot behavior is explicit, reloadable, and included in configuration 
equality and hash state.



##########
iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/config/MetricConfigDescriptor.java:
##########
@@ -112,6 +112,11 @@ private MetricConfig generateFromProperties(Properties 
properties, boolean isCon
                 properties,
                 isConfigNode)));
 
+    loadConfig.setPrometheusReporterAsyncUpdate(

Review Comment:
   Loads the new switch while accepting the global and legacy metric-prefixed 
forms, preserving compatibility with existing node configuration conventions.



##########
iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/prometheus/PrometheusReporter.java:
##########
@@ -122,9 +144,20 @@ public boolean start() {
         serverTransport = serverTransport.secure(spec -> 
spec.sslContext(sslContext));
       }
       httpServer = serverTransport.bindNow();
+      if (METRIC_CONFIG.isPrometheusReporterAsyncUpdate()) {

Review Comment:
   Starts the periodic snapshot task only for async mode; synchronous mode 
continues to scrape on demand, while the cached response keeps Reactor request 
threads independent of expensive metric collection.



##########
iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/prometheus/PrometheusReporter.java:
##########
@@ -318,7 +390,8 @@ private SslContext createSslContext(
   }
 
   @Override
-  public boolean stop() {
+  public synchronized boolean stop() {
+    stopSnapshotUpdater();

Review Comment:
   Stops and disposes the snapshot task with the reporter so reloads, shutdown, 
and failed starts do not leave a scheduler behind.



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/metric/MetricService.java:
##########
@@ -74,7 +76,15 @@ protected void loadReporter() {
           hasJmxReporter = true;
           break;
         case PROMETHEUS:
-          reporter = new PrometheusReporter(metricManager);
+          if (METRIC_CONFIG.isPrometheusReporterAsyncUpdate()) {

Review Comment:
   Creates the IoTDB-managed scheduler only when async snapshot updates are 
enabled; the disabled path now constructs the synchronous reporter without 
allocating a thread pool.



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/concurrent/ThreadName.java:
##########
@@ -191,6 +191,7 @@ public enum ThreadName {
   // -------------------------- Metrics --------------------------
   SYSTEM_SCHEDULE_METRICS("SystemScheduleMetrics"),
   RESOURCE_CONTROL_DISK_STATISTIC("ResourceControl-DataRegionDiskStatistics"),
+  PROMETHEUS_REPORTER_SNAPSHOT_UPDATER("PrometheusReporter-Snapshot-Updater"),

Review Comment:
   Registers a stable thread name for the snapshot updater and includes it in 
the metrics thread classification so the new background work remains observable.



##########
iotdb-core/metrics/interface/src/test/java/org/apache/iotdb/metrics/config/MetricConfigTest.java:
##########
@@ -55,6 +56,7 @@ public void testConfigNodeMetricConfig() {
     assertEquals(MetricLevel.ALL, metricConfig.getMetricLevel());
     assertEquals(10, (int) metricConfig.getAsyncCollectPeriodInSecond());
     assertEquals(9090, (int) metricConfig.getPrometheusReporterPort());
+    assertEquals(false, metricConfig.isPrometheusReporterAsyncUpdate());

Review Comment:
   Covers parsing the explicitly disabled setting; the companion DataNode 
assertion verifies the enabled value and protects the default/alias behavior.



##########
iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template:
##########
@@ -382,6 +382,12 @@ metric_prometheus_reporter_username=
 # Datatype: String
 metric_prometheus_reporter_password=
 
+# Whether Prometheus metrics are collected asynchronously and served from a 
cached snapshot.
+# The snapshot is refreshed every 15 seconds, matching Prometheus's default 
scrape interval.
+# effectiveMode: restart
+# Datatype: boolean
+prometheus_reporter_async_update=true

Review Comment:
   Documents the default-enabled switch, its 15-second refresh cadence, and 
restart semantics in the shipped configuration template.



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