Repository navigation
fix(hygiene): eliminate gRPC fork/ReleaseExecute hazards and clean up logging and notebook output noise #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+2,777
−553
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cd7d03e
fix(grpc): set default GRPC_VERBOSITY=ERROR, pre-warm credentials, an…
dborowitz c146c04
fix(reattach): coalesce concurrent ReleaseUntil RPCs
dborowitz e5500af
fix(logging): remove root basicConfig and gate session/query output o…
dborowitz bff2b7d
refactor: remove test-detection branches and fix non-singleton stop()
dborowitz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """Logging setup. Never configures the root logger.""" | ||
|
|
||
| import logging | ||
| import os | ||
| from typing import Optional | ||
|
|
||
| PACKAGE_LOGGER_NAME = "google.cloud.managed_spark_connect" | ||
| ENV_LOG_LEVEL = "MANAGED_SPARK_CONNECT_LOG_LEVEL" | ||
| _PYSPARK_QUERY_CONTEXT_LOGGERS = ( | ||
| "SQLQueryContextLogger", | ||
| "DataFrameQueryContextLogger", | ||
| ) | ||
|
|
||
|
|
||
| def _parse_level(raw: str) -> Optional[int]: | ||
| """A positive logging level from a name (``DEBUG``) or a number.""" | ||
| raw = raw.strip() | ||
| level = int(raw) if raw.isdigit() else getattr(logging, raw.upper(), None) | ||
| return level if isinstance(level, int) and level > 0 else None | ||
|
|
||
|
|
||
| def configure_package_logger() -> logging.Logger: | ||
| """Give the package logger a NullHandler and apply ``LOG_LEVEL``. | ||
| With ``MANAGED_SPARK_CONNECT_LOG_LEVEL`` set and no handler on the root | ||
| logger, the package logger gets its own ``StreamHandler`` and stops | ||
| propagating, so a later ``logging.basicConfig()`` doesn't print every | ||
| record twice. | ||
| """ | ||
| pkg_logger = logging.getLogger(PACKAGE_LOGGER_NAME) | ||
| if not any(isinstance(h, logging.NullHandler) for h in pkg_logger.handlers): | ||
| pkg_logger.addHandler(logging.NullHandler()) | ||
| level = _parse_level(os.environ.get(ENV_LOG_LEVEL, "")) | ||
| if level is None: | ||
| return pkg_logger | ||
| pkg_logger.setLevel(level) | ||
| has_stream_handler = any( | ||
| not isinstance(h, logging.NullHandler) for h in pkg_logger.handlers | ||
| ) | ||
| if not has_stream_handler and not logging.getLogger().handlers: | ||
| pkg_logger.addHandler(logging.StreamHandler()) | ||
| pkg_logger.propagate = False | ||
| return pkg_logger | ||
|
|
||
|
|
||
| def quiet_pyspark_query_context_loggers() -> None: | ||
| """Stop pyspark from dumping every failed query's context to stderr. | ||
| pyspark's ``SQLQueryContextLogger`` and ``DataFrameQueryContextLogger`` | ||
| write a JSON record with the server stack trace whenever an | ||
| ``AnalysisException`` or similar is built, on top of the exception | ||
| itself. Unless ``SPARK_CONNECT_LOG_LEVEL`` or | ||
| ``MANAGED_SPARK_CONNECT_LOG_LEVEL`` is set, raise both loggers above | ||
| ``CRITICAL``. They are process-wide, so this applies to every pyspark | ||
| session in the process. | ||
| """ | ||
| if ( | ||
| os.environ.get("SPARK_CONNECT_LOG_LEVEL", "").strip() | ||
| or os.environ.get(ENV_LOG_LEVEL, "").strip() | ||
| ): | ||
| return | ||
| from pyspark.logger.logger import PySparkLogger | ||
|
|
||
| for name in _PYSPARK_QUERY_CONTEXT_LOGGERS: | ||
| PySparkLogger.getLogger(name).setLevel(logging.CRITICAL + 1) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.