-
Notifications
You must be signed in to change notification settings - Fork 2
implement cluster_report_destination_override #93
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1f1e433
implement cluster_report_destination_override
brandon-kaplan 431df19
moved write_file definition out of the _monitor_cluster method for co…
brandon-kaplan 577893a
expand testing
brandon-kaplan e81b44c
add PR template!
brandon-kaplan 500260e
dependabot fix
brandon-kaplan 6b6b1af
bump version
brandon-kaplan 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Summary | ||
|
|
||
| *please add a few lines to give the reviewer context on the changes* | ||
|
|
||
| ## Checklist | ||
|
|
||
| Before formally opening this PR, please adhere to the following standards: | ||
|
|
||
| - [ ] Branch/PR names begin with the related Jira ticket id (ie PROD-31) for Jira integration | ||
| - [ ] File names are lower_snake_case | ||
| - [ ] Relevant unit tests have been added or not applicable | ||
| - [ ] Relevant documentation has been added or not applicable | ||
| - [ ] Mark yourself as the assignee (makes it easier to scan the PR list) | ||
|
|
||
| [Related Jira Ticket](https://synccomputing.atlassian.net/browse/PROD-) (add id) | ||
|
|
||
| Add any relevant testing examples or screenshots. |
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 |
|---|---|---|
|
|
@@ -4,4 +4,6 @@ __pycache__ | |
| *.swo | ||
| venv/* | ||
| .idea/* | ||
| .python-version | ||
| .python-version | ||
| .DS_Store | ||
| .venv | ||
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| """Library for leveraging the power of Sync""" | ||
| __version__ = "0.6.3" | ||
| __version__ = "0.6.4" | ||
|
|
||
| TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" |
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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import json | ||
| import logging | ||
| from pathlib import Path | ||
| from time import sleep | ||
| from typing import List, Tuple | ||
| from urllib.parse import urlparse | ||
|
|
@@ -335,7 +336,11 @@ def _get_aws_cluster_info_from_s3(bucket: str, file_key: str, cluster_id): | |
| logger.warning(f"Failed to retrieve cluster info from S3 with key, '{file_key}': {err}") | ||
|
|
||
|
|
||
| def monitor_cluster(cluster_id: str, polling_period: int = 20) -> None: | ||
| def monitor_cluster( | ||
| cluster_id: str, | ||
| polling_period: int = 20, | ||
| cluster_report_destination_override: dict = None, | ||
| ) -> None: | ||
| cluster = get_default_client().get_cluster(cluster_id) | ||
| spark_context_id = cluster.get("spark_context_id") | ||
|
|
||
|
|
@@ -347,16 +352,26 @@ def monitor_cluster(cluster_id: str, polling_period: int = 20) -> None: | |
| spark_context_id = cluster.get("spark_context_id") | ||
|
|
||
| (log_url, filesystem, bucket, base_prefix) = _cluster_log_destination(cluster) | ||
| if log_url: | ||
| if cluster_report_destination_override: | ||
| filesystem = cluster_report_destination_override.get("filesystem", filesystem) | ||
| base_prefix = cluster_report_destination_override.get("base_prefix", base_prefix) | ||
|
|
||
| if log_url or cluster_report_destination_override: | ||
| _monitor_cluster( | ||
| (log_url, filesystem, bucket, base_prefix), cluster_id, spark_context_id, polling_period | ||
| (log_url, filesystem, bucket, base_prefix), | ||
| cluster_id, | ||
| spark_context_id, | ||
| polling_period, | ||
| ) | ||
| else: | ||
| logger.warning("Unable to monitor cluster due to missing cluster log destination - exiting") | ||
|
|
||
|
|
||
| def _monitor_cluster( | ||
| cluster_log_destination, cluster_id: str, spark_context_id: int, polling_period: int | ||
| cluster_log_destination, | ||
| cluster_id: str, | ||
| spark_context_id: int, | ||
| polling_period: int, | ||
| ) -> None: | ||
|
|
||
| (log_url, filesystem, bucket, base_prefix) = cluster_log_destination | ||
|
|
@@ -368,20 +383,7 @@ def _monitor_cluster( | |
| aws_region_name = DB_CONFIG.aws_region_name | ||
| ec2 = boto.client("ec2", region_name=aws_region_name) | ||
|
|
||
| if filesystem == "s3": | ||
| s3 = boto.client("s3") | ||
|
|
||
| def write_file(body: bytes): | ||
| logger.info("Saving state to S3") | ||
| s3.put_object(Bucket=bucket, Key=file_key, Body=body) | ||
|
|
||
| elif filesystem == "dbfs": | ||
| path = format_dbfs_filepath(file_key) | ||
| dbx_client = get_default_client() | ||
|
|
||
| def write_file(body: bytes): | ||
| logger.info("Saving state to DBFS") | ||
| write_dbfs_file(path, body, dbx_client) | ||
| write_file = _define_write_file(file_key, filesystem, bucket) | ||
|
|
||
| all_inst_by_id = {} | ||
| active_timelines_by_id = {} | ||
|
|
@@ -428,6 +430,40 @@ def write_file(body: bytes): | |
| sleep(polling_period) | ||
|
|
||
|
|
||
| def _define_write_file(file_key, filesystem, bucket): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice moving logic into sub-functions! |
||
| if filesystem == "file": | ||
| file_path = Path(f"{Path.home()}{file_key}") | ||
|
|
||
| def ensure_path_exists(report_path: Path): | ||
| logger.info(f"Ensuring path exists for {report_path}") | ||
| report_path.parent.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| def write_file(body: bytes): | ||
| logger.info("Saving state to local file") | ||
| ensure_path_exists(file_path) | ||
| with open(file_path, "wb") as f: | ||
| f.write(body) | ||
|
|
||
| elif filesystem == "s3": | ||
| s3 = boto.client("s3") | ||
|
|
||
| def write_file(body: bytes): | ||
| logger.info("Saving state to S3") | ||
| s3.put_object(Bucket=bucket, Key=file_key, Body=body) | ||
|
|
||
| elif filesystem == "dbfs": | ||
| path = format_dbfs_filepath(file_key) | ||
| dbx_client = get_default_client() | ||
|
|
||
| def write_file(body: bytes): | ||
| logger.info("Saving state to DBFS") | ||
| write_dbfs_file(path, body, dbx_client) | ||
|
|
||
| else: | ||
| raise ValueError(f"Unsupported filesystem: {filesystem}") | ||
| return write_file | ||
|
|
||
|
|
||
| def _get_ec2_instances(cluster_id: str, ec2_client: "botocore.client.ec2") -> List[dict]: | ||
|
|
||
| filters = [ | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it better to type the None as Optional too?