mihir6692 commented on code in PR #1682: URL: https://github.com/apache/phoenix/pull/1682#discussion_r1374839499
########## 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" Review Comment: It's better to not kill a service/JVM start for Metrics classname issue. -- 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]
