From ee03decbc9709453b93e096214856412340d7ef1 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 24 Oct 2022 14:58:30 +0200 Subject: [PATCH 1/4] chore(deps): update dependency google-cloud-batch to v0.4.0 (#61) --- samples/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/requirements.txt b/samples/requirements.txt index 9308bb9..e3741b0 100644 --- a/samples/requirements.txt +++ b/samples/requirements.txt @@ -1,3 +1,3 @@ isort==5.10.1 black==22.10.0 -google-cloud-batch==0.3.2 +google-cloud-batch==0.4.0 From 60a8d5cd4a2596dc6bcbc5d10c80683d29cd17ca Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Wed, 26 Oct 2022 12:55:15 +0200 Subject: [PATCH 2/4] chore(deps): update dependency pytest to v7.2.0 (#62) --- samples/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/requirements-test.txt b/samples/requirements-test.txt index 8a1be62..cac8669 100644 --- a/samples/requirements-test.txt +++ b/samples/requirements-test.txt @@ -1,4 +1,4 @@ -pytest==7.1.3 +pytest==7.2.0 google-cloud-compute==1.6.1 google-cloud-resource-manager==1.6.3 google-cloud-storage==2.5.0 \ No newline at end of file From 9b44e35f3da228deae8815ba91a0710fea760b2b Mon Sep 17 00:00:00 2001 From: Maciej Strzelczyk Date: Thu, 27 Oct 2022 15:33:02 +0200 Subject: [PATCH 3/4] docs(samples): Adding code samples for log reading (#56) * docs(samples): Adding code samples for log reading Co-authored-by: Anthonios Partheniou --- samples/requirements-test.txt | 2 +- samples/requirements.txt | 1 + samples/snippets/logs/read_job_logs.py | 39 ++++++++++++++++++++++++++ samples/snippets/tests/test_basics.py | 14 +++++++-- 4 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 samples/snippets/logs/read_job_logs.py diff --git a/samples/requirements-test.txt b/samples/requirements-test.txt index cac8669..586e344 100644 --- a/samples/requirements-test.txt +++ b/samples/requirements-test.txt @@ -1,4 +1,4 @@ pytest==7.2.0 google-cloud-compute==1.6.1 google-cloud-resource-manager==1.6.3 -google-cloud-storage==2.5.0 \ No newline at end of file +google-cloud-storage==2.5.0 diff --git a/samples/requirements.txt b/samples/requirements.txt index e3741b0..06ae926 100644 --- a/samples/requirements.txt +++ b/samples/requirements.txt @@ -1,3 +1,4 @@ isort==5.10.1 black==22.10.0 google-cloud-batch==0.4.0 +google-cloud-logging==3.2.5 diff --git a/samples/snippets/logs/read_job_logs.py b/samples/snippets/logs/read_job_logs.py new file mode 100644 index 0000000..d9c227a --- /dev/null +++ b/samples/snippets/logs/read_job_logs.py @@ -0,0 +1,39 @@ +# Copyright 2022 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. + + +# [START batch_job_logs] +from typing import NoReturn + +from google.cloud import batch_v1 +from google.cloud import logging + + +def print_job_logs(project_id: str, job: batch_v1.Job) -> NoReturn: + """ + Prints the log messages created by given job. + + Args: + project_id: name of the project hosting the job. + job: the job which logs you want to print. + """ + # Initialize client that will be used to send requests across threads. This + # client only needs to be created once, and can be reused for multiple requests. + log_client = logging.Client(project=project_id) + logger = log_client.logger("batch_task_logs") + + for log_entry in logger.list_entries(filter_=f"labels.job_uid={job.uid}"): + print(log_entry.payload) + +# [END batch_job_logs] diff --git a/samples/snippets/tests/test_basics.py b/samples/snippets/tests/test_basics.py index 980314d..72a11f8 100644 --- a/samples/snippets/tests/test_basics.py +++ b/samples/snippets/tests/test_basics.py @@ -27,6 +27,7 @@ from ..get.get_task import get_task from ..list.list_jobs import list_jobs from ..list.list_tasks import list_tasks +from ..logs.read_job_logs import print_job_logs PROJECT = google.auth.default()[1] REGION = 'europe-north1' @@ -82,11 +83,18 @@ def _check_tasks(job_name): print('Tasks tested') -def test_script_job(job_name): +def _check_logs(job, capsys): + print_job_logs(PROJECT, job) + output = [line for line in capsys.readouterr().out.splitlines(keepends=False) if line != ""] + assert len(output) == 4 + assert all(log_msg.startswith("STDOUT") for log_msg in output) + + +def test_script_job(job_name, capsys): job = create_script_job(PROJECT, REGION, job_name) - _test_body(job, additional_test=lambda: _check_tasks(job_name)) + _test_body(job, additional_test=lambda: _check_logs(job, capsys)) def test_container_job(job_name): job = create_container_job(PROJECT, REGION, job_name) - _test_body(job) + _test_body(job, additional_test=lambda: _check_tasks(job_name)) From b8de40b3b90e67ba40f828408c1cff0ab0a13d68 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 27 Oct 2022 15:26:41 -0400 Subject: [PATCH 4/4] chore(main): release 0.4.1 (#63) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- CHANGELOG.md | 7 +++++++ setup.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 754ff04..7a57a13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [0.4.1](https://github.com/googleapis/python-batch/compare/v0.4.0...v0.4.1) (2022-10-27) + + +### Documentation + +* **samples:** Adding code samples for log reading ([#56](https://github.com/googleapis/python-batch/issues/56)) ([9b44e35](https://github.com/googleapis/python-batch/commit/9b44e35f3da228deae8815ba91a0710fea760b2b)) + ## [0.4.0](https://github.com/googleapis/python-batch/compare/v0.3.2...v0.4.0) (2022-10-18) diff --git a/setup.py b/setup.py index a928cf3..d61f02d 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ name = "google-cloud-batch" description = "Cloud Batch API client library" -version = "0.4.0" +version = "0.4.1" release_status = "Development Status :: 4 - Beta" dependencies = [ "google-api-core[grpc] >= 1.33.2, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*",