You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "Pengzna (via GitHub)" <gi...@apache.org> on 2024/10/18 08:04:40 UTC

[PR] Metric: discard error metric when taking snapthot [iotdb]

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

   as title


-- 
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] Metric: Discard Error Metric When Taking Snapthot [iotdb]

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


-- 
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] Metric: Discard Error Metric When Taking Snapthot [iotdb]

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


##########
iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/prometheus/PrometheusReporter.java:
##########
@@ -144,6 +145,10 @@ private String scrape() {
         } else if (metric instanceof Timer) {
           Timer timer = (Timer) metric;
           HistogramSnapshot snapshot = timer.takeSnapshot();
+          if (Objects.isNull(snapshot)) {
+            LOGGER.warn("Detected an error when taking snapshot, will discard this metric");

Review Comment:
   ```suggestion
               LOGGER.warn("Detected an error when taking metric timer snapshot, will discard this metric");
   ```



##########
iotdb-core/metrics/core/src/main/java/org/apache/iotdb/metrics/core/type/IoTDBTimer.java:
##########
@@ -40,37 +45,73 @@ public void update(long duration, TimeUnit unit) {
 
   @Override
   public HistogramSnapshot takeSnapshot() {
-    return new IoTDBTimerHistogramSnapshot(timer);
+    try {
+      return new IoTDBTimerHistogramSnapshot(timer);
+    } catch (ArrayIndexOutOfBoundsException e) {
+      LOGGER.warn(
+          "Detected an error while taking snapshot, may cause a miss during this recording.", e);
+      return null;
+    }
   }
 
   @Override
   public double getSum() {
-    return this.takeSnapshot().getSum();
+    HistogramSnapshot snapshot = this.takeSnapshot();

Review Comment:
   ```
   return Optional.ofNullable(takeSnapshot()).map(HistogramSnapshot::getSum).orElse(0.0);
   ```
   use this as you already log in `takeSnapshot`?



-- 
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] Metric: Discard Error Metric When Taking Snapthot [iotdb]

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


##########
iotdb-core/metrics/core/src/main/java/org/apache/iotdb/metrics/core/type/IoTDBTimer.java:
##########
@@ -40,37 +45,73 @@ public void update(long duration, TimeUnit unit) {
 
   @Override
   public HistogramSnapshot takeSnapshot() {
-    return new IoTDBTimerHistogramSnapshot(timer);
+    try {
+      return new IoTDBTimerHistogramSnapshot(timer);
+    } catch (ArrayIndexOutOfBoundsException e) {
+      LOGGER.warn(
+          "Detected an error while taking snapshot, may cause a miss during this recording.", e);
+      return null;
+    }
   }
 
   @Override
   public double getSum() {
-    return this.takeSnapshot().getSum();
+    HistogramSnapshot snapshot = this.takeSnapshot();

Review Comment:
   elegant! fixed



-- 
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] Metric: Discard Error Metric When Taking Snapthot [iotdb]

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


##########
iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/prometheus/PrometheusReporter.java:
##########
@@ -144,6 +145,10 @@ private String scrape() {
         } else if (metric instanceof Timer) {
           Timer timer = (Timer) metric;
           HistogramSnapshot snapshot = timer.takeSnapshot();
+          if (Objects.isNull(snapshot)) {
+            LOGGER.warn("Detected an error when taking snapshot, will discard this metric");

Review Comment:
   applied



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