Repository navigation
[SERVER] Add Kubernetes engine Pod discovery latency metric - #7722
ruanwenjun wants to merge 5 commits into
Conversation
|
@pan3793 PTAL |
|
@wangzhigang1999 ping PTAL. |
| 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)) | ||
| } |
There was a problem hiding this 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.
There was a problem hiding this 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.
| override def onAdd(pod: Pod): Unit = { | ||
| val observedAt = System.currentTimeMillis() | ||
| if (isSparkEnginePod(pod)) { | ||
| Option(pod.getMetadata.getCreationTimestamp) match { |
There was a problem hiding this 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).
There was a problem hiding this comment.
Moved the Pod timestamp lookup, parsing, and warnings inside MetricsSystem.tracing. Added a test confirming that disabled metrics do not produce timestamp warnings.
| 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") |
There was a problem hiding this comment.
Two small nits here:
- Use
OffsetDateTime.parse(creationTimestamp).toInstant.toEpochMilliinstead ofInstant.parse, sinceInstant.parserejects RFC 3339 numeric offsets on JDK 8. - Align the two
warnmessages to include[$kubernetesInfo]and namespace/name consistently, and handleOption(pod.getMetadata.getNamespace)so an unset namespace does not log asnull/....
There was a problem hiding this 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.
| val conf = KyuubiConf() | ||
| operation.initialize(conf, None) | ||
| metricsSystem.initialize(conf) | ||
| metricsSystem.start() |
There was a problem hiding this 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.
There was a problem hiding this comment.
Disabled reporters in the metric tests and moved initialization and startup inside try/finally, ensuring cleanup also runs when startup fails.
| | `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. | |
There was a problem hiding this 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).
There was a problem hiding this comment.
Wrapped the description in the same <div> style as the other rows and clarified that Pods created before the event handler was created are excluded.
pan3793
left a comment
There was a problem hiding this comment.
LGTM, with one non-blocking test nit.
| val deletedPod = new PodBuilder() | ||
| .withNewMetadata() | ||
| .withName("deleted-driver") | ||
| .withCreationTimestamp(Instant.now().minusSeconds(180).toString) |
There was a problem hiding this comment.
Non-blocking nit: Instant.now().minusSeconds(180) predates handlerCreatedAt, so the non-engine Pod onAdd check below would pass due to the creation-time filter even without isSparkEnginePod. Using Instant.now().toString here would exercise isSparkEnginePod directly.
|
Merge Summary:
Posted by |
Why are the changes needed?
A Spark engine may not be detected by the Kyuubi server until some time after its Pod is created. This delay can contribute to an engine submission timeout, but the existing engine startup metric only covers engines that register successfully.
Add
kyuubi.engine.kubernetes.pod.discovery.latency, a histogram in milliseconds from Pod creation to entry into the informer ADD callback, to help tunekyuubi.engine.kubernetes.submit.timeout. Exclude Pods created before each event handler was created so historical Pods do not inflate the metric. Informer startup behavior is unchanged.How was this patch tested?
All 10 tests in
KubernetesApplicationOperationSuitepassed with JDK 17, without a Kubernetes cluster. The same compiled suite also passed on JDK 8, including timestamp parsing with a numeric timezone offset. Removing the creation-time filter causes the old-Pod regression test to fail.Tests cover ADD latency, repeated ADD events, exclusion of older Pods and UPDATE/DELETE events, invalid timestamps, continued terminal-state handling, non-engine Pods, and disabled metrics. Reporters are disabled in metric tests to avoid binding a fixed port.
Was this patch assisted by generative AI tooling?
Assisted-by: Codex (GPT-6)