Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

docs(samples): Adding code samples for log reading #56

Merged
merged 11 commits into from
Oct 27, 2022
Merged

Conversation

m-strzelczyk
Copy link
Contributor

Preparing code samples for this page.

@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: batch Issues related to the googleapis/python-batch API. samples Issues that are directly related to samples. labels Oct 13, 2022
@m-strzelczyk m-strzelczyk marked this pull request as ready for review October 13, 2022 18:46
@m-strzelczyk m-strzelczyk requested a review from a team as a code owner October 13, 2022 18:46
@m-strzelczyk m-strzelczyk requested a review from kurtisvg October 13, 2022 18:46
@snippet-bot
Copy link

snippet-bot bot commented Oct 13, 2022

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Comment on lines 23 to 27
def get_job_logs(project_id: str, job: batch_v1.Job) -> Generator[logging.TextEntry, None, None]:
log_client = logging.Client(project=project_id)
logger = log_client.logger("batch_task_logs")

yield from logger.list_entries(filter_=f"labels.job_uid={job.uid}")

Choose a reason for hiding this comment

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

Does this really need to be a seperate function? Can we not just iterate over logger.list_entries directly?

If not, can we provide some context why, and maybe use an inline function so the client and log can be part of the main function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put it in separate function for easier testing. I use this in test, while the printing function can be untested.

I can change it to read the stdout and see if it works that way if you prefer.

Choose a reason for hiding this comment

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

It's an explicit goal of the samples style guide to test the output of the function itself and not use return types: https://googlecloudplatform.github.io/samples-style-guide/#result

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kurtisvg I made the sample fit in one function and just print the logs.

@m-strzelczyk
Copy link
Contributor Author

@kurtisvg I applied some of your comments and suggestions. I kept the log retrieving as 2 separate function for easy testing and so that people can easily copy the log retrieving part for their code. Please let me know if you can accept this division.

@m-strzelczyk m-strzelczyk requested a review from kurtisvg October 19, 2022 13:43
@m-strzelczyk m-strzelczyk added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 21, 2022
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 21, 2022
@m-strzelczyk m-strzelczyk merged commit 9b44e35 into main Oct 27, 2022
@m-strzelczyk m-strzelczyk deleted the samples-logs branch October 27, 2022 13:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: batch Issues related to the googleapis/python-batch API. samples Issues that are directly related to samples. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants