-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[batch] Profile more services not just batch-driver (#12681)
* [batch] Profile more services not just batch-driver * fixes * only add the googlecloudprofiler logger filter if invoked * fix HAIL_SHOULD_PROFILE * sort * add cloud env variable to auth * fix
- Loading branch information
1 parent
d2476f7
commit 451fdcc
Showing
8 changed files
with
78 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,30 @@ | ||
import logging | ||
import os | ||
|
||
import googlecloudprofiler | ||
|
||
HAIL_SHA = os.environ['HAIL_SHA'] | ||
HAIL_SHOULD_PROFILE = 'HAIL_SHOULD_PROFILE' in os.environ | ||
DEFAULT_NAMESPACE = os.environ['HAIL_DEFAULT_NAMESPACE'] | ||
CLOUD = os.environ['CLOUD'] | ||
|
||
|
||
def install_profiler_if_requested(service: str): | ||
if HAIL_SHOULD_PROFILE and CLOUD == 'gcp': | ||
profiler_tag = DEFAULT_NAMESPACE | ||
if profiler_tag == 'default': | ||
profiler_tag = DEFAULT_NAMESPACE + f'-{HAIL_SHA[0:12]}' | ||
googlecloudprofiler.start( | ||
service=service, | ||
service_version=profiler_tag, | ||
# https://cloud.google.com/profiler/docs/profiling-python#agent_logging | ||
verbose=3, | ||
) | ||
|
||
def ignore_failed_to_collect_and_upload_profile(record): | ||
if 'Failed to collect and upload profile: [Errno 32] Broken pipe' in record.msg: | ||
record.levelno = logging.INFO | ||
record.levelname = "INFO" | ||
return record | ||
|
||
googlecloudprofiler.logger.addFilter(ignore_failed_to_collect_and_upload_profile) |