[phoenix] 08/34: PHOENIX-4835 LoggingPhoenixConnection should log metrics upon connection close

2019-04-19 Thread tdsilva
This is an automated email from the ASF dual-hosted git repository.

tdsilva pushed a commit to branch 4.14-HBase-1.2
in repository https://gitbox.apache.org/repos/asf/phoenix.git

commit 663eff7fcb8bd671ebeef2f872721ba23a6e9375
Author: Karan Mehta 
AuthorDate: Thu Aug 16 15:08:12 2018 -0700

PHOENIX-4835 LoggingPhoenixConnection should log metrics upon connection 
close
---
 .../phoenix/monitoring/BasePhoenixMetricsIT.java   | 128 +++
 .../monitoring/PhoenixLoggingMetricsIT.java| 181 +
 .../phoenix/monitoring/PhoenixMetricsIT.java   | 170 ++-
 .../phoenix/jdbc/LoggingPhoenixConnection.java |  12 +-
 4 files changed, 332 insertions(+), 159 deletions(-)

diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/BasePhoenixMetricsIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/BasePhoenixMetricsIT.java
new file mode 100644
index 000..5c016f6
--- /dev/null
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/BasePhoenixMetricsIT.java
@@ -0,0 +1,128 @@
+/*
+ * 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.phoenix.monitoring;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.phoenix.end2end.BaseUniqueNamesOwnClusterIT;
+import org.apache.phoenix.jdbc.PhoenixDriver;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.BeforeClass;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.apache.phoenix.monitoring.MetricType.SCAN_BYTES;
+import static org.apache.phoenix.monitoring.MetricType.TASK_EXECUTED_COUNTER;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class BasePhoenixMetricsIT extends BaseUniqueNamesOwnClusterIT {
+
+static final int MAX_RETRIES = 5;
+
+static final List mutationMetricsToSkip =
+Lists.newArrayList(MetricType.MUTATION_COMMIT_TIME);
+static final List readMetricsToSkip =
+Lists.newArrayList(MetricType.TASK_QUEUE_WAIT_TIME,
+MetricType.TASK_EXECUTION_TIME, MetricType.TASK_END_TO_END_TIME,
+MetricType.COUNT_MILLS_BETWEEN_NEXTS);
+static final String CUSTOM_URL_STRING = "SESSION";
+static final AtomicInteger numConnections = new AtomicInteger(0);
+
+@BeforeClass
+public static void doSetup() throws Exception {
+Map props = Maps.newHashMapWithExpectedSize(1);
+// Phoenix Global client metrics are enabled by default
+// Enable request metric collection at the driver level
+props.put(QueryServices.COLLECT_REQUEST_LEVEL_METRICS, 
String.valueOf(true));
+// disable renewing leases as this will force spooling to happen.
+props.put(QueryServices.RENEW_LEASE_ENABLED, String.valueOf(false));
+setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+// need the non-test driver for some tests that check number of 
hconnections, etc.
+DriverManager.registerDriver(PhoenixDriver.INSTANCE);
+
+}
+
+Connection insertRowsInTable(String tableName, long numRows) throws 
SQLException {
+String dml = "UPSERT INTO " + tableName + " VALUES (?, ?)";
+Connection conn = DriverManager.getConnection(getUrl());
+PreparedStatement stmt = conn.prepareStatement(dml);
+for (int i = 1; i <= numRows; i++) {
+stmt.setString(1, "key" + i);
+stmt.setString(2, "value" + i);
+stmt.executeUpdate();
+}
+conn.commit();
+return conn;
+}
+
+void assertReadMetricsForMutatingSql(String tableName, long 
tableSaltBuckets,
+ Map> readMetrics) {
+assertTrue("No read metrics present when there should have been!", 
readMetrics.size() > 0);
+int numTables = 0;
+for (Map.Entry> entry : 
readMetrics.entrySet()) {
+String t = entry.getKey();
+assertEquals("Table name didn't match f

[phoenix] 08/34: PHOENIX-4835 LoggingPhoenixConnection should log metrics upon connection close

2019-04-19 Thread tdsilva
This is an automated email from the ASF dual-hosted git repository.

tdsilva pushed a commit to branch 4.14-HBase-1.3
in repository https://gitbox.apache.org/repos/asf/phoenix.git

commit 3a5fb00e4419452e3c34bd8c1844a5e2930e264e
Author: Karan Mehta 
AuthorDate: Thu Aug 16 15:08:12 2018 -0700

PHOENIX-4835 LoggingPhoenixConnection should log metrics upon connection 
close
---
 .../phoenix/monitoring/BasePhoenixMetricsIT.java   | 128 +++
 .../monitoring/PhoenixLoggingMetricsIT.java| 181 +
 .../phoenix/monitoring/PhoenixMetricsIT.java   | 170 ++-
 .../phoenix/jdbc/LoggingPhoenixConnection.java |  12 +-
 4 files changed, 332 insertions(+), 159 deletions(-)

diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/BasePhoenixMetricsIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/BasePhoenixMetricsIT.java
new file mode 100644
index 000..5c016f6
--- /dev/null
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/BasePhoenixMetricsIT.java
@@ -0,0 +1,128 @@
+/*
+ * 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.phoenix.monitoring;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.phoenix.end2end.BaseUniqueNamesOwnClusterIT;
+import org.apache.phoenix.jdbc.PhoenixDriver;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.BeforeClass;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.apache.phoenix.monitoring.MetricType.SCAN_BYTES;
+import static org.apache.phoenix.monitoring.MetricType.TASK_EXECUTED_COUNTER;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class BasePhoenixMetricsIT extends BaseUniqueNamesOwnClusterIT {
+
+static final int MAX_RETRIES = 5;
+
+static final List mutationMetricsToSkip =
+Lists.newArrayList(MetricType.MUTATION_COMMIT_TIME);
+static final List readMetricsToSkip =
+Lists.newArrayList(MetricType.TASK_QUEUE_WAIT_TIME,
+MetricType.TASK_EXECUTION_TIME, MetricType.TASK_END_TO_END_TIME,
+MetricType.COUNT_MILLS_BETWEEN_NEXTS);
+static final String CUSTOM_URL_STRING = "SESSION";
+static final AtomicInteger numConnections = new AtomicInteger(0);
+
+@BeforeClass
+public static void doSetup() throws Exception {
+Map props = Maps.newHashMapWithExpectedSize(1);
+// Phoenix Global client metrics are enabled by default
+// Enable request metric collection at the driver level
+props.put(QueryServices.COLLECT_REQUEST_LEVEL_METRICS, 
String.valueOf(true));
+// disable renewing leases as this will force spooling to happen.
+props.put(QueryServices.RENEW_LEASE_ENABLED, String.valueOf(false));
+setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+// need the non-test driver for some tests that check number of 
hconnections, etc.
+DriverManager.registerDriver(PhoenixDriver.INSTANCE);
+
+}
+
+Connection insertRowsInTable(String tableName, long numRows) throws 
SQLException {
+String dml = "UPSERT INTO " + tableName + " VALUES (?, ?)";
+Connection conn = DriverManager.getConnection(getUrl());
+PreparedStatement stmt = conn.prepareStatement(dml);
+for (int i = 1; i <= numRows; i++) {
+stmt.setString(1, "key" + i);
+stmt.setString(2, "value" + i);
+stmt.executeUpdate();
+}
+conn.commit();
+return conn;
+}
+
+void assertReadMetricsForMutatingSql(String tableName, long 
tableSaltBuckets,
+ Map> readMetrics) {
+assertTrue("No read metrics present when there should have been!", 
readMetrics.size() > 0);
+int numTables = 0;
+for (Map.Entry> entry : 
readMetrics.entrySet()) {
+String t = entry.getKey();
+assertEquals("Table name didn't match f

[phoenix] 08/34: PHOENIX-4835 LoggingPhoenixConnection should log metrics upon connection close

2019-04-19 Thread tdsilva
This is an automated email from the ASF dual-hosted git repository.

tdsilva pushed a commit to branch 4.14-HBase-1.4
in repository https://gitbox.apache.org/repos/asf/phoenix.git

commit 4241f5711bf55e4fcf192414e7f4f7796122ba29
Author: Karan Mehta 
AuthorDate: Thu Aug 16 15:08:12 2018 -0700

PHOENIX-4835 LoggingPhoenixConnection should log metrics upon connection 
close
---
 .../phoenix/monitoring/BasePhoenixMetricsIT.java   | 128 +++
 .../monitoring/PhoenixLoggingMetricsIT.java| 181 +
 .../phoenix/monitoring/PhoenixMetricsIT.java   | 170 ++-
 .../phoenix/jdbc/LoggingPhoenixConnection.java |  12 +-
 4 files changed, 332 insertions(+), 159 deletions(-)

diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/BasePhoenixMetricsIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/BasePhoenixMetricsIT.java
new file mode 100644
index 000..5c016f6
--- /dev/null
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/BasePhoenixMetricsIT.java
@@ -0,0 +1,128 @@
+/*
+ * 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.phoenix.monitoring;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.phoenix.end2end.BaseUniqueNamesOwnClusterIT;
+import org.apache.phoenix.jdbc.PhoenixDriver;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.BeforeClass;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.apache.phoenix.monitoring.MetricType.SCAN_BYTES;
+import static org.apache.phoenix.monitoring.MetricType.TASK_EXECUTED_COUNTER;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class BasePhoenixMetricsIT extends BaseUniqueNamesOwnClusterIT {
+
+static final int MAX_RETRIES = 5;
+
+static final List mutationMetricsToSkip =
+Lists.newArrayList(MetricType.MUTATION_COMMIT_TIME);
+static final List readMetricsToSkip =
+Lists.newArrayList(MetricType.TASK_QUEUE_WAIT_TIME,
+MetricType.TASK_EXECUTION_TIME, MetricType.TASK_END_TO_END_TIME,
+MetricType.COUNT_MILLS_BETWEEN_NEXTS);
+static final String CUSTOM_URL_STRING = "SESSION";
+static final AtomicInteger numConnections = new AtomicInteger(0);
+
+@BeforeClass
+public static void doSetup() throws Exception {
+Map props = Maps.newHashMapWithExpectedSize(1);
+// Phoenix Global client metrics are enabled by default
+// Enable request metric collection at the driver level
+props.put(QueryServices.COLLECT_REQUEST_LEVEL_METRICS, 
String.valueOf(true));
+// disable renewing leases as this will force spooling to happen.
+props.put(QueryServices.RENEW_LEASE_ENABLED, String.valueOf(false));
+setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+// need the non-test driver for some tests that check number of 
hconnections, etc.
+DriverManager.registerDriver(PhoenixDriver.INSTANCE);
+
+}
+
+Connection insertRowsInTable(String tableName, long numRows) throws 
SQLException {
+String dml = "UPSERT INTO " + tableName + " VALUES (?, ?)";
+Connection conn = DriverManager.getConnection(getUrl());
+PreparedStatement stmt = conn.prepareStatement(dml);
+for (int i = 1; i <= numRows; i++) {
+stmt.setString(1, "key" + i);
+stmt.setString(2, "value" + i);
+stmt.executeUpdate();
+}
+conn.commit();
+return conn;
+}
+
+void assertReadMetricsForMutatingSql(String tableName, long 
tableSaltBuckets,
+ Map> readMetrics) {
+assertTrue("No read metrics present when there should have been!", 
readMetrics.size() > 0);
+int numTables = 0;
+for (Map.Entry> entry : 
readMetrics.entrySet()) {
+String t = entry.getKey();
+assertEquals("Table name didn't match f