zhtaoxiang commented on code in PR #10106: URL: https://github.com/apache/pinot/pull/10106#discussion_r1080869461
########## pinot-common/src/test/java/org/apache/pinot/common/metrics/MetricValueUtils.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.pinot.common.metrics; + +import com.yammer.metrics.core.MetricName; +import org.apache.pinot.plugin.metrics.yammer.YammerMetricName; +import org.apache.pinot.plugin.metrics.yammer.YammerSettableGauge; +import org.apache.pinot.spi.metrics.PinotMetric; + + +public class MetricValueUtils { + private MetricValueUtils() { + } + + public static boolean gaugeExists(AbstractMetrics metrics, String metricName) { + return extractMetric(metrics, metricName) != null; + } + + public static long getGaugeValue(AbstractMetrics metrics, String metricName) { + PinotMetric pinotMetric = extractMetric(metrics, metricName); + if (pinotMetric == null) { + return 0; + } + return ((YammerSettableGauge<Long>) pinotMetric.getMetric()).value(); + } + + public static boolean globalGaugeExists(AbstractMetrics metrics, AbstractMetrics.Gauge gauge) { + return extractMetric(metrics, gauge.getGaugeName()) != null; + } + + public static long getGlobalGaugeValue(AbstractMetrics metrics, AbstractMetrics.Gauge gauge) { + PinotMetric pinotMetric = extractMetric(metrics, gauge.getGaugeName()); + if (pinotMetric == null) { + return 0; + } + return ((YammerSettableGauge<Long>) pinotMetric.getMetric()).value(); + } + + public static boolean globalGaugeExists(AbstractMetrics metrics, String key, AbstractMetrics.Gauge gauge) { + return extractMetric(metrics, gauge.getGaugeName() + "." + key) != null; + } + + public static long getGlobalGaugeValue(AbstractMetrics metrics, String key, AbstractMetrics.Gauge gauge) { + PinotMetric pinotMetric = extractMetric(metrics, gauge.getGaugeName() + "." + key); + if (pinotMetric == null) { + return 0; + } + return ((YammerSettableGauge<Long>) pinotMetric.getMetric()).value(); + } + + public static boolean tableGaugeExists(AbstractMetrics metrics, String tableName, AbstractMetrics.Gauge gauge) { + return extractMetric(metrics, gauge.getGaugeName() + "." + tableName) != null; + } + + public static long getTableGaugeValue(AbstractMetrics metrics, String tableName, AbstractMetrics.Gauge gauge) { + PinotMetric pinotMetric = extractMetric(metrics, gauge.getGaugeName() + "." + tableName); + if (pinotMetric == null) { + return 0; + } + return ((YammerSettableGauge<Long>) pinotMetric.getMetric()).value(); + } + + public static boolean tableGaugeExists(AbstractMetrics metrics, String tableName, String key, + AbstractMetrics.Gauge gauge) { + return extractMetric(metrics, gauge.getGaugeName() + "." + tableName + "." + key) != null; + } + + public static long getTableGaugeValue(AbstractMetrics metrics, String tableName, String key, + AbstractMetrics.Gauge gauge) { + PinotMetric pinotMetric = extractMetric(metrics, gauge.getGaugeName() + "." + tableName + "." + key); + if (pinotMetric == null) { + return 0; + } + return ((YammerSettableGauge<Long>) pinotMetric.getMetric()).value(); + } + + public static boolean partitionGaugeExists(AbstractMetrics metrics, String tableName, int partitionId, + AbstractMetrics.Gauge gauge) { + return extractMetric(metrics, gauge.getGaugeName() + "." + tableName + "." + partitionId) != null; + } + + public static long getPartitionGaugeValue(AbstractMetrics metrics, String tableName, int partitionId, + AbstractMetrics.Gauge gauge) { + PinotMetric pinotMetric = extractMetric(metrics, gauge.getGaugeName() + "." + tableName + "." + partitionId); + if (pinotMetric == null) { Review Comment: This `getValueOfPartitionGauge` is only used in unit tests and integration tests, as long as we don't break those tests, it should be fine even if we don't return `-1` in the new method ########## pinot-common/src/main/java/org/apache/pinot/common/metrics/AbstractMetrics.java: ########## @@ -481,20 +461,6 @@ public long getValueOfTableGauge(final String tableName, final G gauge) { return gaugeValue == null ? 0 : gaugeValue.get(); } - /** - * Gets the value of a table partition gauge. - * - * @param tableName The table name - * @param partitionId The partition name - * @param gauge The gauge to use - */ - public long getValueOfPartitionGauge(final String tableName, final int partitionId, final G gauge) { - final String fullGaugeName = composeTableGaugeName(tableName, String.valueOf(partitionId), gauge); - - AtomicLong gaugeValue = _gaugeValues.get(fullGaugeName); - return gaugeValue == null ? -1 : gaugeValue.get(); Review Comment: This getValueOfPartitionGauge is only used in unit tests and integration tests, as long as we don't break those tests, it should be fine even if we don't return -1 in the new method -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
