diff --git a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java index 4a457174f01..33999bc3b29 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java @@ -209,6 +209,11 @@ public void testGlobalPhoenixMetricsForQueries() throws Exception { assertTrue(GLOBAL_SCAN_BYTES.getMetric().getValue() > 0); assertTrue(GLOBAL_QUERY_TIME.getMetric().getValue() > 0); + // The pool thread records the task times after it gives the scan result to the client. + // Wait until it records them. + getUtility().waitFor(10000, 10, + () -> GLOBAL_TASK_END_TO_END_TIME.getMetric().getNumberOfSamples() > 0 + && GLOBAL_TASK_EXECUTION_TIME.getMetric().getNumberOfSamples() > 0); assertTrue(GLOBAL_TASK_END_TO_END_TIME.getMetric().getValue() > 0); assertTrue(GLOBAL_TASK_EXECUTION_TIME.getMetric().getValue() > 0); @@ -1079,6 +1084,21 @@ private void changeInternalStateForTesting(PhoenixResultSet rs) throws NoSuchFie private void assertReadMetricValuesForSelectSql(ArrayList numRows, ArrayList numExpectedTasks, PhoenixResultSet resultSetBeingTested, Set expectedTableNames) throws SQLException { + // The pool threads record the task times after they give the scan results to the client. + // Wait until each task records its time. The checks below then find any wrong value. + getUtility().waitFor(10000, 10, () -> { + for (Map m : PhoenixRuntime.getRequestReadMetricInfo(resultSetBeingTested) + .values()) { + Long numTasks = m.get(TASK_EXECUTED_COUNTER); + Long taskTime = m.get(TASK_EXECUTION_TIME); + if ( + numTasks == null || taskTime == null || taskTime < numTasks * TASK_EXECUTION_TIME_DELTA + ) { + return false; + } + } + return true; + }); Map> metrics = PhoenixRuntime.getRequestReadMetricInfo(resultSetBeingTested); int counter = 0;