You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "JackieTien97 (via GitHub)" <gi...@apache.org> on 2026/10/21 06:57:57 UTC

[PR] [Metrics] Fix concurrent Prometheus scrapes and disk sampling [iotdb]

JackieTien97 opened a new pull request, #18957:
URL: https://github.com/apache/iotdb/pull/18957

   ## Description
   
   Initial Prometheus requests and scheduled snapshot refreshes can collect stateful gauges concurrently. This was identified while investigating [a 1C3D CI failure](https://github.com/apache/iotdb/actions/runs/39541561392/job/119030246374?pr=18952), where `disk_io_busy_percentage` was exported as `NaN` and rejected by the integration test's format validator.
   
   - Serialize metric collection and snapshot publication using a dedicated lock. First requests recheck the cache after acquiring it; requests with an existing snapshot retain the fast, lock-free read path.
   - Protect Linux disk refreshes and reads with the same monitor, return copies of counter maps, and reuse the timestamp checked for refresh eligibility. Zero or backward elapsed intervals retain the previous sample instead of reaching the rate calculation.
   - Accept the Prometheus text format's valid `NaN`, `+Inf`, and `-Inf` sample values in the integration-test validator while continuing to reject malformed values.
   
   The regression tests control overlapping collection calls, exercise snapshot initialization/removal, and test Linux disk sampling with temporary proc/sys fixtures and a controlled clock.
   
   ## Validation
   
   All checks below passed locally on macOS arm64 with Corretto JDK 17:
   - Clean reactor unit-test build for `PrometheusReporterTest` and `LinuxDiskMetricsManagerTest`: **9 tests passed**.
   - Clean `ClusterIT` / `with-integration-tests` verify for `IoTDBMetricIT` and `IoTDBMetricFormatIT`: **4 tests passed**, including the original failing method.
   - Full-reactor `mvn test-compile -DskipTests`.
   - Full-reactor `mvn test-compile -DskipTests -P with-zh-locale`.
   - Spotless and `git diff --check`.
   
   The four new Prometheus concurrency tests were also run against the pre-fix reporter: all four failed, then passed with this change. Local integration verification used an external RAT exclusion file to omit pre-existing, untracked `diagrams/` SVG files; repository license configuration is unchanged.
   
   This PR has:
   - [x] been self-reviewed, including concurrent reads and writes.
   - [x] added unit and integration regression tests.
   - [x] been tested in a 1 ConfigNode / 3 DataNode cluster.
   
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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


Re: [PR] [Metrics] Fix concurrent Prometheus scrapes and disk sampling [iotdb]

Posted by "JackieTien97 (via GitHub)" <gi...@apache.org>.
JackieTien97 merged PR #18957:
URL: https://github.com/apache/iotdb/pull/18957


-- 
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: reviews-unsubscribe@iotdb.apache.org

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


Re: [PR] [Metrics] Fix concurrent Prometheus scrapes and disk sampling [iotdb]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #18957:
URL: https://github.com/apache/iotdb/pull/18957#issuecomment-6311324406

   ## [Codecov](https://app.codecov.io/gh/apache/iotdb/pull/18957?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `50.00000%` with `27 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 47.15%. Comparing base ([`83d4197`](https://app.codecov.io/gh/apache/iotdb/commit/83d419796fb91a6cccb874414820d3865ab34b98?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`e7230ea`](https://app.codecov.io/gh/apache/iotdb/commit/e7230eabe108a1667d28bf8609a923b56c4a6e23?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 8 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/iotdb/pull/18957?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...trics/metricsets/disk/LinuxDiskMetricsManager.java](https://app.codecov.io/gh/apache/iotdb/pull/18957?src=pr&el=tree&filepath=iotdb-core%2Fmetrics%2Finterface%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fiotdb%2Fmetrics%2Fmetricsets%2Fdisk%2FLinuxDiskMetricsManager.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aW90ZGItY29yZS9tZXRyaWNzL2ludGVyZmFjZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW90ZGIvbWV0cmljcy9tZXRyaWNzZXRzL2Rpc2svTGludXhEaXNrTWV0cmljc01hbmFnZXIuamF2YQ==) | 37.20% | [27 Missing :warning: ](https://app.codecov.io/gh/apache/iotdb/pull/18957?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #18957      +/-   ##
   ============================================
   + Coverage     47.08%   47.15%   +0.07%     
   - Complexity      737      787      +50     
   ============================================
     Files          5539     5539              
     Lines        405217   405248      +31     
     Branches      53029    53030       +1     
   ============================================
   + Hits         190777   191079     +302     
   + Misses       214440   214169     -271     
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/iotdb/pull/18957?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   </details>


-- 
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: reviews-unsubscribe@iotdb.apache.org

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


Re: [PR] [Metrics] Fix concurrent Prometheus scrapes and disk sampling [iotdb]

Posted by "JackieTien97 (via GitHub)" <gi...@apache.org>.
JackieTien97 commented on code in PR #18957:
URL: https://github.com/apache/iotdb/pull/18957#discussion_r4333959836


##########
integration-test/src/test/java/org/apache/iotdb/db/it/metric/IoTDBMetricFormatIT.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.it.metric;
+
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({LocalStandaloneIT.class, ClusterIT.class})
+public class IoTDBMetricFormatIT {
+  private static final String SAMPLE =
+      "disk_io_busy_percentage{cluster=\"defaultCluster\",nodeType=\"CONFIGNODE\",nodeId=\"0\",disk_id=\"vda\",} ";
+
+  @Test
+  public void testValidSampleValues() {
+    for (String value : new String[] {"NaN", "+Inf", "-Inf", "0", "-0.25", "1.0e-3"}) {
+      assertTrue(value, IoTDBMetricIT.isValidPrometheusTextFormat(SAMPLE + value));
+    }
+  }
+
+  @Test
+  public void testInvalidSampleValues() {
+    for (String value : new String[] {"", "Infinity", "null", "1.0garbage"}) {
+      assertFalse(value, IoTDBMetricIT.isValidPrometheusTextFormat(SAMPLE + value));

Review Comment:
   [P2] Treat Infinity as a valid Prometheus sample value
   
   Please move `Infinity` to the valid-value cases, include `-Infinity`, and extend `METRIC_LINE_REGEX` accordingly. The [Prometheus text format](https://prometheus.io/docs/instrumenting/exposition_formats/#text-format-details) uses Go's `ParseFloat` rules, which explicitly [accept optionally signed `Infinity`](https://pkg.go.dev/strconv#ParseFloat). This also matches IoTDB's actual exporter: `PrometheusTextWriter.writeSample()` calls `value.toString()`, so gauges returning `Double.POSITIVE_INFINITY` or `Double.NEGATIVE_INFINITY` emit `Infinity` or `-Infinity`, not `+Inf` or `-Inf`. I reproduced both round trips through the actual reporter and `isValidPrometheusTextFormat()`; both are rejected. Although the regex already lacked these forms before this PR, this new negative test now enforces that incorrect expectation, leaving valid exporter output capable of causing false IT failures.



-- 
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: reviews-unsubscribe@iotdb.apache.org

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