vmeka2020 commented on a change in pull request #1231:
URL: https://github.com/apache/phoenix/pull/1231#discussion_r724578730



##########
File path: 
phoenix-core/src/main/java/org/apache/phoenix/monitoring/TableHistograms.java
##########
@@ -0,0 +1,120 @@
+/*
+ * 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 maynot 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 applicablelaw 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.phoenix.monitoring;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.apache.hadoop.conf.Configuration;
+
+public class TableHistograms {
+    private String tableName;
+    private LatencyHistogram queryLatencyHisto;
+    private SizeHistogram querySizeHisto;
+    private LatencyHistogram upsertLatencyHisto;
+    private SizeHistogram upsertSizeHisto;
+    private LatencyHistogram deleteLatencyHisto;
+    private SizeHistogram deleteSizeHisto;
+    private LatencyHistogram pointLookupLatencyHisto;
+    private SizeHistogram pointLookupSizeHisto;
+    private LatencyHistogram rangeScanLatencyHisto;
+    private SizeHistogram rangeScanSizeHisto;
+
+    public TableHistograms(String tableName, Configuration conf) {
+        this.tableName = tableName;
+        queryLatencyHisto = new LatencyHistogram("QueryTime", "Query time 
latency", conf);
+        querySizeHisto = new SizeHistogram("QuerySize", "Query size", conf);
+
+        upsertLatencyHisto = new LatencyHistogram("UpsertTime", "Upsert time 
latency", conf);
+        upsertSizeHisto = new SizeHistogram("UpsertSize", "Upsert size", conf);
+
+        deleteLatencyHisto = new LatencyHistogram("DeleteTime", "Delete time 
latency", conf);
+        deleteSizeHisto = new SizeHistogram("DeleteSize", "Delete size", conf);
+
+        pointLookupLatencyHisto = new LatencyHistogram("PointLookupTime",
+                "Point Lookup Query time latency", conf);
+        pointLookupSizeHisto = new SizeHistogram("PointLookupSize",
+                "Point Lookup Query Size", conf);
+
+        rangeScanLatencyHisto = new LatencyHistogram("RangeScanTime",
+                "Range Scan Query time latency", conf);
+        rangeScanSizeHisto = new SizeHistogram("RangeScanSize",
+                "Range Scan Query size", conf);
+    }
+
+    public String getTableName() {
+        return tableName;
+    }
+
+    public LatencyHistogram getQueryLatencyHisto() {
+        return queryLatencyHisto;
+    }
+
+    public SizeHistogram getQuerySizeHisto() {
+        return querySizeHisto;
+    }
+
+
+    public LatencyHistogram getPointLookupLatencyHisto() {
+        return pointLookupLatencyHisto;
+    }
+
+    public SizeHistogram getPointLookupSizeHisto() {
+        return pointLookupSizeHisto;
+    }
+
+    public LatencyHistogram getRangeScanLatencyHisto() {
+        return rangeScanLatencyHisto;
+    }
+
+    public SizeHistogram getRangeScanSizeHisto() {
+        return rangeScanSizeHisto;
+    }
+
+    public LatencyHistogram getUpsertLatencyHisto() {
+        return upsertLatencyHisto;
+    }
+
+    public SizeHistogram getUpsertSizeHisto() {
+        return upsertSizeHisto;
+    }
+
+    public LatencyHistogram getDeleteLatencyHisto() {
+        return deleteLatencyHisto;
+    }
+
+    public SizeHistogram getDeleteSizeHisto() {
+        return deleteSizeHisto;
+    }
+
+    public List<HistogramDistribution> getTableLatencyHistogramsDistribution() 
{
+        List<HistogramDistribution> list = new 
ArrayList<>(Arrays.asList(queryLatencyHisto.getRangeHistogramDistribution(),

Review comment:
       updated with immutableList

##########
File path: 
phoenix-core/src/main/java/org/apache/phoenix/monitoring/TableHistograms.java
##########
@@ -0,0 +1,120 @@
+/*
+ * 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 maynot 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 applicablelaw 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.phoenix.monitoring;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.apache.hadoop.conf.Configuration;
+
+public class TableHistograms {
+    private String tableName;
+    private LatencyHistogram queryLatencyHisto;
+    private SizeHistogram querySizeHisto;
+    private LatencyHistogram upsertLatencyHisto;
+    private SizeHistogram upsertSizeHisto;
+    private LatencyHistogram deleteLatencyHisto;
+    private SizeHistogram deleteSizeHisto;
+    private LatencyHistogram pointLookupLatencyHisto;
+    private SizeHistogram pointLookupSizeHisto;
+    private LatencyHistogram rangeScanLatencyHisto;
+    private SizeHistogram rangeScanSizeHisto;
+
+    public TableHistograms(String tableName, Configuration conf) {
+        this.tableName = tableName;
+        queryLatencyHisto = new LatencyHistogram("QueryTime", "Query time 
latency", conf);
+        querySizeHisto = new SizeHistogram("QuerySize", "Query size", conf);
+
+        upsertLatencyHisto = new LatencyHistogram("UpsertTime", "Upsert time 
latency", conf);
+        upsertSizeHisto = new SizeHistogram("UpsertSize", "Upsert size", conf);
+
+        deleteLatencyHisto = new LatencyHistogram("DeleteTime", "Delete time 
latency", conf);
+        deleteSizeHisto = new SizeHistogram("DeleteSize", "Delete size", conf);
+
+        pointLookupLatencyHisto = new LatencyHistogram("PointLookupTime",
+                "Point Lookup Query time latency", conf);
+        pointLookupSizeHisto = new SizeHistogram("PointLookupSize",
+                "Point Lookup Query Size", conf);
+
+        rangeScanLatencyHisto = new LatencyHistogram("RangeScanTime",
+                "Range Scan Query time latency", conf);
+        rangeScanSizeHisto = new SizeHistogram("RangeScanSize",
+                "Range Scan Query size", conf);
+    }
+
+    public String getTableName() {
+        return tableName;
+    }
+
+    public LatencyHistogram getQueryLatencyHisto() {
+        return queryLatencyHisto;
+    }
+
+    public SizeHistogram getQuerySizeHisto() {
+        return querySizeHisto;
+    }
+
+
+    public LatencyHistogram getPointLookupLatencyHisto() {
+        return pointLookupLatencyHisto;
+    }
+
+    public SizeHistogram getPointLookupSizeHisto() {
+        return pointLookupSizeHisto;
+    }
+
+    public LatencyHistogram getRangeScanLatencyHisto() {
+        return rangeScanLatencyHisto;
+    }
+
+    public SizeHistogram getRangeScanSizeHisto() {
+        return rangeScanSizeHisto;
+    }
+
+    public LatencyHistogram getUpsertLatencyHisto() {
+        return upsertLatencyHisto;
+    }
+
+    public SizeHistogram getUpsertSizeHisto() {
+        return upsertSizeHisto;
+    }
+
+    public LatencyHistogram getDeleteLatencyHisto() {
+        return deleteLatencyHisto;
+    }
+
+    public SizeHistogram getDeleteSizeHisto() {
+        return deleteSizeHisto;
+    }
+
+    public List<HistogramDistribution> getTableLatencyHistogramsDistribution() 
{
+        List<HistogramDistribution> list = new 
ArrayList<>(Arrays.asList(queryLatencyHisto.getRangeHistogramDistribution(),
+                upsertLatencyHisto.getRangeHistogramDistribution(), 
deleteLatencyHisto.getRangeHistogramDistribution(),
+                pointLookupLatencyHisto.getRangeHistogramDistribution(), 
rangeScanLatencyHisto.getRangeHistogramDistribution()));
+        return Collections.unmodifiableList(list);
+    }
+
+    public List<HistogramDistribution> getTableSizeHistogramsDistribution() {
+        List<HistogramDistribution> list = new 
ArrayList<>(Arrays.asList(querySizeHisto.getRangeHistogramDistribution(),

Review comment:
       updated with immutableList

##########
File path: 
phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixTableLevelMetricsIT.java
##########
@@ -1148,13 +1195,156 @@ private static void assertMetricValue(Metric m, 
MetricType checkType, long compa
         }
     }
 
+    @Test
+    public void testHistogramMetricsForMutations() throws Exception {
+        String tableName = generateUniqueName();
+        // Reset table level metrics to capture histogram metrics for upsert.
+        try (Connection conn =  getConnFromTestDriver()) {
+            createTableAndInsertValues(tableName, true, true, 10, true, conn, 
false);
+        }
+        // Metrics will be reset after creation of table so below we will get 
latency
+        // just for upsert queries.
+        // Since we are recording latency histograms after every 
executeMutation method and
+        // since we are not batch upserting, it will record histogram event 
after every upsert.
+        assertHistogramMetricsForMutations(tableName, true, 1, 1, true);
+
+        // Reset table histograms as well as global metrics
+        PhoenixRuntime.clearTableLevelMetrics();
+        PhoenixMetricsIT.resetGlobalMetrics();
+        try (Connection connection = getConnFromTestDriver();
+                Statement statement = connection.createStatement()) {
+            String delete = "DELETE FROM " + tableName;
+            statement.execute(delete);
+            connection.commit();
+        }
+        // Verify metrics for delete mutations
+        assertHistogramMetricsForMutations(tableName, false, 1, 1, true);
+        PhoenixRuntime.clearTableLevelMetrics();
+    }
+
+    @Test
+    public void testHistogramMetricsForMutationsAutoCommitTrue() throws 
Exception {
+        String tableName = generateUniqueName();
+        // Reset table level metrics to capture histogram metrics for upsert.
+        try (Connection conn =  getConnFromTestDriver()) {
+            conn.setAutoCommit(true);
+            createTableAndInsertValues(tableName, true, true, 10, false, conn, 
false);
+        }
+        // Metrics will be reset after creation of table so below we will get 
latency
+        // just for upsert queries.
+        // Since we are recording latency histograms after every 
executeMutation method and
+        // since we are not batch upserting, it will record histogram event 
after every upsert.
+        assertHistogramMetricsForMutations(tableName, true, 10, 10, false);
+
+        // Reset table histograms as well as global metrics
+        PhoenixRuntime.clearTableLevelMetrics();
+        PhoenixMetricsIT.resetGlobalMetrics();
+        try (Connection connection = getConnFromTestDriver();
+                Statement statement = connection.createStatement()) {
+            connection.setAutoCommit(true);
+            String delete = "DELETE FROM " + tableName;
+            statement.execute(delete);
+        }
+        // Verify metrics for delete mutations. We won't get any data point for
+        // size histogram since delete happened on server side using 
ServerSelectDeleteMutationPlan.

Review comment:
       Find the HBase server-side calls to get the data back to Phoenix. 




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