Skip to content
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

Add fetch-logs and enable Azure log fetching #259

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open

Conversation

bshifaw
Copy link
Collaborator

@bshifaw bshifaw commented May 9, 2023

Refracted Log command such that code is broken into smaller functions
Added option to download logs
Added Azure components such that files from azure storage containers can be read or downloaded

@bshifaw bshifaw self-assigned this May 9, 2023
@bshifaw bshifaw added the Cromshell 2 Issues related to Cromshell 2.0 label May 9, 2023
@bshifaw bshifaw added this to the Cromshell2.1 milestone May 9, 2023
@bshifaw bshifaw changed the title Bs fetch logs Add fetch-logs and enable Azure log fetching May 10, 2023

def get_task_level_outputs(config, expand_subworkflows, requested_status) -> dict:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Add reason why we're using Metadata api instead of Cromwells logs API as comment in code

"Separate multiple keys by comma or use 'ALL' to print all logs. "
"Some standard Cromwell status options are 'ALL', 'Done', 'RetryableFailure', 'Running', and 'Failed'.",
)
@click.argument("workflow_ids", required=True, nargs=-1)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Accept 1 id at a time because the output of multiple ids might overwhelm user

"backendLogs",
"backend",
"shardIndex",
"stderr",
Copy link
Collaborator Author

@bshifaw bshifaw May 11, 2023

Choose a reason for hiding this comment

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

"As of now cromwell on Azure does not provide backendlogs, hence retrieving stderr and stdout". add as a comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Add the above comment as inline comment

LOGGER.error(f"No calls found for workflow: {workflow_id}")
raise Exception(f"No calls found for workflow: {workflow_id}")

if "log" not in json.dumps(workflow_logs):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

put json.dumps into a string variable instead of calling 3 times

@bshifaw
Copy link
Collaborator Author

bshifaw commented May 25, 2023

Why aren't we using log API?

Copy link
Contributor

@SHuang-Broad SHuang-Broad left a comment

Choose a reason for hiding this comment

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

some minor issues

* List the log files produced by a workflow.
* [COMING SOON] `fetch-logs [workflow-id] [[workflow-id]...]`
* Download all logs produced by a workflow.
* List the log files produced by a workflow, Defaults to print `Failed` status only.
Copy link
Contributor

Choose a reason for hiding this comment

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

indentations seem to be off?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

should be correct.

- command
  - command description
  - command description

@@ -230,6 +234,173 @@ def copy_files_to_directory(
shutil.copy(inputs, directory)


def cat_file(file_path: str or Path, backend: str = None) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

Not saying that you should do it here, but backend is a good candidate to be a enum

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

else:
LOGGER.error(
"Caught an error while trying to download the file from Azure: %s", e
)
Copy link
Contributor

Choose a reason for hiding this comment

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

do you want to re-raise the exception here?
Currently, it only emits an error message, but the program continues.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

return config.cromshell_config_options["azure_storage_account"]
except KeyError:
LOGGER.error(
"An 'azure_storage_account' is required for this action but"
Copy link
Contributor

Choose a reason for hiding this comment

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

In future PRs, we could support reading from env variables

LOGGER.error(
"An 'azure_storage_account' is required for this action but"
"was not found in Cromshell configuration file. "
)
Copy link
Contributor

Choose a reason for hiding this comment

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

re-raise?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@click.pass_obj
def main(
config,
workflow_id: str,
workflow_ids: list,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's switch it to supporting a single workflow.

default="Failed",
help="Return a list with links to the task logs with the indicated status. "
"Separate multiple keys by comma or use 'ALL' to print all logs. "
"Some standard Cromwell status options are 'ALL', 'Done', 'RetryableFailure', 'Running', and 'Failed'.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is status already an enum in config?

or index.get("executionStatus") in requested_status
):
all_task_logs[call].append(
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like a good candidate to be a class


return did_print
check_for_empty_logs(
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this necessary?

print(f"{call}:")
for call_index in index_list:
if call_index is not None:
print_file_like_value_in_dict(
Copy link
Contributor

Choose a reason for hiding this comment

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

If we define a class like recommended above, this could be a method in that class.

@bshifaw bshifaw marked this pull request as ready for review June 28, 2023 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cromshell 2 Issues related to Cromshell 2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants