[ 
https://issues.apache.org/jira/browse/PHOENIX-7038?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17769503#comment-17769503
 ] 

ASF GitHub Bot commented on PHOENIX-7038:
-----------------------------------------

ranganathg commented on code in PR #1682:
URL: https://github.com/apache/phoenix/pull/1682#discussion_r1338311821


##########
phoenix-core/src/main/java/org/apache/phoenix/monitoring/connqueryservice/ConnectionQueryServicesMetricsManager.java:
##########
@@ -0,0 +1,375 @@
+/*
+ * 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.connqueryservice;
+
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.phoenix.monitoring.HistogramDistribution;
+import org.apache.phoenix.monitoring.MetricPublisherSupplierFactory;
+import org.apache.phoenix.monitoring.MetricServiceResolver;
+import org.apache.phoenix.monitoring.MetricType;
+import org.apache.phoenix.monitoring.PhoenixConnectionProfileMetric;
+import org.apache.phoenix.query.QueryServicesOptions;
+import 
org.apache.phoenix.thirdparty.com.google.common.annotations.VisibleForTesting;
+import org.apache.phoenix.thirdparty.com.google.common.base.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * Central place where we keep track of all the Connection Query Service 
metrics. Register each
+ * Connection Query Service and store the instance of it associated with 
ConnectionServiceName in a
+ * map This class exposes following functions as static methods to help catch 
all exception
+ * 1.clearConnectionQueryServiceMetrics
+ * 2.getTableMetricsMethod
+ * 3.pushMetricsFromConnInstanceMethod
+ * 4.updateMetricsMethod
+ */
+public class ConnectionQueryServicesMetricsManager {
+    private static final Logger LOGGER =
+            
LoggerFactory.getLogger(ConnectionQueryServicesMetricsManager.class);
+    private static boolean isConnectionQueryServiceMetricsEnabled;
+    private static boolean isConnectionQueryServiceMetricPublisherEnabled;
+    private static ConcurrentMap<String, PhoenixConnectionQueryServiceMetrics>
+            connectionQueryServiceMetricsMapping;
+    // Singleton object
+    private static volatile ConnectionQueryServicesMetricsManager
+            connectionQueryServicesMetricsManager = null;
+    private static volatile MetricPublisherSupplierFactory mPublisher = null;
+    private static volatile QueryServicesOptions options;
+
+    @VisibleForTesting
+    public ConnectionQueryServicesMetricsManager(QueryServicesOptions opts) {
+        options = opts;
+        isConnectionQueryServiceMetricsEnabled = 
options.isConnectionQueryServiceMetricsEnabled();
+        connectionQueryServiceMetricsMapping = new ConcurrentHashMap<>();
+        LOGGER.info("Phoenix connection query service metrics enabled status: "
+                + isConnectionQueryServiceMetricsEnabled);
+        // Return simply if connection query service metrics are not enabled
+        if (!isConnectionQueryServiceMetricsEnabled) {
+            return;
+        }
+        isConnectionQueryServiceMetricPublisherEnabled =
+                options.isConnectionQueryServiceMetricsPublisherEnabled();
+        LOGGER.info("Phoenix connection query service metrics publisher 
enabled status: "
+                + isConnectionQueryServiceMetricPublisherEnabled);
+    }
+
+    @VisibleForTesting
+    public static void setInstance(ConnectionQueryServicesMetricsManager 
metricsManager) {
+        connectionQueryServicesMetricsManager = metricsManager;
+    }
+
+    /**
+     * Method to provide instance of 
ConnectionQueryServiceMetricsManager(Create if needed in
+     * thread safe manner)
+     * @return returns instance of ConnectionQueryServicesMetricsManager for 
the said
+     *         ConnectionQueryService
+     */
+    public static ConnectionQueryServicesMetricsManager getInstance() {
+        ConnectionQueryServicesMetricsManager localRef = 
connectionQueryServicesMetricsManager;
+
+        if (localRef == null) {
+            synchronized (ConnectionQueryServicesMetricsManager.class) {
+                localRef = connectionQueryServicesMetricsManager;
+                if (localRef == null) {
+                    QueryServicesOptions options = 
QueryServicesOptions.withDefaults();
+                    localRef = connectionQueryServicesMetricsManager =
+                            new ConnectionQueryServicesMetricsManager(options);
+                    LOGGER.info("connection query service created object for 
metrics manager");
+                    if (isConnectionQueryServiceMetricsEnabled
+                            && isConnectionQueryServiceMetricPublisherEnabled) 
{
+                        String className = 
options.getConnectionProfileMetricsPublisherClass();
+                        if (className != null) {
+                            MetricServiceResolver mResolver = new 
MetricServiceResolver();
+                            LOGGER.info(String.format(
+                                    "connection query service metrics 
publisher className %s",
+                                    className));
+                            try {
+                                mPublisher = mResolver.instantiate(className);
+                                mPublisher.registerMetricProvider();
+                            } catch (Throwable e) {
+                                LOGGER.error("The exception from metric 
publish Function", e);
+                            }
+
+                        } else {
+                            LOGGER.warn("connection query service metrics 
publisher className"
+                                    + " can't be null");
+                        }
+                    }
+                }
+            }
+        }
+        return localRef;
+    }
+
+    private PhoenixConnectionQueryServiceMetrics 
getConnectionQueryServiceMetricsInstance(

Review Comment:
   should this be the responsibility of PhoenixConnectionQueryServiceMetrics 
itself?





> Implement Phoenix Connection Profile Metrics
> --------------------------------------------
>
>                 Key: PHOENIX-7038
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-7038
>             Project: Phoenix
>          Issue Type: New Feature
>            Reporter: Mihir Monani
>            Assignee: Mihir Monani
>            Priority: Major
>
> With JDBC connection profile string, Clients can provide connection profile 
> name. With use of Connection Profile, different kinds of clients/use-case in 
> single JVM can create connection with different configuration like time-outs, 
> retries, sleep between retries. 
> Connection URL Example : jdbc:phoenix:localhost:2181:CONN_PROFILE_2
> Here CONN_PROFILE_2 is connection profile name.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to