Skip to content

feat(spark): add get_job_metrics to SparkClient - #692

Open
Sharkyii wants to merge 1 commit into
kubeflow:mainfrom
Sharkyii:spark-job-metrics
Open

feat(spark): add get_job_metrics to SparkClient#692
Sharkyii wants to merge 1 commit into
kubeflow:mainfrom
Sharkyii:spark-job-metrics

Conversation

@Sharkyii

@Sharkyii Sharkyii commented Jul 30, 2026

Copy link
Copy Markdown

What this PR does / why we need it:

SparkClient.get_job and get_job_logs cover status and logs for a batch job, but there's no visibility into what's actually happening while it runs, no executor count, no task progress, nothing. This adds get_job_metrics(name), which pulls basic runtime metrics from Spark's own REST API on the driver's web UI (executor counts, task counts, stage progress).

The Spark Operator creates a Service for the driver web UI on every SparkApplication. Rather than constructing that name (<app-name>-ui-svc), which the operator itself truncates and hashes past the 63 character DNS label limit, this looks the service up by the sparkoperator.k8s.io/app-name label the operator sets on it, and reuses the existing port-forward pattern from get_connect_url for out-of-cluster access.

Returns an empty SparkJobMetrics instead of raising when metrics aren't available, covering three real cases: the driver hasn't started yet, the SparkApplication has already been cleaned up, or the cluster's Spark Operator was deployed with --enable-ui-service=false (defaults to true, but it's an operator-level flag, so it can't be assumed present).

Opening as a draft since the approach hasn't had maintainer eyes on it yet, see the open questions on #689. Happy to adjust the field set on SparkJobMetrics or the fallback behavior based on feedback.

Testing done:

  • Unit tests: no app id yet, no UI service found, successful in-cluster fetch, REST API unreachable
  • make verify (ruff check + format) clean
  • uv run pytest kubeflow/spark/ passes (268 tests)

Which issue(s) this PR fixes:

Fixes #689

Checklist:

  • Docs included if any changes are user facing

Batch jobs have status and logs but no visibility into what's actually
running, no executor count, no task progress. This pulls basic runtime
metrics off the driver's web UI service via Spark's own REST API.

Looks the UI service up by the sparkoperator.k8s.io/app-name label
instead of guessing its name, since the operator truncates and hashes
names past the 63 char DNS limit. Falls back to an empty
SparkJobMetrics rather than raising when the service isn't there yet,
already gone, or the operator has it disabled entirely.

Part of the observability work tracked in kubeflow#655 and scoped in kubeflow#689.

Signed-off-by: Sneh Kansagara <snehkansagara@gmail.com>
@google-oss-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign kramaranya for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Sharkyii
Sharkyii marked this pull request as ready for review July 30, 2026 17:22
@google-oss-prow
google-oss-prow Bot requested a review from andreyvelich July 30, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Spark metrics collection via Spark REST API

1 participant