ruanwenjun commented on code in PR #7722:
URL: https://github.com/apache/kyuubi/pull/7722#discussion_r4690854834
##########
kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala:
##########
@@ -359,7 +363,26 @@ class KubernetesApplicationOperation extends
ApplicationOperation with Logging {
extends ResourceEventHandler[Pod] {
override def onAdd(pod: Pod): Unit = {
+ val observedAt = System.currentTimeMillis()
if (isSparkEnginePod(pod)) {
+ Option(pod.getMetadata.getCreationTimestamp) match {
+ case Some(creationTimestamp) =>
+ try {
+ val latency = observedAt -
Instant.parse(creationTimestamp).toEpochMilli
+ if (latency >= 0) {
+ MetricsSystem.tracing(_.updateHistogram(
+ ENGINE_KUBERNETES_POD_DISCOVERY_LATENCY,
+ latency))
+ }
Review Comment:
The metric now excludes Pods created before each event handler was created,
covering lazy client initialization without changing informer startup behavior.
Added a regression test to verify that excluded Pods still update application
state.
##########
kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala:
##########
@@ -359,7 +363,26 @@ class KubernetesApplicationOperation extends
ApplicationOperation with Logging {
extends ResourceEventHandler[Pod] {
override def onAdd(pod: Pod): Unit = {
+ val observedAt = System.currentTimeMillis()
if (isSparkEnginePod(pod)) {
+ Option(pod.getMetadata.getCreationTimestamp) match {
Review Comment:
Moved the Pod timestamp lookup, parsing, and warnings inside
`MetricsSystem.tracing`. Added a test confirming that disabled metrics do not
produce timestamp warnings.
##########
kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala:
##########
@@ -359,7 +363,26 @@ class KubernetesApplicationOperation extends
ApplicationOperation with Logging {
extends ResourceEventHandler[Pod] {
override def onAdd(pod: Pod): Unit = {
+ val observedAt = System.currentTimeMillis()
if (isSparkEnginePod(pod)) {
+ Option(pod.getMetadata.getCreationTimestamp) match {
+ case Some(creationTimestamp) =>
+ try {
+ val latency = observedAt -
Instant.parse(creationTimestamp).toEpochMilli
+ if (latency >= 0) {
+ MetricsSystem.tracing(_.updateHistogram(
+ ENGINE_KUBERNETES_POD_DISCOVERY_LATENCY,
+ latency))
+ }
+ } catch {
+ case e: DateTimeParseException =>
+ warn(s"Invalid creation timestamp for engine pod
${pod.getMetadata.getName}", e)
+ }
+ case None =>
+ warn(s"[$kubernetesInfo] Missing creation timestamp for engine pod
" +
+ s"${pod.getMetadata.getNamespace}/${pod.getMetadata.getName}, " +
+ "skipping pod discovery latency metric")
Review Comment:
Switched to `OffsetDateTime.parse(...).toInstant` and verified numeric
timezone offsets on JDK 8. Both warnings now include `kubernetesInfo` and the
Pod name, with the namespace included when available.
##########
kyuubi-server/src/test/scala/org/apache/kyuubi/engine/KubernetesApplicationOperationSuite.scala:
##########
@@ -17,15 +17,113 @@
package org.apache.kyuubi.engine
+import java.time.Instant
+
import io.fabric8.kubernetes.api.model.{ContainerState, ContainerStateWaiting,
PodBuilder}
import org.apache.kyuubi.{KyuubiException, KyuubiFunSuite}
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.engine.ApplicationState.{FAILED, FINISHED, PENDING}
import
org.apache.kyuubi.engine.KubernetesApplicationOperation.LABEL_KYUUBI_UNIQUE_KEY
+import
org.apache.kyuubi.metrics.MetricsConstants.ENGINE_KUBERNETES_POD_DISCOVERY_LATENCY
+import org.apache.kyuubi.metrics.MetricsSystem
class KubernetesApplicationOperationSuite extends KyuubiFunSuite {
+ test("record pod discovery latency only for ADD events") {
+ val operation = new KubernetesApplicationOperation()
+ val metricsSystem = new MetricsSystem
+ val conf = KyuubiConf()
+ operation.initialize(conf, None)
+ metricsSystem.initialize(conf)
+ metricsSystem.start()
Review Comment:
Disabled reporters in the metric tests and moved initialization and startup
inside `try/finally`, ensuring cleanup also runs when startup fails.
--
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]