[
https://issues.apache.org/jira/browse/PHOENIX-6397?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17342190#comment-17342190
]
ASF GitHub Bot commented on PHOENIX-6397:
-----------------------------------------
yanxinyi commented on a change in pull request #1224:
URL: https://github.com/apache/phoenix/pull/1224#discussion_r629746729
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/monitoring/TableMetricsManager.java
##########
@@ -0,0 +1,289 @@
+/**
+ * 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 java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.thirdparty.com.google.common.base.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Central place where we keep track of all the Table Level metrics. Register
each tableMetrics and
+ * store the instance of it associated with TableName in a map
+ * This class exposes following functions as static methods to help catch all
execptions
+ * 1.clearTableLevelMetricsMethod
+ * 2.getTableMetricsMethod
+ * 3.pushMetricsFromConnInstanceMethod
+ * 4.updateMetricsMethod
+ */
+
+public class TableMetricsManager {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(TableMetricsManager.class);
+ private static final Set<String> allowedListOfTableNames = new HashSet<>();
+ private static volatile boolean isTableLevelMetricsEnabled;
+ private static volatile boolean isMetricPublisherEnabled;
+ private static volatile ConcurrentMap<String, TableClientMetrics>
tableClientMetricsMapping = null;
+ // Singleton object
+ private static volatile TableMetricsManager tableMetricsManager = null;
+ private static volatile MetricPublisherSupplierFactory mPublisher = null;
+ private static volatile QueryServicesOptions options = null;
+
+ public TableMetricsManager(QueryServicesOptions ops) {
+ options = ops;
+ isTableLevelMetricsEnabled = options.isTableLevelMetricsEnabled();
+ LOGGER.info(String.format("Phoenix Table metrics enabled status: %s",
+ isTableLevelMetricsEnabled));
+ tableClientMetricsMapping = new ConcurrentHashMap<>();
+
+ String tableNamesList = options.getAllowedListTableNames();
+ if (tableNamesList != null && !tableNamesList.isEmpty()) {
+ for (String tableName : tableNamesList.split(",")) {
+ allowedListOfTableNames.add(tableName);
+ }
+ }
+ isMetricPublisherEnabled = options.isMetricPublisherEnabled();
+ LOGGER.info(String.format("Phoenix table level metrics publisher
enabled status %s",
+ isMetricPublisherEnabled));
+ }
+
+ public TableMetricsManager() {
+
+ }
+
+ /**
+ * Method to provide instance of TableMetricsManager(Create if needed in
thread safe manner)
+ *
+ * @return
+ */
+ private static TableMetricsManager getInstance() {
+
+ TableMetricsManager localRef = tableMetricsManager;
+ if (localRef == null) {
+ synchronized (TableMetricsManager.class) {
+ if (localRef == null) {
+ QueryServicesOptions options =
QueryServicesOptions.withDefaults();
+ if (!options.isTableLevelMetricsEnabled()) {
+ localRef = tableMetricsManager =
+
NoOpTableMetricsManager.noOpsTableMetricManager;
+ return localRef;
+ }
+ localRef = tableMetricsManager = new
TableMetricsManager(options);
+ LOGGER.info("Phoenix Table metrics created object for
metrics manager");
+ if (isMetricPublisherEnabled) {
+ String className = options.getMetricPublisherClass();
+ if (className != null) {
+ MetricServiceResolver mResolver = new
MetricServiceResolver();
+ LOGGER.info(String.format(
+ "Phoenix table level 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.error(
+ "Phoenix table level metrics publisher
className cannot be null");
+ }
+
+ }
+ }
+ }
+ }
+ return localRef;
+ }
+
+ public static void setInstance(TableMetricsManager metricsManager) {
Review comment:
@VisibleForTesting has been added on 4.x branch but not here
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]
> Implement TableMetricsManager class and its associated functions for select.
> upsert and Delete Queries
> ------------------------------------------------------------------------------------------------------
>
> Key: PHOENIX-6397
> URL: https://issues.apache.org/jira/browse/PHOENIX-6397
> Project: Phoenix
> Issue Type: Sub-task
> Reporter: vikas meka
> Assignee: vikas meka
> Priority: Major
> Fix For: 4.17.0, 5.2.0
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)