OneSizeFitsQuorum commented on code in PR #11378:
URL: https://github.com/apache/iotdb/pull/11378#discussion_r1371077061


##########
iotdb-core/metrics/interface/src/test/java/org/apache/iotdb/metrics/config/MetricConfigTest.java:
##########
@@ -54,7 +53,7 @@ public void testConfigNodeMetricConfig() {
     MetricConfig metricConfig = 
MetricConfigDescriptor.getInstance().getMetricConfig();
 
     assertEquals(3, metricConfig.getMetricReporterList().size());
-    assertEquals(MetricFrameType.DROPWIZARD, 
metricConfig.getMetricFrameType());
+    //    assertEquals(MetricFrameType.DROPWIZARD, 
metricConfig.getMetricFrameType());

Review Comment:
   remove this line?



##########
iotdb-core/metrics/interface/src/test/java/org/apache/iotdb/metrics/config/MetricConfigTest.java:
##########
@@ -93,7 +92,7 @@ public void testDataNodeMetricConfig() {
     MetricConfig metricConfig = 
MetricConfigDescriptor.getInstance().getMetricConfig();
 
     assertEquals(3, metricConfig.getMetricReporterList().size());
-    assertEquals(MetricFrameType.DROPWIZARD, 
metricConfig.getMetricFrameType());
+    //    assertEquals(MetricFrameType.DROPWIZARD, 
metricConfig.getMetricFrameType());

Review Comment:
   remove this line?
   



##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metric/MetricServiceTest.java:
##########
@@ -55,30 +50,31 @@ public class MetricServiceTest {
       MetricConfigDescriptor.getInstance().getMetricConfig();
   private static AbstractMetricService metricService = new 
DoNothingMetricService();
 
-  @Test
-  public void testMetricService() {
-    for (MetricFrameType type : MetricFrameType.values()) {
-      // init metric service
-      metricConfig.setMetricFrameType(type);
-      metricConfig.setMetricLevel(MetricLevel.IMPORTANT);
-      metricService = new DoNothingMetricService();
-      metricService.startService();
-
-      // test metric service
-      
assertTrue(metricService.getMetricManager().isEnableMetricInGivenLevel(MetricLevel.CORE));
-      assertTrue(
-          
metricService.getMetricManager().isEnableMetricInGivenLevel(MetricLevel.IMPORTANT));
-      
assertFalse(metricService.getMetricManager().isEnableMetricInGivenLevel(MetricLevel.NORMAL));
-      
assertFalse(metricService.getMetricManager().isEnableMetricInGivenLevel(MetricLevel.ALL));
-
-      testNormalSituation();
-
-      testOtherSituation();
-
-      // stop metric module
-      metricService.stopService();
-    }
-  }
+  //  @Test
+  //  public void testMetricService() {

Review Comment:
   Do not comment test.
   BTW, I think this test(line58 - line 75) is still useful 



##########
iotdb-core/metrics/core/src/main/java/org/apache/iotdb/metrics/core/type/IoTDBCounter.java:
##########
@@ -17,29 +17,35 @@
  * under the License.
  */
 
-package org.apache.iotdb.metrics.micrometer.type;
+package org.apache.iotdb.metrics.core.type;
 
 import org.apache.iotdb.metrics.type.Counter;
 
-public class MicrometerCounter implements Counter {
+import java.util.concurrent.atomic.LongAdder;
+
+public class IoTDBCounter implements Counter {
+  private final LongAdder count;
+  // Here we retain the micrometer counter variable in order to use its naming 
system within
+  // micrometer.
   io.micrometer.core.instrument.Counter counter;

Review Comment:
   If we just want to use its naming system, do we need to hold a reference 
here? Seems that it is never used?



##########
iotdb-core/metrics/pom.xml:
##########
@@ -31,8 +31,8 @@
     <name>IoTDB: Core: Metrics</name>
     <description>Metrics interfaces for IoTDB</description>
     <modules>
+        <module>core</module>
         <module>interface</module>
-        <module>micrometer-metrics</module>
         <module>dropwizard-metrics</module>

Review Comment:
   How about just removing whole dropwizard-metrics module



##########
iotdb-core/metrics/core/src/main/java/org/apache/iotdb/metrics/core/uitls/IoTDBCachedGauge.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.metrics.core.uitls;
+
+import org.apache.iotdb.metrics.type.AutoGauge;
+
+import com.codahale.metrics.Clock;
+
+import java.lang.ref.WeakReference;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.ToDoubleFunction;
+
+/**
+ * Gauges with cache, which have better performance in some read-intensive and 
calculation-intensive
+ * scenarios. Can be served as an additional option.
+ */
+public class IoTDBCachedGauge<T> implements AutoGauge {
+  /** The timer of metric system */
+  private final Clock clock;
+  /** The time to reload cache */
+  private final AtomicLong reloadAt;
+  /** The timeout duration */
+  private final long timeoutNS;
+  /** The cache's value */
+  private final AtomicReference<Double> value;
+  /** The reference object of gauge */
+  private final WeakReference<T> refObj;
+  /** The calculate function of gauge */
+  private final ToDoubleFunction<T> mapper;
+
+  protected IoTDBCachedGauge(
+      WeakReference<T> refObj, ToDoubleFunction<T> mapper, long timeout, 
TimeUnit timeoutUnit) {
+    this(Clock.defaultClock(), refObj, mapper, timeout, timeoutUnit);
+  }
+
+  protected IoTDBCachedGauge(
+      Clock clock,
+      WeakReference<T> refObj,
+      ToDoubleFunction<T> mapper,
+      long timeout,
+      TimeUnit timeoutUnit) {
+    this.clock = clock;
+    this.refObj = refObj;
+    this.mapper = mapper;
+    this.reloadAt = new AtomicLong(clock.getTick());
+    this.timeoutNS = timeoutUnit.toNanos(timeout);
+    this.value = new AtomicReference<>();
+  }
+
+  @Override
+  public double value() {
+    return getValue();
+  }
+
+  private double loadValue() {
+    if (refObj.get() == null) {
+      return 0d;
+    }
+    return mapper.applyAsDouble(refObj.get());
+  }
+
+  public double getValue() {
+    Double currentValue = this.value.get();
+    // if cache expires or is not loaded, we update the cache with calculate 
function
+    if (shouldLoad() || currentValue == null) {
+      double newValue = loadValue();
+      if (!this.value.compareAndSet(currentValue, newValue)) {
+        return this.value.get();
+      }
+      return newValue;
+    }
+    // else we directly return the cache's value
+    return currentValue;
+  }
+
+  private boolean shouldLoad() {
+    while (true) {
+      final long time = clock.getTick();
+      final long current = reloadAt.get();
+      if (current > time) {
+        return false;
+      }
+      if (reloadAt.compareAndSet(current, time + timeoutNS)) {

Review Comment:
   Perhaps when time is much larger than current (e.g., many times we have not 
come to get), we still only have cas once instead of multiple times



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