Skip to content

feat: integrate ManagedSparkSession with Spark Connect cell monitoring - #237

Merged
ptch314 merged 7 commits into
mainfrom
feat/spark-connect-cell-monitoring
Dec 1, 2026
Merged

ptch314 merged 7 commits into
mainfrom
feat/spark-connect-cell-monitoring

Conversation

@ptch314

@ptch314 ptch314 commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Integrates ManagedSparkSession and interactive IPython extras with managed-spark-cell-monitoring's Spark Connect GetStatus poller via a thin lifecycle bridge:

  • Interactive Extras (_ipython.py): Auto-loads managed_spark_cell_monitoring.spark_connect (%cellmonitor) when installed in IPython notebooks, respecting MANAGED_SPARK_CONNECT_ENABLE_EXTRAS and %config ManagedSparkConnect.enable_extras.
  • Client Concurrency (client/core.py): Adds "/GetStatus" to _UNGUARDED_METHOD_SUFFIXES so background GetStatus RPCs can poll concurrently while an ExecutePlan stream is active on the channel.
  • Thin Session Lifecycle Bridge (_cell_monitoring.py, session.py):
    • Lazily resolves managed_spark_cell_monitoring.spark_connect.create_session_poller(...) with zero overhead or extra imports when managed-spark-cell-monitoring is not installed or inactive.
    • Wraps _execute and _execute_and_fetch_as_iterator across full stream lifetimes, classifying completion outcomes (SUCCEEDED, FAILED, CANCELLED) for finish_operation(...).
    • Suppresses duplicate per-operation links and tqdm progress bars while cell monitoring is active for an operation, restoring them automatically via session fallback if the server does not serve CellMonitorTelemetry.

Companion PRs in GoogleCloudDataproc/managed-spark-cell-monitoring:

Testing

  • pyink . --check
  • vermin --no-tips --violations --eval-annotations --target=3.10- google tests setup.py
  • pytest tests/unit/test_cell_monitoring.py tests/unit/test_init.py and full unit test suite
  • python -m build --no-isolation & twine check --strict dist/*

Wires optional notebook cell monitoring into `ManagedSparkSession` and
IPython interactive extras via a lightweight lifecycle bridge:

- `google.cloud.managed_spark_connect._ipython`: auto-loads
  `managed_spark_cell_monitoring.spark_connect` (`%cellmonitor`) alongside
  installed interactive extras when available.
- `google.cloud.managed_spark_connect.client.core`: adds `/GetStatus` to
  `_UNGUARDED_METHOD_SUFFIXES` so background `GetStatus` polling runs
  concurrently with in-flight `ExecutePlan` streams.
- `google.cloud.managed_spark_connect._cell_monitoring` & `session`:
  - Lazily delegates `begin_operation`, `finish_operation(..., outcome=...)`
    (`SUCCEEDED`, `FAILED`, `CANCELLED`), and task progress suppression to
    `managed_spark_cell_monitoring.spark_connect.create_session_poller(...)`
    with zero imports or overhead when the extension is inactive.
  - Restores per-operation Console links and legacy `tqdm` progress bars
    automatically if the session falls back.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a thin lifecycle bridge (SessionCellMonitorBridge) to integrate with managed_spark_cell_monitoring.spark_connect for cell monitoring in Managed Spark Connect sessions. Key changes include tracking operation outcomes, suppressing progress bars, and handling fallbacks. The review feedback highlights three main improvement opportunities: wrapping the exception classification logic in classify_exception_outcome to prevent secondary exceptions from masking the original error, avoiding exception classification in _execute when the operation is not monitored, and ensuring the poller is closed during garbage collection while using getattr instead of direct __dict__ access.

@dborowitz dborowitz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR just sets it up when installed; we're going to need to add it as a dep with [client] too. That is blocked on an upstream version release, but it should be safe to submit this in the meantime.

@dborowitz dborowitz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address remaining gemini comments.

@dborowitz dborowitz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Dave's review agent] Review of e6a9f7c / 5f078ee / 36597f2 (verified locally on 36597f2: 789 unit tests pass, pyink --check passes).

Summary of main items (details in inline comments):

  • Blocking / high priority: unguarded TypeError fallback in SessionCellMonitorBridge.finish_operation can escape into finally: and mask user exceptions or fail succeeded queries.
  • Should-fix: getErrorClass() emits FutureWarning on PySpark 4.x; classify_exception_outcome outer except BaseException swallows interrupts and aborts cause-chain traversal on a broken property; note_spark_tasks_seen fires on Progress.finish() (done=True) after finish_operation; lazy iterators can leak active ops if never iterated; __del__ poller cleanup reachability/weak-client contract and teardown safety; test global-state cleanup and missing coverage; README.md docs for auto-loaded %cellmonitor.
  • History / non-blocking notes:
    • Consider squashing 36597f2 into 5f078ee so the history doesn't carry a PySpark-4.0-only GC test commit.
    • Worth double-checking whether begin_operation should respect showOperationLinks(False) / showProgressBar(False) / non-interactive mode, whether str(exc) substring matching for OPERATION_CANCELED/JOB_CANCELLED could false-positive on echoed error text, and how the monitor handles position-lost replay (seeing op1 FAILED followed by op2 begin_operation for one user query).

Comment thread tests/unit/test_cell_monitoring.py Resolved
@ptch314

ptch314 commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator Author

[Agent] Summary notes on PRR_kwDOMxZWQc8AAAABZZt5qQ (24bbde5):

  • Addressed all 11 inline items above (verified locally: pyink --check clean, vermin 3.10- clean, 792 passed, 17 skipped unit tests; GitHub Actions unit tests, pyink, vermin, and lint-readme green).
  • Kept begin_operation controlled by %cellmonitor / MANAGED_SPARK_CELL_MONITORING_ENABLED / enable_extras rather than showProgressBar(False)/showOperationLinks(False) so hiding tqdm bars alone doesn't implicitly turn off the Cell Monitor widget.
  • Position-lost replay (op1 FAILED -> fresh op2 begin_operation) isolates op1 and op2 under separate operation IDs inside the same cell widget.
  • Kept forward commit history (24bbde5) to preserve existing comment SHA references cleanly for Squash & Merge (happy to squash before merge if preferred).

@ptch314
ptch314 merged commit cdbe7c5 into main Dec 1, 2026
29 checks passed
@ptch314
ptch314 deleted the feat/spark-connect-cell-monitoring branch December 1, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants