[
https://issues.apache.org/jira/browse/PHOENIX-6564?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17563707#comment-17563707
]
ASF GitHub Bot commented on PHOENIX-6564:
-----------------------------------------
lokiore commented on code in PR #1459:
URL: https://github.com/apache/phoenix/pull/1459#discussion_r915741551
##########
phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java:
##########
@@ -1099,6 +1100,53 @@ public void testGetConnectionsThrottledForSameUrl()
throws Exception {
assertEquals(maxConnections, connections.size());
}
+ @Test
+ public void testGetConnectionsFailedCounter() throws Exception {
+ int attemptedPhoenixConnections = 7;
+ //3 Failed connections and 1 throttled connection
+ int maxConnections = attemptedPhoenixConnections - 4;
+ List<Connection> connections = Lists.newArrayList();
+ String zkQuorum = "localhost:" +
getUtility().getZkCluster().getClientPort();
+ String url = PhoenixRuntime.JDBC_PROTOCOL +
PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum +
+ ':' + CUSTOM_URL_STRING + '=' + "FailedCounterTest";
+ Properties props = new Properties();
+
props.setProperty(QueryServices.CLIENT_CONNECTION_MAX_ALLOWED_CONNECTIONS,
Integer.toString(maxConnections));
+ Properties props1 = new Properties(props);
+ props1.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
Integer.toString(-1));
+
+ GLOBAL_QUERY_SERVICES_COUNTER.getMetric().reset();
+ GLOBAL_PHOENIX_CONNECTIONS_ATTEMPTED_COUNTER.getMetric().reset();
+ GLOBAL_PHOENIX_CONNECTIONS_THROTTLED_COUNTER.getMetric().reset();
+ GLOBAL_FAILED_PHOENIX_CONNECTIONS.getMetric().reset();
+ try {
+ for (int i = 0; i < attemptedPhoenixConnections; i++) {
+ try {
+ if (i % 3 == 0) {
+ connections.add(DriverManager.getConnection(url,
props1));
+ } else {
+ connections.add(DriverManager.getConnection(url,
props));
+ }
+ } catch (SQLException se) {
+ if (i % 3 == 0) {
+
assertEquals(SQLExceptionCode.INVALID_SCN.getErrorCode(), se.getErrorCode());
+ } else {
+
assertEquals(SQLExceptionCode.NEW_CONNECTION_THROTTLED.getErrorCode(),
se.getErrorCode());
+ }
+ }
+ }
+ } finally {
+ for (Connection c : connections) {
+ c.close();
+ }
+ }
+ assertEquals(1, GLOBAL_QUERY_SERVICES_COUNTER.getMetric().getValue());
+ assertEquals(1,
GLOBAL_PHOENIX_CONNECTIONS_THROTTLED_COUNTER.getMetric().getValue());
+ assertEquals(3,
GLOBAL_FAILED_PHOENIX_CONNECTIONS.getMetric().getValue());
+ assertTrue("Not all connections were attempted!",
+ attemptedPhoenixConnections <=
GLOBAL_PHOENIX_CONNECTIONS_ATTEMPTED_COUNTER.getMetric().getValue());
Review Comment:
When we are creating/initializing ConnectionQueryServices I see we are
creating one more metaconnection which is increasing it's count with 1 more, I
confirmed with logs as well, first connection is increasing it's count twice.
> Add Phoenix Connection Failed Global Metric
> -------------------------------------------
>
> Key: PHOENIX-6564
> URL: https://issues.apache.org/jira/browse/PHOENIX-6564
> Project: Phoenix
> Issue Type: New Feature
> Components: core
> Affects Versions: 4.16.1, 5.1.2
> Reporter: Daniel Wong
> Assignee: Lokesh Khurana
> Priority: Minor
>
> Add Phoenix Connection Failed Global Metric. We have
> PHOENIX_CONNECTIONS_ATTEMPTED_COUNTER as well as a
> PHOENIX_CONNECTIONS_THROTTLED_COUNTER but this doesn't cover all possible
> failures under attempted during DriverManager.getConnection. This Jira is to
> provide a counter that covers all failures and to ensure that attempted also
> covers as wide of a net as possible. This would be a counter metric that
> increments when DriverManager.getConnection fails to return a jdbc connection
> to the user.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)