diff --git a/docs/monitor/metrics.md b/docs/monitor/metrics.md
index 561014c370c..c44d8f9edbe 100644
--- a/docs/monitor/metrics.md
+++ b/docs/monitor/metrics.md
@@ -60,7 +60,7 @@ These metrics include:
| `kyuubi.operation.opened` | `${operationType}` | counter | 1.5.0 |
current opened count for the operation `${operationType}`
|
| `kyuubi.operation.failed` | `${operationType}`
`.${errorType}` | counter | 1.5.0 | cumulative failed count for the operation `${operationType}` with a particular `${errorType}`, e.g. `execute_statement.AnalysisException`
|
| `kyuubi.operation.state` | `${operationState}` | meter | 1.5.0 | kyuubi operation state rate
|
-| `kyuubi.operation.exec_time` | `${operationType}` | histogram | 1.7.0 | execution time histogram for the operation `${operationType}`, now only `ExecuteStatement` is enabled.
|
+| `kyuubi.operation.exec_time` | `${operationType}` | histogram | 1.7.0 | execution time histogram for the operation `${operationType}`.
|
| `kyuubi.engine.total` | | counter | 1.2.0 | cumulative created engines
|
| `kyuubi.engine.timeout` | | counter | 1.2.0 | cumulative timeout engines
|
| `kyuubi.engine.failed` | `${user}` | counter | 1.2.0 | cumulative explicitly failed engine count for a `${user}`
|
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/ExecuteStatement.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/ExecuteStatement.scala
index 026d4be2ddb..4bae5c70d98 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/ExecuteStatement.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/ExecuteStatement.scala
@@ -19,12 +19,9 @@ package org.apache.kyuubi.operation
import scala.collection.JavaConverters._
-import com.codahale.metrics.MetricRegistry
-
import org.apache.kyuubi.KyuubiSQLException
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf.OPERATION_QUERY_TIMEOUT_MONITOR_ENABLED
-import org.apache.kyuubi.metrics.{MetricsConstants, MetricsSystem}
import org.apache.kyuubi.operation.FetchOrientation.FETCH_NEXT
import org.apache.kyuubi.operation.log.OperationLog
import org.apache.kyuubi.session.Session
@@ -139,12 +136,6 @@ class ExecuteStatement(
}
sendCredentialsIfNeeded()
}
- MetricsSystem.tracing { ms =>
- val execTime = System.currentTimeMillis() - startTime
- ms.updateHistogram(
- MetricRegistry.name(MetricsConstants.OPERATION_EXEC_TIME, opType),
- execTime)
- }
// see if anymore log could be fetched
fetchQueryLog()
} catch onError()
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/KyuubiOperation.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/KyuubiOperation.scala
index d0289abb99a..943a647fce0 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/KyuubiOperation.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/KyuubiOperation.scala
@@ -25,7 +25,7 @@ import org.apache.commons.lang3.StringUtils
import org.apache.kyuubi.{KyuubiSQLException, Utils}
import org.apache.kyuubi.config.KyuubiReservedKeys.KYUUBI_OPERATION_HANDLE_KEY
import org.apache.kyuubi.events.{EventBus, KyuubiOperationEvent}
-import org.apache.kyuubi.metrics.MetricsConstants.{OPERATION_FAIL, OPERATION_OPEN, OPERATION_STATE, OPERATION_TOTAL}
+import org.apache.kyuubi.metrics.MetricsConstants.{OPERATION_EXEC_TIME, OPERATION_FAIL, OPERATION_OPEN, OPERATION_STATE, OPERATION_TOTAL}
import org.apache.kyuubi.metrics.MetricsSystem
import org.apache.kyuubi.operation.FetchOrientation.FetchOrientation
import org.apache.kyuubi.operation.OperationState.OperationState
@@ -210,8 +210,11 @@ abstract class KyuubiOperation(session: Session) extends AbstractOperation(sessi
override def setState(newState: OperationState): Unit = {
MetricsSystem.tracing { ms =>
- if (!OperationState.isTerminal(state)) {
+ if (!isTerminalState(state)) {
ms.markMeter(MetricRegistry.name(OPERATION_STATE, opType, state.toString.toLowerCase), -1)
+ } else {
+ val execTime = System.currentTimeMillis() - startTime
+ ms.updateHistogram(MetricRegistry.name(OPERATION_EXEC_TIME, opType), execTime)
}
ms.markMeter(MetricRegistry.name(OPERATION_STATE, opType, newState.toString.toLowerCase))
ms.markMeter(MetricRegistry.name(OPERATION_STATE, newState.toString.toLowerCase))
diff --git a/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerUserSuite.scala b/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerUserSuite.scala
index de491e03f21..0f22ff9960f 100644
--- a/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerUserSuite.scala
+++ b/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerUserSuite.scala
@@ -325,14 +325,20 @@ class KyuubiOperationPerUserSuite
}
}
- test("trace ExecuteStatement exec time histogram") {
+ test("trace KyuubiOperation exec time histogram") {
withJdbcStatement() { statement =>
statement.executeQuery("select engine_name()")
+ statement.executeQuery("KYUUBI DESC ENGINE")
}
- val metric =
- s"${MetricsConstants.OPERATION_EXEC_TIME}.${classOf[ExecuteStatement].getSimpleName}"
- val snapshot = MetricsSystem.histogramSnapshot(metric).get
- assert(snapshot.getMax > 0 && snapshot.getMedian > 0)
+ Seq(
+ classOf[LaunchEngine].getSimpleName,
+ classOf[ExecutedCommandExec].getSimpleName,
+ classOf[ExecuteStatement].getSimpleName)
+ .map(className => s"${MetricsConstants.OPERATION_EXEC_TIME}.$className")
+ .foreach { metric =>
+ val snapshot = MetricsSystem.histogramSnapshot(metric).get
+ assert(snapshot.getMax > 0 && snapshot.getMedian > 0)
+ }
}
test("align the server/engine session/executeStatement handle for Spark engine") {