KYLIN-2776 Using dropwizard as default metric framework
modify comment code


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/b778f33a
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/b778f33a
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/b778f33a

Branch: refs/heads/master
Commit: b778f33af3718fd1bf5f705b81104f424803fe78
Parents: fad75c9
Author: yiming.xu <100650...@qq.com>
Authored: Mon Aug 28 12:57:10 2017 +0800
Committer: Hongbin Ma <m...@kyligence.io>
Committed: Mon Aug 28 13:50:36 2017 +0800

----------------------------------------------------------------------
 .../apache/kylin/common/KylinConfigBase.java    |  4 ++
 .../kylin/common/metrics/common/Metrics.java    | 40 ++++++++-------
 .../common/metrics/common/MetricsConstant.java  |  2 +-
 .../common/metrics/common/MetricsFactory.java   |  2 +-
 .../metrics/common/MetricsNameBuilder.java      | 38 ++++++++++++++
 .../common/metrics/common/MetricsScope.java     |  8 +--
 .../kylin/common/metrics/common/Metricss.java   | 40 ---------------
 .../metrics/metrics2/CodahaleMetrics.java       | 20 ++++----
 .../metrics2/ConsoleMetricsReporter.java        |  2 +-
 .../metrics/metrics2/JmxMetricsReporter.java    |  2 +-
 .../metrics2/MetricVariableRatioGauge.java      |  2 +-
 .../metrics/metrics2/Metrics2Reporter.java      |  2 +-
 .../metrics/metrics2/MetricsReporting.java      |  3 --
 .../common/metrics/perflog/PerfLogger.java      |  3 +-
 .../kylin/rest/metrics/QueryMetrics2Facade.java | 20 ++++----
 .../kylin/rest/metrics/QueryMetrics2Test.java   | 52 ++++++++++----------
 16 files changed, 122 insertions(+), 118 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java 
b/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
index 99b9bb2..bca00e7 100644
--- a/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
+++ b/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
@@ -1149,6 +1149,10 @@ abstract public class KylinConfigBase implements 
Serializable {
         return 
Boolean.parseBoolean(getOptional("kylin.server.query-metrics-enabled", 
"false"));
     }
 
+    public boolean getQueryMetrics2Enabled() {
+        return 
Boolean.parseBoolean(getOptional("kylin.server.query-metrics2-enabled", 
"false"));
+    }
+
     public int[] getQueryMetricsPercentilesIntervals() {
         String[] dft = { "60", "300", "3600" };
         return 
getOptionalIntArray("kylin.server.query-metrics-percentiles-intervals", dft);

http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/core-common/src/main/java/org/apache/kylin/common/metrics/common/Metrics.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/metrics/common/Metrics.java 
b/core-common/src/main/java/org/apache/kylin/common/metrics/common/Metrics.java
index dcda3cd..9bf8e7a 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/metrics/common/Metrics.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/metrics/common/Metrics.java
@@ -17,13 +17,13 @@
 */
 package org.apache.kylin.common.metrics.common;
 
+import java.util.concurrent.TimeUnit;
+
 import com.codahale.metrics.Counter;
 import com.codahale.metrics.Histogram;
 import com.codahale.metrics.Meter;
 import com.codahale.metrics.Timer;
 
-import java.util.concurrent.TimeUnit;
-
 /**
  * Generic Metics interface.
  */
@@ -35,7 +35,6 @@ public interface Metrics {
     public void close() throws Exception;
 
     /**
-     *
      * @param name starts a scope of a given name.  Scopes is stored as 
thread-local variable.
      */
     public void startStoredScope(String name);
@@ -43,12 +42,14 @@ public interface Metrics {
     /**
      * Closes the stored scope of a given name.
      * Note that this must be called on the same thread as where the scope was 
started.
+     *
      * @param name
      */
     public void endStoredScope(String name);
 
     /**
      * Create scope with given name and returns it.
+     *
      * @param name
      * @return
      */
@@ -56,6 +57,7 @@ public interface Metrics {
 
     /**
      * Close the given scope.
+     *
      * @param scope
      */
     public void endScope(MetricsScope scope);
@@ -64,6 +66,7 @@ public interface Metrics {
 
     /**
      * Increments a counter of the given name by 1.
+     *
      * @param name
      * @return
      */
@@ -71,6 +74,7 @@ public interface Metrics {
 
     /**
      * Increments a counter of the given name by "increment"
+     *
      * @param name
      * @param increment
      * @return
@@ -79,6 +83,7 @@ public interface Metrics {
 
     /**
      * Decrements a counter of the given name by 1.
+     *
      * @param name
      * @return
      */
@@ -86,6 +91,7 @@ public interface Metrics {
 
     /**
      * Decrements a counter of the given name by "decrement"
+     *
      * @param name
      * @param decrement
      * @return
@@ -94,15 +100,17 @@ public interface Metrics {
 
     /**
      * Adds a metrics-gauge to track variable.  For example, number of open 
database connections.
-     * @param name name of gauge
+     *
+     * @param name     name of gauge
      * @param variable variable to track.
      */
     public void addGauge(String name, final MetricsVariable variable);
 
     /**
      * Add a ratio metric to track the correlation between two variables
-     * @param name name of the ratio gauge
-     * @param numerator numerator of the ratio
+     *
+     * @param name        name of the ratio gauge
+     * @param numerator   numerator of the ratio
      * @param denominator denominator of the ratio
      */
     public void addRatio(String name, MetricsVariable<Integer> numerator, 
MetricsVariable<Integer> denominator);
@@ -110,51 +118,45 @@ public interface Metrics {
     /**
      * Mark an event occurance for a meter. Meters measure the rate of an 
event and track
      * 1/5/15 minute moving averages
+     *
      * @param name name of the meter
      */
     public void markMeter(String name);
 
     /**
-     *
-     * @param name         name of the Timer
+     * @param name     name of the Timer
      * @param duration
      * @param unit
      */
 
     public void updateTimer(String name, long duration, TimeUnit unit);
 
-
     /**
-     *
-     * @param name        name of the histogram
+     * @param name  name of the histogram
      * @param count
      */
     public void updateHistogram(String name, long count);
 
     /**
-     *
-     * @param name      name of the time
+     * @param name name of the time
      * @return
      */
     public Timer getTimer(String name);
 
     /**
-     *
-     * @param name      name of the counter
+     * @param name name of the counter
      * @return
      */
     public Counter getCounter(String name);
 
     /**
-     *
-     * @param name      name of the time
+     * @param name name of the time
      * @return
      */
     public Histogram getHistogram(String name);
 
     /**
-     *
-     * @param name      name of the meter
+     * @param name name of the meter
      * @return
      */
     public Meter getMeter(String name);

http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsConstant.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsConstant.java
 
b/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsConstant.java
index 49c8d8e..1e7cdae 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsConstant.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsConstant.java
@@ -18,7 +18,7 @@
 package org.apache.kylin.common.metrics.common;
 
 /**
- * This class defines some metrics generated by Hive processes.
+ * This class defines some metrics generated by Kylin processes.
  */
 public class MetricsConstant {
 

http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsFactory.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsFactory.java
 
b/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsFactory.java
index ff0ab7d..269c7dc 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsFactory.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsFactory.java
@@ -18,7 +18,6 @@
 
 package org.apache.kylin.common.metrics.common;
 
-
 import org.apache.kylin.common.metrics.metrics2.CodahaleMetrics;
 
 /**
@@ -29,6 +28,7 @@ public class MetricsFactory {
     //Volatile ensures that static access returns Metrics instance in 
fully-initialized state.
     //Alternative is to synchronize static access, which has performance 
penalties.
     private volatile static Metrics metrics;
+
     static {
         MetricsFactory.init();
     }

http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsNameBuilder.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsNameBuilder.java
 
b/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsNameBuilder.java
new file mode 100644
index 0000000..656a478
--- /dev/null
+++ 
b/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsNameBuilder.java
@@ -0,0 +1,38 @@
+/*
+ * 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.kylin.common.metrics.common;
+
+public final class MetricsNameBuilder {
+    public final static String METRICS = "metrics:";
+    public final static String PROJECT_TEMPLATE = METRICS + "project=%s";
+    public final static String CUBE_TEMPLATE = METRICS + "project=%s,cube=%s";
+
+    public static String buildMetricName(String prefix, String name) {
+        return String.format(prefix + ",name=%s", name);
+    }
+
+    public static String buildCubeMetricPrefix(String project) {
+        return String.format(PROJECT_TEMPLATE, project);
+    }
+
+    public static String buildCubeMetricPrefix(String project, String cube) {
+        return String.format(CUBE_TEMPLATE, project, cube);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsScope.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsScope.java
 
b/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsScope.java
index 8a72073..19db350 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsScope.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/metrics/common/MetricsScope.java
@@ -19,14 +19,14 @@ package org.apache.kylin.common.metrics.common;
 
 /**
  * Metrics Scope to represent duration of an event.
- *
+ * <p>
  * Implementation can capture information like the average duration of open 
scopes,
  * number of open scopes, number of completed scopes.
- *
+ * <p>
  * Scopes are created via the Metrics framework (see Metrics#createScope or 
Metrics$createStoredScope)
- *
+ * <p>
  * Scope may be stored by the Metrics framework via 'storedScope' concept for 
further reference.
- *
+ * <p>
  * In either case, it is the caller's responsibility to end the scope via the 
Metrics framework (see Metrics#endScope)
  */
 public interface MetricsScope {

http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/core-common/src/main/java/org/apache/kylin/common/metrics/common/Metricss.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/metrics/common/Metricss.java
 
b/core-common/src/main/java/org/apache/kylin/common/metrics/common/Metricss.java
deleted file mode 100644
index 105ab5d..0000000
--- 
a/core-common/src/main/java/org/apache/kylin/common/metrics/common/Metricss.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.kylin.common.metrics.common;
-
-public final class Metricss {
-    public final static String METRICS = "metrics:";
-    public final static String PROJECT_TEMPLATE = METRICS + "project=%s";
-    public final static String CUBE_TEMPLATE = METRICS + "project=%s,cube=%s";
-
-
-    public static String buildMetricName(String prefix, String name) {
-        return String.format(prefix+",name=%s", name);
-    }
-
-    public static String buildCubeMetricPrefix(String project) {
-        return String.format(PROJECT_TEMPLATE, project);
-    }
-
-    public static String buildCubeMetricPrefix(String project, String cube) {
-        return String.format(CUBE_TEMPLATE, project, cube);
-    }
-
-
-}

http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/CodahaleMetrics.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/CodahaleMetrics.java
 
b/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/CodahaleMetrics.java
index d7e2f8c..8cc79e7 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/CodahaleMetrics.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/CodahaleMetrics.java
@@ -88,7 +88,7 @@ public class CodahaleMetrics implements Metrics {
     private KylinConfig conf;
 
     public CodahaleMetrics() {
-        this.conf = conf;
+        this.conf = KylinConfig.getInstanceFromEnv();
         //Codahale artifacts are lazily-created.
         timers = CacheBuilder.newBuilder().build(new CacheLoader<String, 
Timer>() {
             @Override
@@ -365,8 +365,8 @@ public class CodahaleMetrics implements Metrics {
     }
 
     /**
-     * Initializes reporters from HIVE_CODAHALE_METRICS_REPORTER_CLASSES or 
HIVE_METRICS_REPORTER if the former is not defined.
-     * Note: if both confs are defined, only  
HIVE_CODAHALE_METRICS_REPORTER_CLASSES will be used.
+     * Initializes reporters from kylin.metric.codahale-metric-report-classes  
if the former is not defined.
+     * Note: if both confs are defined, only  
kylin.metric.codahale-metric-report-classes will be used.
      */
     private void initReporting() {
 
@@ -380,7 +380,8 @@ public class CodahaleMetrics implements Metrics {
     }
 
     /**
-     * Initializes reporting using HIVE_CODAHALE_METRICS_REPORTER_CLASSES.
+     * Initializes reporting using kylin.metric.codahale-metric-report-classes.
+     *
      * @return whether initialization was successful or not
      */
     private boolean initCodahaleMetricsReporterClasses() {
@@ -397,7 +398,7 @@ public class CodahaleMetrics implements Metrics {
                 name = ClassUtils.getClass(reporterClass);
             } catch (ClassNotFoundException e) {
                 LOGGER.error("Unable to instantiate metrics reporter class " + 
reporterClass
-                        + " from conf HIVE_CODAHALE_METRICS_REPORTER_CLASSES", 
e);
+                        + " from conf 
kylin.metric.codahale-metric-report-classes", e);
                 throw new IllegalArgumentException(e);
             }
             try {
@@ -407,8 +408,8 @@ public class CodahaleMetrics implements Metrics {
                 reporters.add(reporter);
             } catch (NoSuchMethodException | InstantiationException | 
IllegalAccessException
                     | InvocationTargetException e) {
-                LOGGER.error("Unable to instantiate using 
constructor(MetricRegistry, HiveConf) for" + " reporter "
-                        + reporterClass + " from conf 
HIVE_CODAHALE_METRICS_REPORTER_CLASSES", e);
+                LOGGER.error("Unable to instantiate using 
constructor(MetricRegistry, KylinConfig) for" + " reporter "
+                        + reporterClass + " from conf 
kylin.metric.codahale-metric-report-classes", e);
                 throw new IllegalArgumentException(e);
             }
         }
@@ -416,7 +417,8 @@ public class CodahaleMetrics implements Metrics {
     }
 
     /**
-     * Initializes reporting using HIVE_METRICS+REPORTER.
+     * Initializes reporting using KYLIN_METRICS+REPORTER.
+     *
      * @return whether initialization was successful or not
      */
     private boolean initMetricsReporter() {
@@ -470,6 +472,7 @@ public class CodahaleMetrics implements Metrics {
 
         /**
          * Instantiates a named scope - intended to only be called by Metrics, 
so locally scoped.
+         *
          * @param name - name of the variable
          */
         private CodahaleMetricsScope(String name) {
@@ -480,7 +483,6 @@ public class CodahaleMetrics implements Metrics {
 
         /**
          * Opens scope, and makes note of the time started, increments run 
counter
-         *
          */
         public void open() {
             if (!isOpen) {

http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/ConsoleMetricsReporter.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/ConsoleMetricsReporter.java
 
b/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/ConsoleMetricsReporter.java
index b292443..062525d 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/ConsoleMetricsReporter.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/ConsoleMetricsReporter.java
@@ -26,7 +26,7 @@ import com.codahale.metrics.ConsoleReporter;
 import com.codahale.metrics.MetricRegistry;
 
 /**
- * A wrapper around Codahale ConsoleReporter to make it a 
pluggable/configurable Hive Metrics reporter.
+ * A wrapper around Codahale ConsoleReporter to make it a 
pluggable/configurable Kylin Metrics reporter.
  */
 public class ConsoleMetricsReporter implements CodahaleReporter {
 

http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/JmxMetricsReporter.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/JmxMetricsReporter.java
 
b/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/JmxMetricsReporter.java
index 2b18f2e..53b0926 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/JmxMetricsReporter.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/JmxMetricsReporter.java
@@ -26,7 +26,7 @@ import com.codahale.metrics.JmxReporter;
 import com.codahale.metrics.MetricRegistry;
 
 /**
- * A wrapper around Codahale JmxReporter to make it a pluggable/configurable 
Hive Metrics reporter.
+ * A wrapper around Codahale JmxReporter to make it a pluggable/configurable 
Kylin Metrics reporter.
  */
 public class JmxMetricsReporter implements CodahaleReporter {
 

http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/MetricVariableRatioGauge.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/MetricVariableRatioGauge.java
 
b/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/MetricVariableRatioGauge.java
index b49093d..625e780 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/MetricVariableRatioGauge.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/MetricVariableRatioGauge.java
@@ -18,9 +18,9 @@
 
 package org.apache.kylin.common.metrics.metrics2;
 
-import com.codahale.metrics.RatioGauge;
 import org.apache.kylin.common.metrics.common.MetricsVariable;
 
+import com.codahale.metrics.RatioGauge;
 
 /**
  * Combines two numeric metric variables into one gauge type metric displaying 
their ratio

http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/Metrics2Reporter.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/Metrics2Reporter.java
 
b/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/Metrics2Reporter.java
index d1c3c7f..e1da056 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/Metrics2Reporter.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/Metrics2Reporter.java
@@ -27,7 +27,7 @@ import com.codahale.metrics.MetricRegistry;
 import com.github.joshelser.dropwizard.metrics.hadoop.HadoopMetrics2Reporter;
 
 /**
- * A wrapper around Codahale HadoopMetrics2Reporter to make it a 
pluggable/configurable Hive Metrics reporter.
+ * A wrapper around Codahale HadoopMetrics2Reporter to make it a 
pluggable/configurable Kylin Metrics reporter.
  */
 public class Metrics2Reporter implements CodahaleReporter {
 

http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/MetricsReporting.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/MetricsReporting.java
 
b/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/MetricsReporting.java
index fc1b663..d699bf1 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/MetricsReporting.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/metrics/metrics2/MetricsReporting.java
@@ -18,9 +18,6 @@
 
 package org.apache.kylin.common.metrics.metrics2;
 
-/**
- * Reporting options for 
org.apache.hadoop.hive.common.metrics.metrics2.Metrics.
- */
 public enum MetricsReporting {
     JMX, CONSOLE, JSON_FILE, HADOOP2
 }

http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/core-common/src/main/java/org/apache/kylin/common/metrics/perflog/PerfLogger.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/metrics/perflog/PerfLogger.java
 
b/core-common/src/main/java/org/apache/kylin/common/metrics/perflog/PerfLogger.java
index cf235bb..9bede12 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/metrics/perflog/PerfLogger.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/metrics/perflog/PerfLogger.java
@@ -29,7 +29,6 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.ImmutableMap;
 
-
 /**
  * PerfLogger.
  * <p>
@@ -49,7 +48,7 @@ public class PerfLogger implements IPerfLogger {
         if (LOG.isDebugEnabled()) {
             LOG.debug("<PERFLOG method=" + method + " from=" + callerName + 
">");
         }
-        beginMetrics(callerName + "." +  method);
+        beginMetrics(callerName + "." + method);
     }
 
     public long perfLogEnd(String callerName, String method) {

http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/server-base/src/main/java/org/apache/kylin/rest/metrics/QueryMetrics2Facade.java
----------------------------------------------------------------------
diff --git 
a/server-base/src/main/java/org/apache/kylin/rest/metrics/QueryMetrics2Facade.java
 
b/server-base/src/main/java/org/apache/kylin/rest/metrics/QueryMetrics2Facade.java
index b42e65c..6d38572 100644
--- 
a/server-base/src/main/java/org/apache/kylin/rest/metrics/QueryMetrics2Facade.java
+++ 
b/server-base/src/main/java/org/apache/kylin/rest/metrics/QueryMetrics2Facade.java
@@ -19,7 +19,7 @@
 package org.apache.kylin.rest.metrics;
 
 import static org.apache.kylin.common.metrics.common.MetricsConstant.TOTAL;
-import static 
org.apache.kylin.common.metrics.common.Metricss.buildCubeMetricPrefix;
+import static 
org.apache.kylin.common.metrics.common.MetricsNameBuilder.buildCubeMetricPrefix;
 
 import java.util.concurrent.TimeUnit;
 
@@ -29,7 +29,7 @@ import org.apache.kylin.common.KylinConfig;
 import org.apache.kylin.common.metrics.common.Metrics;
 import org.apache.kylin.common.metrics.common.MetricsConstant;
 import org.apache.kylin.common.metrics.common.MetricsFactory;
-import org.apache.kylin.common.metrics.common.Metricss;
+import org.apache.kylin.common.metrics.common.MetricsNameBuilder;
 import org.apache.kylin.rest.request.SQLRequest;
 import org.apache.kylin.rest.response.SQLResponse;
 import org.slf4j.Logger;
@@ -46,7 +46,7 @@ public class QueryMetrics2Facade {
     private static boolean enabled = false;
 
     public static void init() {
-        enabled = KylinConfig.getInstanceFromEnv().getQueryMetricsEnabled();
+        enabled = KylinConfig.getInstanceFromEnv().getQueryMetrics2Enabled();
     }
 
     public static void updateMetrics(SQLRequest sqlRequest, SQLResponse 
sqlResponse) {
@@ -75,11 +75,11 @@ public class QueryMetrics2Facade {
             incrQueryCount(name, sqlResponse);
             incrCacheHitCount(name, sqlResponse);
             if (!sqlResponse.getIsException()) {
-                metrics.updateTimer(Metricss.buildMetricName(name, 
MetricsConstant.QUERY_DURATION),
+                metrics.updateTimer(MetricsNameBuilder.buildMetricName(name, 
MetricsConstant.QUERY_DURATION),
                         sqlResponse.getDuration(), TimeUnit.MILLISECONDS);
-                metrics.updateHistogram(Metricss.buildMetricName(name, 
MetricsConstant.QUERY_RESULT_ROWCOUNT),
+                
metrics.updateHistogram(MetricsNameBuilder.buildMetricName(name, 
MetricsConstant.QUERY_RESULT_ROWCOUNT),
                         sqlResponse.getResults().size());
-                metrics.updateHistogram(Metricss.buildMetricName(name, 
MetricsConstant.QUERY_SCAN_ROWCOUNT),
+                
metrics.updateHistogram(MetricsNameBuilder.buildMetricName(name, 
MetricsConstant.QUERY_SCAN_ROWCOUNT),
                         sqlResponse.getTotalScanCount());
             }
         } catch (Exception e) {
@@ -90,16 +90,16 @@ public class QueryMetrics2Facade {
 
     private static void incrQueryCount(String name, SQLResponse sqlResponse) {
         if (!sqlResponse.isHitExceptionCache() && 
!sqlResponse.getIsException()) {
-            metrics.incrementCounter(Metricss.buildMetricName(name, 
MetricsConstant.QUERY_SUCCESS_COUNT));
+            metrics.incrementCounter(MetricsNameBuilder.buildMetricName(name, 
MetricsConstant.QUERY_SUCCESS_COUNT));
         } else {
-            metrics.incrementCounter(Metricss.buildMetricName(name, 
MetricsConstant.QUERY_FAIL_COUNT));
+            metrics.incrementCounter(MetricsNameBuilder.buildMetricName(name, 
MetricsConstant.QUERY_FAIL_COUNT));
         }
-        metrics.incrementCounter(Metricss.buildMetricName(name, 
MetricsConstant.QUERY_COUNT));
+        metrics.incrementCounter(MetricsNameBuilder.buildMetricName(name, 
MetricsConstant.QUERY_COUNT));
     }
 
     private static void incrCacheHitCount(String name, SQLResponse 
sqlResponse) {
         if (sqlResponse.isStorageCacheUsed()) {
-            metrics.incrementCounter(Metricss.buildMetricName(name, 
MetricsConstant.QUERY_CACHE_COUNT));
+            metrics.incrementCounter(MetricsNameBuilder.buildMetricName(name, 
MetricsConstant.QUERY_CACHE_COUNT));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/kylin/blob/b778f33a/server/src/test/java/org/apache/kylin/rest/metrics/QueryMetrics2Test.java
----------------------------------------------------------------------
diff --git 
a/server/src/test/java/org/apache/kylin/rest/metrics/QueryMetrics2Test.java 
b/server/src/test/java/org/apache/kylin/rest/metrics/QueryMetrics2Test.java
index 5e3e00b..4019d64 100644
--- a/server/src/test/java/org/apache/kylin/rest/metrics/QueryMetrics2Test.java
+++ b/server/src/test/java/org/apache/kylin/rest/metrics/QueryMetrics2Test.java
@@ -18,7 +18,7 @@
 
 package org.apache.kylin.rest.metrics;
 
-import static 
org.apache.kylin.common.metrics.common.Metricss.buildCubeMetricPrefix;
+import static 
org.apache.kylin.common.metrics.common.MetricsNameBuilder.buildCubeMetricPrefix;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -30,7 +30,7 @@ import javax.management.ObjectName;
 import org.apache.kylin.common.metrics.common.Metrics;
 import org.apache.kylin.common.metrics.common.MetricsConstant;
 import org.apache.kylin.common.metrics.common.MetricsFactory;
-import org.apache.kylin.common.metrics.common.Metricss;
+import org.apache.kylin.common.metrics.common.MetricsNameBuilder;
 import org.apache.kylin.rest.request.SQLRequest;
 import org.apache.kylin.rest.response.SQLResponse;
 import org.apache.kylin.rest.service.ServiceTestBase;
@@ -54,13 +54,11 @@ public class QueryMetrics2Test extends ServiceTestBase {
 
     @Test
     public void testQueryMetrics() throws Exception {
-        System.setProperty("kylin.server.query-metrics-enabled", "true");
+        System.setProperty("kylin.server.query-metrics2-enabled", "true");
         QueryMetrics2Facade.init();
-
         SQLRequest sqlRequest = new SQLRequest();
         sqlRequest.setSql("select * from TEST_KYLIN_FACT");
         sqlRequest.setProject("default");
-
         SQLResponse sqlResponse = new SQLResponse();
         sqlResponse.setDuration(10);
         sqlResponse.setCube("test_cube");
@@ -83,46 +81,50 @@ public class QueryMetrics2Test extends ServiceTestBase {
         Thread.sleep(2000);
 
         Assert.assertEquals(1L,
-                metrics.getCounter(Metricss.buildMetricName(prefix, 
MetricsConstant.QUERY_COUNT)).getCount());
-        Assert.assertEquals(1L,
-                metrics.getCounter(Metricss.buildMetricName(prefix, 
MetricsConstant.QUERY_SUCCESS_COUNT)).getCount());
-        Assert.assertEquals(0L,
-                metrics.getCounter(Metricss.buildMetricName(prefix, 
MetricsConstant.QUERY_FAIL_COUNT)).getCount());
+                metrics.getCounter(MetricsNameBuilder.buildMetricName(prefix, 
MetricsConstant.QUERY_COUNT)).getCount());
         Assert.assertEquals(1L,
-                metrics.getCounter(Metricss.buildMetricName(prefix, 
MetricsConstant.QUERY_CACHE_COUNT)).getCount());
+                metrics.getCounter(MetricsNameBuilder.buildMetricName(prefix, 
MetricsConstant.QUERY_SUCCESS_COUNT))
+                        .getCount());
+        Assert.assertEquals(0L, metrics
+                .getCounter(MetricsNameBuilder.buildMetricName(prefix, 
MetricsConstant.QUERY_FAIL_COUNT)).getCount());
+        Assert.assertEquals(1L, metrics
+                .getCounter(MetricsNameBuilder.buildMetricName(prefix, 
MetricsConstant.QUERY_CACHE_COUNT)).getCount());
         //
-        Snapshot  queryScanSnapshot= metrics
-                .getHistogram(Metricss.buildMetricName(prefix, 
MetricsConstant.QUERY_SCAN_ROWCOUNT)).getSnapshot();
+        Snapshot queryScanSnapshot = metrics
+                .getHistogram(MetricsNameBuilder.buildMetricName(prefix, 
MetricsConstant.QUERY_SCAN_ROWCOUNT))
+                .getSnapshot();
         Assert.assertEquals(100.0, queryScanSnapshot.getMean(), 0);
         Assert.assertEquals(100.0, queryScanSnapshot.getMax(), 0);
         Assert.assertEquals(100.0, queryScanSnapshot.getMin(), 0);
 
         Snapshot queryResultSnapshot = metrics
-                .getHistogram(Metricss.buildMetricName(prefix, 
MetricsConstant.QUERY_RESULT_ROWCOUNT)).getSnapshot();
+                .getHistogram(MetricsNameBuilder.buildMetricName(prefix, 
MetricsConstant.QUERY_RESULT_ROWCOUNT))
+                .getSnapshot();
 
         Assert.assertEquals(2.0, queryResultSnapshot.getMean(), 0);
         Assert.assertEquals(2.0, queryResultSnapshot.getMax(), 0);
         Assert.assertEquals(2.0, queryResultSnapshot.getMin(), 0);
 
-        Snapshot queryLatencySnapshot = 
metrics.getTimer(Metricss.buildMetricName(prefix, 
MetricsConstant.QUERY_DURATION)).getSnapshot();
+        Snapshot queryLatencySnapshot = metrics
+                .getTimer(MetricsNameBuilder.buildMetricName(prefix, 
MetricsConstant.QUERY_DURATION)).getSnapshot();
         Assert.assertEquals(TimeUnit.MILLISECONDS.toNanos(10), 
queryLatencySnapshot.getMean(), 0);
         Assert.assertEquals(TimeUnit.MILLISECONDS.toNanos(10), 
queryLatencySnapshot.getMax(), 0);
         Assert.assertEquals(TimeUnit.MILLISECONDS.toNanos(10), 
queryLatencySnapshot.getMin(), 0);
 
-                SQLResponse sqlResponse2 = new SQLResponse();
-                sqlResponse2.setDuration(10);
-                sqlResponse2.setCube("test_cube");
-                sqlResponse2.setIsException(true);
-
+        SQLResponse sqlResponse2 = new SQLResponse();
+        sqlResponse2.setDuration(10);
+        sqlResponse2.setCube("test_cube");
+        sqlResponse2.setIsException(true);
 
         QueryMetrics2Facade.updateMetrics(sqlRequest, sqlResponse2);
-         prefix = buildCubeMetricPrefix(sqlRequest.getProject(), 
sqlResponse.getCube().replace("=", "->"));
+        prefix = buildCubeMetricPrefix(sqlRequest.getProject(), 
sqlResponse.getCube().replace("=", "->"));
         Assert.assertEquals(2L,
-                metrics.getCounter(Metricss.buildMetricName(prefix, 
MetricsConstant.QUERY_COUNT)).getCount());
-        Assert.assertEquals(1L,
-                metrics.getCounter(Metricss.buildMetricName(prefix, 
MetricsConstant.QUERY_SUCCESS_COUNT)).getCount());
+                metrics.getCounter(MetricsNameBuilder.buildMetricName(prefix, 
MetricsConstant.QUERY_COUNT)).getCount());
         Assert.assertEquals(1L,
-                metrics.getCounter(Metricss.buildMetricName(prefix, 
MetricsConstant.QUERY_FAIL_COUNT)).getCount());
+                metrics.getCounter(MetricsNameBuilder.buildMetricName(prefix, 
MetricsConstant.QUERY_SUCCESS_COUNT))
+                        .getCount());
+        Assert.assertEquals(1L, metrics
+                .getCounter(MetricsNameBuilder.buildMetricName(prefix, 
MetricsConstant.QUERY_FAIL_COUNT)).getCount());
     }
 
 }

Reply via email to