migrate code from googleapis/python-logging#13844
Conversation
Change-Id: I67e149dc43ebdb11144ac3839e062aa4668ebb2e
Change-Id: I866edcc956fda2265dd7af7b774336930ec6a151
Change-Id: Ieaf7237fc6f925daec46a07d2e81a452b841198a
* Auto-update dependencies. * Explicitly use latest bigtable client Change-Id: Id71e9e768f020730e4ca9514a0d7ebaa794e7d9e * Revert language update for now Change-Id: I8867f154e9a5aae00d0047c9caf880e5e8f50c53 * Remove pdb. smh Change-Id: I5ff905fadc026eebbcd45512d4e76e003e3b2b43
Change-Id: I6691c70912b1e1b5993e962a4827a846642feac3
* Auto-update dependencies. * Fix storage notification poll sample Change-Id: I6afbc79d15e050531555e4c8e51066996717a0f3 * Fix spanner samples Change-Id: I40069222c60d57e8f3d3878167591af9130895cb * Drop coverage because it's not useful Change-Id: Iae399a7083d7866c3c7b9162d0de244fbff8b522 * Try again to fix flaky logging test Change-Id: I6225c074701970c17c426677ef1935bb6d7e36b4
* Update Readme.rst to add Python setup guide As requested in b/64770713. This sample is linked in documentation https://cloud.google.com/bigtable/docs/scaling, and it would make more sense to update the guide here than in the documentation. * Update README.rst * Update README.rst * Update README.rst * Update README.rst * Update README.rst * Update install_deps.tmpl.rst * Updated readmegen scripts and re-generated related README files * Fixed the lint error
Change-Id: I0d420f3053f391fa225e4b8179e45fd1138f5c65
#1233) * Add sample for standard library logging handler configuration * Add handler.py to readme
* chore(python): Add Python 3.12 Source-Link: googleapis/synthtool@af16e6d Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:bacc3af03bff793a03add584537b36b5644342931ad989e3ba1171d3bd5399f5 * add trove classifier for python 3.12 * add python 3.12, and older, as a required check --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
* build: treat warnings as errors * resolve warning Client.dataset is deprecated and will be removed in a future version * See googleapis/python-logging#820 * address warning @pytest.yield_fixture is deprecated. Use @pytest.fixture instead; they are the same. * filter warnings from grpcio * revert * update comment
Co-authored-by: Kevin Zheng <147537668+gkevinzheng@users.noreply.github.com>
* chore(deps): update all dependencies * Update requirements-test.txt for Python 3.7 compatibility --------- Co-authored-by: Kevin Zheng <147537668+gkevinzheng@users.noreply.github.com>
#848) * docs: Added documentation for Django/Flask integrations and dictConfig * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Added product prefix to new snippet * Added client setup in sample + link to settings in documentation * Changed django links to point to `/stable/` links --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
* chore(deps): update all dependencies * pin pytest for python 3.7 --------- Co-authored-by: Anthonios Partheniou <partheniou@google.com>
* docs: Update `dictConfig` snippet to add line that applies the config * Added `import logging.config` into snippet * Update root handlers dict entry in dictConfig * Update usage_guide.py * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Remove propagate config option from loggers * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Added test for dictConfig snippet * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
…ours in export_test.py (#925) * chore: Running this to remove all sinks * readd try block * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * added timestamp to sink name * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Fixed regex string * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
* chore(python): update dependencies in .kokoro/docker/docs Source-Link: googleapis/synthtool@59171c8 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:2ed982f884312e4883e01b5ab8af8b6935f0216a5a2d82928d273081fc3be562 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * add constraints file for Python 3.13 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Remove obsolete release configs and script --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
… setup_logging (#971) * docs: Added documentation on log_level and excluded_loggers params in setup_logging * Added product prefix to new region tags.
* test: Added cleanup of old sink storage buckets * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * add list_buckets threshold --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
This PR adds python 3.14 support to the python-logging package. Expanding off of Omair's work here: googleapis/python-logging#1055 --------- Co-authored-by: ohmayr <omairn@google.com> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Kevin Zheng <kevzheng@google.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Summary of ChangesHello @chalmerlowe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This extensive pull request orchestrates a major update and migration of the Python samples for Google Cloud Logging. It systematically transitions the sample code to leverage the latest Highlights
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This PR migrates a large number of logging samples and generated snippets. The changes are extensive, adding new samples for various logging features like sinks, metrics, and handlers, along with corresponding tests and configuration files. The new samples are a great addition. I've reviewed the code and found a few areas for improvement, mainly related to security best practices in the usage guide snippets and a minor bug in command-line argument parsing in another snippet.
| # [START sink_bucket_permissions] | ||
| bucket.acl.reload() # API call | ||
| logs_group = bucket.acl.group("cloud-logs@google.com") | ||
| logs_group.grant_owner() |
There was a problem hiding this comment.
The OWNER permission is overly permissive for exporting logs to a Cloud Storage bucket. The logging service account only requires WRITER permission to create log files. Granting OWNER permission violates the principle of least privilege as it allows the service account to manage bucket properties and even delete the bucket. Please use grant_writer() instead.
| logs_group.grant_owner() | |
| logs_group.grant_writer() |
| topic = client.create_topic(request={"name": topic_path}) | ||
|
|
||
| policy = client.get_iam_policy(request={"resource": topic_path}) # API call | ||
| policy.bindings.add(role="roles/owner", members=["group:cloud-logs@google.com"]) |
There was a problem hiding this comment.
The roles/owner IAM role is overly permissive for this use case. To allow the logging service account to publish messages to the Pub/Sub topic, the roles/pubsub.publisher role is sufficient and follows the principle of least privilege.
| policy.bindings.add(role="roles/owner", members=["group:cloud-logs@google.com"]) | |
| policy.bindings.add(role="roles/pubsub.publisher", members=["group:cloud-logs@google.com"]) |
| parser = argparse.ArgumentParser( | ||
| description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter | ||
| ) | ||
| parser.add_argument("logger_name", help="Logger name", default="example_log") |
There was a problem hiding this comment.
The default value for a positional argparse argument is only used when nargs is set to ? or *. As it is, logger_name is a required argument, and the provided default "example_log" will never be used. To make the argument optional with a default value, you should add nargs="?".
| parser.add_argument("logger_name", help="Logger name", default="example_log") | |
| parser.add_argument("logger_name", help="Logger name", nargs="?", default="example_log") |
39ab60b to
2b16cce
Compare
removing noxfile to avoid conflicts.
|
Note to self:
|
retry_asyncinstead ofretryin async client (transcribe 3gp audio #816)dictConfigsnippet (Updates library version. #885)Description
Fixes #
Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.
Checklist
nox -s py-3.9(see Test Environment Setup)nox -s lint(see Test Environment Setup)