This is an automated email from the ASF dual-hosted git repository. stoty pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push: new 28de55b PHOENIX-5537 Phoenix-4701 made hard coupling between phoenix.log.level and getting request metrics. 28de55b is described below commit 28de55b5c79a5fc32dee97a59e5b4f528ca6dce6 Author: Richard Antal <antal97rich...@gmail.com> AuthorDate: Tue Feb 11 15:09:26 2020 +0100 PHOENIX-5537 Phoenix-4701 made hard coupling between phoenix.log.level and getting request metrics. --- .../org/apache/phoenix/monitoring/MetricUtil.java | 15 ++++++- .../phoenix/monitoring/MetricsStopWatch.java | 5 +++ .../phoenix/monitoring/OverAllQueryMetrics.java | 24 ++++++---- .../apache/phoenix/monitoring/MetricUtilTest.java | 51 ++++++++++++++++++++++ 4 files changed, 85 insertions(+), 10 deletions(-) diff --git a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/MetricUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/MetricUtil.java index e792c08..1974eb8 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/MetricUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/MetricUtil.java @@ -22,9 +22,20 @@ import org.apache.phoenix.monitoring.CombinableMetric.NoOpRequestMetric; public class MetricUtil { - public static CombinableMetric getCombinableMetric(boolean isRequestMetricsEnabled, LogLevel connectionLogLevel, MetricType type) { - if (!type.isLoggingEnabled(connectionLogLevel) && !isRequestMetricsEnabled) { return NoOpRequestMetric.INSTANCE; } + public static CombinableMetric getCombinableMetric(boolean isRequestMetricsEnabled, + LogLevel connectionLogLevel, + MetricType type) { + if (!type.isLoggingEnabled(connectionLogLevel) && !isRequestMetricsEnabled) { + return NoOpRequestMetric.INSTANCE; } return new CombinableMetricImpl(type); } + public static MetricsStopWatch getMetricsStopWatch(boolean isRequestMetricsEnabled, + LogLevel connectionLogLevel, + MetricType type) { + if(!type.isLoggingEnabled(connectionLogLevel) && !isRequestMetricsEnabled) { + return new MetricsStopWatch(false); } + return new MetricsStopWatch(true); + } + } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/MetricsStopWatch.java b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/MetricsStopWatch.java index ee260a8..a852ca9 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/MetricsStopWatch.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/MetricsStopWatch.java @@ -56,4 +56,9 @@ final class MetricsStopWatch { } return 0; } + + @com.google.common.annotations.VisibleForTesting + final boolean getMetricsEnabled(){ + return isMetricsEnabled; + } } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/OverAllQueryMetrics.java b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/OverAllQueryMetrics.java index 9a2f426..6202eee 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/monitoring/OverAllQueryMetrics.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/monitoring/OverAllQueryMetrics.java @@ -43,14 +43,22 @@ public class OverAllQueryMetrics { private final CombinableMetric cacheRefreshedDueToSplits; public OverAllQueryMetrics(boolean isRequestMetricsEnabled, LogLevel connectionLogLevel) { - queryWatch = new MetricsStopWatch(WALL_CLOCK_TIME_MS.isLoggingEnabled(connectionLogLevel)); - resultSetWatch = new MetricsStopWatch(RESULT_SET_TIME_MS.isLoggingEnabled(connectionLogLevel)); - numParallelScans = MetricUtil.getCombinableMetric(isRequestMetricsEnabled,connectionLogLevel, NUM_PARALLEL_SCANS); - wallClockTimeMS = MetricUtil.getCombinableMetric(isRequestMetricsEnabled,connectionLogLevel, WALL_CLOCK_TIME_MS); - resultSetTimeMS = MetricUtil.getCombinableMetric(isRequestMetricsEnabled,connectionLogLevel, RESULT_SET_TIME_MS); - queryTimedOut = MetricUtil.getCombinableMetric(isRequestMetricsEnabled,connectionLogLevel, QUERY_TIMEOUT_COUNTER); - queryFailed = MetricUtil.getCombinableMetric(isRequestMetricsEnabled,connectionLogLevel, QUERY_FAILED_COUNTER); - cacheRefreshedDueToSplits = MetricUtil.getCombinableMetric(isRequestMetricsEnabled,connectionLogLevel, CACHE_REFRESH_SPLITS_COUNTER); + queryWatch = MetricUtil.getMetricsStopWatch(isRequestMetricsEnabled, connectionLogLevel, + WALL_CLOCK_TIME_MS); + resultSetWatch = MetricUtil.getMetricsStopWatch(isRequestMetricsEnabled, connectionLogLevel, + RESULT_SET_TIME_MS); + numParallelScans = MetricUtil.getCombinableMetric(isRequestMetricsEnabled, + connectionLogLevel, NUM_PARALLEL_SCANS); + wallClockTimeMS = MetricUtil.getCombinableMetric(isRequestMetricsEnabled, + connectionLogLevel, WALL_CLOCK_TIME_MS); + resultSetTimeMS = MetricUtil.getCombinableMetric(isRequestMetricsEnabled, + connectionLogLevel, RESULT_SET_TIME_MS); + queryTimedOut = MetricUtil.getCombinableMetric(isRequestMetricsEnabled, + connectionLogLevel, QUERY_TIMEOUT_COUNTER); + queryFailed = MetricUtil.getCombinableMetric(isRequestMetricsEnabled, + connectionLogLevel, QUERY_FAILED_COUNTER); + cacheRefreshedDueToSplits = MetricUtil.getCombinableMetric(isRequestMetricsEnabled, + connectionLogLevel, CACHE_REFRESH_SPLITS_COUNTER); } public void updateNumParallelScans(long numParallelScans) { diff --git a/phoenix-core/src/test/java/org/apache/phoenix/monitoring/MetricUtilTest.java b/phoenix-core/src/test/java/org/apache/phoenix/monitoring/MetricUtilTest.java new file mode 100644 index 0000000..141ce72 --- /dev/null +++ b/phoenix-core/src/test/java/org/apache/phoenix/monitoring/MetricUtilTest.java @@ -0,0 +1,51 @@ +/* + * 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 org.apache.phoenix.log.LogLevel; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.apache.phoenix.monitoring.MetricType.RESULT_SET_TIME_MS; +import static org.apache.phoenix.monitoring.MetricType.WALL_CLOCK_TIME_MS; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +@RunWith(MockitoJUnitRunner.class) +public class MetricUtilTest { + + @Test + public void testGetMetricsStopWatchWithMetricsTrue() throws Exception { + MetricsStopWatch metricsStopWatch = MetricUtil.getMetricsStopWatch(true, + LogLevel.OFF, WALL_CLOCK_TIME_MS); + assertTrue(metricsStopWatch.getMetricsEnabled()); + metricsStopWatch.start(); + + metricsStopWatch = MetricUtil.getMetricsStopWatch(false, + LogLevel.INFO, RESULT_SET_TIME_MS); + assertTrue(metricsStopWatch.getMetricsEnabled()); + } + + @Test + public void testGetMetricsStopWatchWithMetricsFalse() throws Exception { + MetricsStopWatch metricsStopWatch = MetricUtil.getMetricsStopWatch(false, + LogLevel.OFF, WALL_CLOCK_TIME_MS); + assertFalse(metricsStopWatch.getMetricsEnabled()); + } +}