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

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

Reply via email to