pan3793 commented on code in PR #7722:
URL: https://github.com/apache/kyuubi/pull/7722#discussion_r4681620221
##########
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:
`inform(...)` performs an initial `LIST` on startup (and on lazy `(context,
namespace)` client initialization) and delivers every pre-existing engine Pod
to `onAdd`. Those Pods can be hours or days old, so `observedAt -
creationTimestamp` records Pod age rather than discovery latency. With
Dropwizard's `ExponentiallyDecayingReservoir` (size 1028), those outliers stay
in `max` and skew high percentiles until enough new Pods arrive, which makes
the metric misleading for tuning `kyuubi.engine.kubernetes.submit.timeout`.
Please exclude initial-list Pods from this metric (for example, enable
latency recording only after `inform(...)` finishes its blocking initial sync,
or skip Pods whose `creationTimestamp` predates informer/handler creation).
Note that `informer.hasSynced()` is not safe for this in Fabric8 6.14.0 because
`lastSyncResourceVersion` is set before queued initial-list `onAdd` callbacks
finish executing.
##########
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:
Please set `.set(MetricsConf.METRICS_REPORTERS, Set.empty[String])` in both
new tests (matching `KyuubiOperationSuite`). With default `KyuubiConf()`,
`MetricsSystem` starts `PrometheusReporterService` on fixed port `10019`, which
can fail with `BindException` when port `10019` is occupied.
Also move `operation.initialize`, `metricsSystem.initialize`, and
`metricsSystem.start` inside `try ... finally` (or into
`beforeEach`/`afterEach`) so a failure during startup does not skip
`operation.stop()` and leak executors.
##########
docs/monitor/metrics.md:
##########
@@ -63,6 +63,7 @@ These metrics include:
| `kyuubi.operation.exec_time` | `${operationType}`
| histogram | 1.7.0 | <div style='width: 150pt;word-wrap:
break-word;white-space: normal'> execution time histogram for the operation
`${operationType}`, now only `ExecuteStatement` is enabled. </div>
|
| `kyuubi.engine.total` |
| counter | 1.2.0 | <div style='width: 150pt;word-wrap:
break-word;white-space: normal'> cumulative created engines</div>
|
| `kyuubi.engine.startup.time` |
| histogram | 1.12.0 | <div style='width: 150pt;word-wrap:
break-word;white-space: normal'> startup time histogram for successfully
created engines, from submitting a new engine to the engine being registered
and discovered by Kyuubi server </div>
|
+| `kyuubi.engine.kubernetes.pod.discovery.latency` |
| histogram | 1.13.0 | Time in milliseconds from Spark engine Pod
creation to the informer ADD callback. Recorded for each ADD event, including
existing Pods discovered during initial listing. UPDATE and DELETE events do
not contribute samples.
|
Review Comment:
Please wrap the description in `<div style='width: 150pt;word-wrap:
break-word;white-space: normal'> ... </div>` to match all other rows in this
table (and update the wording if initial-list Pods are excluded).
##########
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:
Let's move the timestamp lookup, parsing, and warnings inside
`MetricsSystem.tracing { ms => ... }` so we avoid unnecessary parsing and
warning logs when `kyuubi.metrics.enabled=false` (or in unit tests that do not
start `MetricsSystem`).
##########
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:
Two small nits here:
1. Use `OffsetDateTime.parse(creationTimestamp).toInstant.toEpochMilli`
instead of `Instant.parse`, since `Instant.parse` rejects RFC 3339 numeric
offsets on JDK 8.
2. Align the two `warn` messages to include `[$kubernetesInfo]` and
namespace/name consistently, and handle `Option(pod.getMetadata.getNamespace)`
so an unset namespace does not log as `null/...`.
--
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]