Repository navigation
feat: integrate ManagedSparkSession with Spark Connect cell monitoring - #237
Conversation
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Please address remaining gemini comments.
dborowitz
left a comment
There was a problem hiding this comment.
[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
TypeErrorfallback inSessionCellMonitorBridge.finish_operationcan escape intofinally:and mask user exceptions or fail succeeded queries. - Should-fix:
getErrorClass()emitsFutureWarningon PySpark 4.x;classify_exception_outcomeouterexcept BaseExceptionswallows interrupts and aborts cause-chain traversal on a broken property;note_spark_tasks_seenfires onProgress.finish()(done=True) afterfinish_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.mddocs for auto-loaded%cellmonitor. - History / non-blocking notes:
- Consider squashing
36597f2into5f078eeso the history doesn't carry a PySpark-4.0-only GC test commit. - Worth double-checking whether
begin_operationshould respectshowOperationLinks(False)/showProgressBar(False)/ non-interactive mode, whetherstr(exc)substring matching forOPERATION_CANCELED/JOB_CANCELLEDcould false-positive on echoed error text, and how the monitor handles position-lost replay (seeingop1FAILEDfollowed byop2begin_operationfor one user query).
- Consider squashing
…s, and test review
|
[Agent] Summary notes on
|
Summary
Integrates
ManagedSparkSessionand interactive IPython extras withmanaged-spark-cell-monitoring's Spark ConnectGetStatuspoller via a thin lifecycle bridge:_ipython.py): Auto-loadsmanaged_spark_cell_monitoring.spark_connect(%cellmonitor) when installed in IPython notebooks, respectingMANAGED_SPARK_CONNECT_ENABLE_EXTRASand%config ManagedSparkConnect.enable_extras.client/core.py): Adds"/GetStatus"to_UNGUARDED_METHOD_SUFFIXESso backgroundGetStatusRPCs can poll concurrently while anExecutePlanstream is active on the channel._cell_monitoring.py,session.py):managed_spark_cell_monitoring.spark_connect.create_session_poller(...)with zero overhead or extra imports whenmanaged-spark-cell-monitoringis not installed or inactive._executeand_execute_and_fetch_as_iteratoracross full stream lifetimes, classifying completion outcomes (SUCCEEDED,FAILED,CANCELLED) forfinish_operation(...).tqdmprogress bars while cell monitoring is active for an operation, restoring them automatically via session fallback if the server does not serveCellMonitorTelemetry.Companion PRs in
GoogleCloudDataproc/managed-spark-cell-monitoring:GetStatus+cell_monitor.protostubs)GetStatuspoller & AnyWidget snapshot mode, stacked on fix: unit test expected error message #54)Testing
pyink . --checkvermin --no-tips --violations --eval-annotations --target=3.10- google tests setup.pypytest tests/unit/test_cell_monitoring.py tests/unit/test_init.pyand full unit test suitepython -m build --no-isolation&twine check --strict dist/*