From d282153f7cc2bc07198ccb44bf2b33f04ae96cd9 Mon Sep 17 00:00:00 2001 From: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Date: Mon, 28 Sep 2020 15:52:17 -0700 Subject: [PATCH 01/77] move monitoring samples from python-docs-samples (#51) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add Monitoring v3 Samples Refactor v2 samples in to separate directory Add v3 Samples Renamed auth to list_env * Update requirements * Fix metric.name All the filters should be metric.type (API change, name is now the fully qualified REST resource). * Monitoring Doc Fixups * Use Main Project (now whitelisted) * Fix minor typo in custom_metric.py * Mark Monitoring As Flaky * Updating requirements. Change-Id: I95c7ddfe77430a2800d09e329f23ba8b2b939be2 * Don’t send name in create custom metric * updating requirements [(#358)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/358) Change-Id: I6177a17fad021e26ed76679d9db34848c17b62a8 * Update Reqs * Fix flaky custom metric test. Change-Id: Ia2628f205537099d28415412fe302763f17c3081 * Update requirements. [(#436)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/436) * Remove output only fields [(#454)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/454) * Auto-update dependencies. [(#459)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/459) * Fix import order lint errors Change-Id: Ieaf7237fc6f925daec46a07d2e81a452b841198a * bump Change-Id: I02e7767d13ba267ee9fc72c5b68a57013bb8b8d3 * Auto-update dependencies. [(#470)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/470) * Auto-update dependencies. [(#476)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/476) * Auto-update dependencies. [(#486)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/486) * Stackdriver product rename [(#508)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/508) * Auto-update dependencies. [(#537)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/537) * Fix lint issues Change-Id: I0af78055cf33393a737f44acea2ba14555f494e1 * Fix monitoring test Change-Id: I31c4dc368617996bc5b95c1414a39b9d45e11ebe * Auto-update dependencies. [(#584)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/584) * Generate readmes for most service samples [(#599)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/599) * Auto-update dependencies. [(#609)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/609) * Auto-update dependencies. [(#625)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/625) * Auto-update dependencies. [(#629)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/629) * Auto-update dependencies. [(#735)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/735) * Auto-update dependencies. * Fix language OCR sample * Remove unused import * Add region tags for writing time series [(#757)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/757) * Auto-update dependencies. [(#762)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/762) * Cleanup metric descriptors [(#776)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/776) * Auto-update dependencies. [(#783)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/783) * Auto-update dependencies. [(#785)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/785) * Auto-update dependencies. [(#790)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/790) * Add Monitoring Google Cloud Samples [(#789)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/789) * Add Monitoring Google Cloud Samples * jon wayne review * fixups * Fix tests * jonwayne * Auto-update dependencies. [(#794)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/794) * Monitoring Region Tags [(#796)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/796) * Add get metric descriptor [(#797)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/797) * Fix mon reginos [(#798)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/798) * Fix monitoring tests [(#799)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/799) * Fix monitoring tests * Fixing monitoring tests Change-Id: I9e5d2a1143381430cc790085f90e210f9495d630 * Remove usage of GoogleCredentials [(#810)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/810) * Update monitoring region tags [(#830)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/830) * Remove cloud config fixture [(#887)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/887) * Remove cloud config fixture * Fix client secrets * Fix bigtable instance * Remove resource [(#890)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/890) * Remove resource fixture * Remove remote resource * De-flake metric test * Fix lint issues * Fix reference to our testing tools * Auto-update dependencies. [(#914)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/914) * Auto-update dependencies. * xfail the error reporting test * Fix lint * Re-generate all readmes * Fix README rst links [(#962)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/962) * Fix README rst links * Update all READMEs * Auto-update dependencies. [(#1004)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1004) * Auto-update dependencies. * Fix natural language samples * Fix pubsub iam samples * Fix language samples * Fix bigquery samples * Auto-update dependencies. [(#1055)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1055) * 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 * Update monitoring samples to use more descriptive variable names [(#1058)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1058) Change-Id: I648cd686a10399b7f92373fdcd48708396fd7140 * Auto-update dependencies. [(#1093)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1093) * 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 * Auto-update dependencies. [(#1094)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1094) * Auto-update dependencies. * Relax assertions in the ocr_nl sample Change-Id: I6d37e5846a8d6dd52429cb30d501f448c52cbba1 * Drop unused logging apiary samples Change-Id: I545718283773cb729a5e0def8a76ebfa40829d51 * Update all generated readme auth instructions [(#1121)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1121) Change-Id: I03b5eaef8b17ac3dc3c0339fd2c7447bd3e11bd2 * Auto-update dependencies. [(#1133)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1133) * Auto-update dependencies. * Fix missing http library Change-Id: I99faa600f2f3f1f50f57694fc9835d7f35bda250 * Added Link to Python Setup Guide [(#1158)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1158) * 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 * Auto-update dependencies. [(#1186)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1186) * Auto-update dependencies. [(#1217)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1217) * Added "Open in Cloud Shell" buttons to README files [(#1254)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1254) * Auto-update dependencies. [(#1309)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1309) * Auto-update dependencies. [(#1320)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1320) * Auto-update dependencies. [(#1355)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1355) * Auto-update dependencies. [(#1359)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1359) * Auto-update dependencies. [(#1377)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1377) * Auto-update dependencies. * Update requirements.txt * Fix client instantiation [(#1396)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1396) * Auto-update dependencies. * Regenerate the README files and fix the Open in Cloud Shell link for some samples [(#1441)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1441) * Update READMEs to fix numbering and add git clone [(#1464)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1464) * Fix monitoring region tags. [(#1472)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1472) * Sample's for stackdriver's uptime check api. [(#1478)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1478) * Sample's for stackdriver's uptime check api. * Add doc tags. * Stackdriver monitoring alerts sample. [(#1475)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1475) * Stackdriver monitoring alerts sample. * Lint * py27 tests pass * Accomodate reviewer's comments. * Add spaces around code blocks, Inc => LLC, and add docstring. * Reformat doc comments to look like Google doc comments. * Add more doc tags to alerts sample. [(#1483)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1483) * Add more doc tags to alerts sample. * lint * Update monitoring samples to use version 0.29.0 of the client library. [(#1495)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1495) * Update monitoring samples to use version 0.29.0 of the client library. * Fix typo. * Add sample to update a cloud monitoring uptime check. [(#1508)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1508) * Add sample to update a cloud monitoring uptime check. * Replace double quotes with single quotes. * Auto-update dependencies. [(#1658)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1658) * Auto-update dependencies. * Rollback appengine/standard/bigquery/. * Rollback appengine/standard/iap/. * Rollback bigtable/metricscaler. * Rolledback appengine/flexible/datastore. * Rollback dataproc/ * Rollback jobs/api_client * Rollback vision/cloud-client. * Rollback functions/ocr/app. * Rollback iot/api-client/end_to_end_example. * Rollback storage/cloud-client. * Rollback kms/api-client. * Rollback dlp/ * Rollback bigquery/cloud-client. * Rollback iot/api-client/manager. * Rollback appengine/flexible/cloudsql_postgresql. * Time series tests use random unique name to avoid limits [(#1776)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1776) * Time series tests use random unique name to avoid limits * Lint wants another blank line here * Use current debian image family * Restore to old state. Work should be on different branch. * Update snippets.py * Added new region tag [(#1844)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1844) * Auto-update dependencies. [(#1846)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1846) ACK, merging. * New snippet to delete notification channel [(#1920)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1920) New snippet to delete notification channel * Auto-update dependencies. [(#1980)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1980) * Auto-update dependencies. * Update requirements.txt * Update requirements.txt * monitoring/metrics: update from 5 to 20 minutes [(#2210)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2210) * Make backup/restore file name a parameter [(#2248)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2248) * Make backup/restore file a parameter Previously was hard coded as 'backup.json' * Added parameter to test function calls * Adds split updates for Firebase ... opencensus [(#2438)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2438) * Auto-update dependencies. [(#2005)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2005) * Auto-update dependencies. * Revert update of appengine/flexible/datastore. * revert update of appengine/flexible/scipy * revert update of bigquery/bqml * revert update of bigquery/cloud-client * revert update of bigquery/datalab-migration * revert update of bigtable/quickstart * revert update of compute/api * revert update of container_registry/container_analysis * revert update of dataflow/run_template * revert update of datastore/cloud-ndb * revert update of dialogflow/cloud-client * revert update of dlp * revert update of functions/imagemagick * revert update of functions/ocr/app * revert update of healthcare/api-client/fhir * revert update of iam/api-client * revert update of iot/api-client/gcs_file_to_device * revert update of iot/api-client/mqtt_example * revert update of language/automl * revert update of run/image-processing * revert update of vision/automl * revert update testing/requirements.txt * revert update of vision/cloud-client/detect * revert update of vision/cloud-client/product_search * revert update of jobs/v2/api_client * revert update of jobs/v3/api_client * revert update of opencensus * revert update of translate/cloud-client * revert update to speech/cloud-client Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com> Co-authored-by: Doug Mahugh * fix: monitoring tests [(#2995)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2995) * fix: monitoring tests * Add eventually consistent to flaky test * chore(deps): update dependency google-auth to v1.11.2 [(#2724)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2724) Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com> * Simplify noxfile setup. [(#2806)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2806) * chore(deps): update dependency requests to v2.23.0 * Simplify noxfile and add version control. * Configure appengine/standard to only test Python 2.7. * Update Kokokro configs to match noxfile. * Add requirements-test to each folder. * Remove Py2 versions from everything execept appengine/standard. * Remove conftest.py. * Remove appengine/standard/conftest.py * Remove 'no-sucess-flaky-report' from pytest.ini. * Add GAE SDK back to appengine/standard tests. * Fix typo. * Roll pytest to python 2 version. * Add a bunch of testing requirements. * Remove typo. * Add appengine lib directory back in. * Add some additional requirements. * Fix issue with flake8 args. * Even more requirements. * Readd appengine conftest.py. * Add a few more requirements. * Even more Appengine requirements. * Add webtest for appengine/standard/mailgun. * Add some additional requirements. * Add workaround for issue with mailjet-rest. * Add responses for appengine/standard/mailjet. Co-authored-by: Renovate Bot * [monitoring] fix: use retrying module in the fixture class [(#3285)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3285) * fix: use retrying module in the fixture class fixes #2971 fixes #2972 fixes #2973 fixes #3085 It will likely fix those issues, not guaranteed, but it's worth a try. * [monitoring] testing: mitigate 409 conflicts [(#3311)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3311) * [monitoring] testing: mitigate 409 conflicts fixes #2971 * retry on ServiceUnavailable too * reduce the number of api calls * mark tests as flaky instead of having retries * fix the rerun_filter implementation * add randomness to the sleep calls * lonter wait, better teardown * allow both messages * switch to regular flaky in monitoring [(#3333)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3333) * switch to regular flaky * minor assertion adjustment * address nit * Update dependency tabulate to v0.8.7 [(#3202)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3202) Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com> The error is a known error that does not have to do with this dependency change * Update dependency google-auth to v1.14.0 [(#3148)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3148) Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com> * chore(deps): update dependency google-api-python-client to v1.8.0 [(#3100)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3100) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [google-api-python-client](https://togithub.com/google/google-api-python-client) | minor | `==1.7.11` -> `==1.8.0` | --- ### Release Notes
google/google-api-python-client ### [`v1.8.0`](https://togithub.com/google/google-api-python-client/releases/v1.8.0) [Compare Source](https://togithub.com/google/google-api-python-client/compare/v1.7.12...v1.8.0) Release to support API endpoint override. New Features - Add api endpoint override. ([#​829](https://togithub.com/googleapis/google-api-python-client/pull/829)) Implementation Changes - Don't set http.redirect_codes if the attr doesn't exist and allow more httplib2 versions. ([#​841](https://togithub.com/googleapis/google-api-python-client/pull/841)) ### [`v1.7.12`](https://togithub.com/google/google-api-python-client/releases/v1.7.12) [Compare Source](https://togithub.com/google/google-api-python-client/compare/v1.7.11...v1.7.12) Bugfix release Implementation Changes - Look for field 'detail' in error message. ([#​739](https://togithub.com/googleapis/google-api-python-client/pull/739)) - Exclude 308s from httplib2 redirect codes list ([#​813](https://togithub.com/googleapis/google-api-python-client/pull/813)) Documentation - Remove oauth2client from docs ([#​738](https://togithub.com/googleapis/google-api-python-client/pull/738)) - Fix typo. ([#​745](https://togithub.com/googleapis/google-api-python-client/pull/745)) - Remove compatibility badges. ([#​746](https://togithub.com/googleapis/google-api-python-client/pull/746)) - Fix TypeError: search_analytics_api_sample.py [#​732](https://togithub.com/google/google-api-python-client/issues/732) ([#​742](https://togithub.com/googleapis/google-api-python-client/pull/742)) - Correct response access ([#​750](https://togithub.com/googleapis/google-api-python-client/pull/750)) - Fix link to API explorer ([#​760](https://togithub.com/googleapis/google-api-python-client/pull/760)) - Fix argument typo in oauth2 code example ([#​763](https://togithub.com/googleapis/google-api-python-client/pull/763)) - Recommend install with virtualenv ([#​768](https://togithub.com/googleapis/google-api-python-client/pull/768)) - Fix capitalization in docs/README.md ([#​770](https://togithub.com/googleapis/google-api-python-client/pull/770)) - Remove compatibility badges ([#​796](https://togithub.com/googleapis/google-api-python-client/pull/796)) - Remove mentions of pycrypto ([#​799](https://togithub.com/googleapis/google-api-python-client/pull/799)) - Fix typo in model.py - Add note about Google Ads llibrary ([#​814](https://togithub.com/googleapis/google-api-python-client/pull/814)) Internal / Testing Changes - Blacken ([#​772](https://togithub.com/googleapis/google-api-python-client/pull/722)) - Move kokoro configs ([#​832](https://togithub.com/googleapis/google-api-python-client/pull/832))
--- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Never, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#GoogleCloudPlatform/python-docs-samples). * chore(deps): update dependency google-cloud-monitoring to v0.35.0 [(#3459)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3459) Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com> * [monitoring] chore: remove gcp-devrel-py-tools [(#3480)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3480) * [monitoring] chore: remove gcp-devrel-py-tools * fixed the infinite loop * fix 404 error * Update dependency google-api-python-client to v1.8.2 [(#3452)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3452) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [google-api-python-client](https://togithub.com/google/google-api-python-client) | patch | `==1.8.0` -> `==1.8.2` | | [google-api-python-client](https://togithub.com/google/google-api-python-client) | minor | `==1.7.11` -> `==1.8.2` | --- ### Release Notes
google/google-api-python-client ### [`v1.8.2`](https://togithub.com/google/google-api-python-client/blob/master/CHANGELOG.md#​182-httpswwwgithubcomgoogleapisgoogle-api-python-clientcomparev181v182-2020-04-21) [Compare Source](https://togithub.com/google/google-api-python-client/compare/v1.8.1...v1.8.2) ### [`v1.8.1`](https://togithub.com/google/google-api-python-client/blob/master/CHANGELOG.md#​181-httpswwwgithubcomgoogleapisgoogle-api-python-clientcomparev180v181-2020-04-20) [Compare Source](https://togithub.com/google/google-api-python-client/compare/v1.8.0...v1.8.1)
--- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Never, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#GoogleCloudPlatform/python-docs-samples). * testing: replace @flaky with @pytest.mark.flaky [(#3496)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3496) * testing: replace @flaky with @pytest.mark.flaky * lint * mark few tests as flaky that involves LRO polling. * lint * chore(deps): update dependency google-auth to v1.14.1 [(#3464)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3464) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [google-auth](https://togithub.com/googleapis/google-auth-library-python) | patch | `==1.14.0` -> `==1.14.1` | | [google-auth](https://togithub.com/googleapis/google-auth-library-python) | minor | `==1.11.2` -> `==1.14.1` | --- ### Release Notes
googleapis/google-auth-library-python ### [`v1.14.1`](https://togithub.com/googleapis/google-auth-library-python/blob/master/CHANGELOG.md#​1141-httpswwwgithubcomgoogleapisgoogle-auth-library-pythoncomparev1140v1141-2020-04-21) [Compare Source](https://togithub.com/googleapis/google-auth-library-python/compare/v1.14.0...v1.14.1)
--- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Never, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#GoogleCloudPlatform/python-docs-samples). * [monitoring] fix: use backoff for writing the value [(#3697)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3697) * [monitoring] fix: use backoff for writing the value fixes #3694 * use uuid * chore(deps): update dependency google-auth to v1.14.2 [(#3724)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3724) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [google-auth](https://togithub.com/googleapis/google-auth-library-python) | patch | `==1.14.1` -> `==1.14.2` | --- ### Release Notes
googleapis/google-auth-library-python ### [`v1.14.2`](https://togithub.com/googleapis/google-auth-library-python/blob/master/CHANGELOG.md#​1142-httpswwwgithubcomgoogleapisgoogle-auth-library-pythoncomparev1141v1142-2020-05-07) [Compare Source](https://togithub.com/googleapis/google-auth-library-python/compare/v1.14.1...v1.14.2)
--- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Never, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#GoogleCloudPlatform/python-docs-samples). * chore: some lint fixes [(#3748)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3748) * chore(deps): update dependency google-auth to v1.14.3 [(#3728)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3728) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [google-auth](https://togithub.com/googleapis/google-auth-library-python) | patch | `==1.14.2` -> `==1.14.3` | --- ### Release Notes
googleapis/google-auth-library-python ### [`v1.14.3`](https://togithub.com/googleapis/google-auth-library-python/blob/master/CHANGELOG.md#​1143-httpswwwgithubcomgoogleapisgoogle-auth-library-pythoncomparev1142v1143-2020-05-11) [Compare Source](https://togithub.com/googleapis/google-auth-library-python/compare/v1.14.2...v1.14.3)
--- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Never, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [x] If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#GoogleCloudPlatform/python-docs-samples). * Add request_method to create example. [(#3745)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3745) Co-authored-by: Takashi Matsuo * testing: multi project noxfile-template.py [(#3700)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3700) * testing: prototpe for multi project noxfile.py * correct project names * introduce TEST_CONFIG * modify noxfile-template, add default config * changed how we import user config * fix stale comments * use different project for python 3.6 and 3.7 * fix a bug * changed the filename also simplified the config stop runnint `gcloud update` add a warning about editing noxfile.py * add BUILD_SPECIFIC_GCLOUD_PROJECT * use session.skip * print debuggin * more print debuggin * adding cwd to sys.path * removed debug print, display details of ImportError * use the usual test project * stop setting gcloud project * simplified the noxfile-template * [monitoring] testing: start using build specific projects [(#3771)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3771) Also added `required_api_url` and `required_role` field in `README.rst.in`. A part of #3310 Note: Now the service account has permission only on the project for py36 build, so py37 build should fail. * chore(deps): update dependency google-cloud-monitoring to v0.36.0 [(#3783)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3783) Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com> * update google-auth to 1.15.0 final part [(#3819)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3819) * update google-api-python-client to 1.8.3 final part [(#3827)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3827) * chore(deps): update dependency google-api-python-client to v1.8.4 [(#3881)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3881) Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Co-authored-by: gcf-merge-on-green[bot] <60162190+gcf-merge-on-green[bot]@users.noreply.github.com> * [monitoring] fix: use the same random value for retry [(#3900)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3900) * [monitoring] fix: use the same random value for retry fixes #3875 * Just reseed in `write_value()` * revert comment * chore(deps): update dependency google-auth to v1.16.0 [(#3903)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3903) * chore(deps): update dependency google-api-python-client to v1.9.1 [(#3930)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3930) * chore(deps): update dependency google-cloud-monitoring to v1 [(#3950)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3950) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [google-cloud-monitoring](https://togithub.com/googleapis/python-monitoring) | major | `==0.36.0` -> `==1.0.0` | --- ### Release Notes
googleapis/python-monitoring ### [`v1.0.0`](https://togithub.com/googleapis/python-monitoring/blob/master/CHANGELOG.md#​100-httpswwwgithubcomgoogleapispython-monitoringcomparev0360v100-2020-06-03) [Compare Source](https://togithub.com/googleapis/python-monitoring/compare/v0.36.0...v1.0.0) ##### Features - set release_status to Production/Stable ([#​8](https://www.github.com/googleapis/python-monitoring/issues/8)) ([a99d67a](https://www.github.com/googleapis/python-monitoring/commit/a99d67a4f1399b9a74f189c6332cd85e56149fac))
--- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Never, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#GoogleCloudPlatform/python-docs-samples). * final update for google-auth [(#3967)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3967) * testing: start using btlr [(#3959)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3959) * testing: start using btlr The binary is at gs://cloud-devrel-kokoro-resources/btlr/v0.0.1/btlr * add period after DIFF_FROM * use array for btlr args * fix websocket tests * add debug message * wait longer for the server to spin up * dlp: bump the wait timeout to 10 minutes * [run] copy noxfile.py to child directory to avoid gcloud issue * [iam] fix: only display description when the key exists * use uuid4 instead of uuid1 * [iot] testing: use the same format for registry id * Stop asserting Out of memory not in the output * fix missing imports * [dns] testing: more retries with delay * [dlp] testing: longer timeout * use the max-concurrency flag * use 30 workers * [monitoring] use multiple projects * [dlp] testing: longer timeout * Replace GCLOUD_PROJECT with GOOGLE_CLOUD_PROJECT. [(#4022)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4022) * Update dependency google-api-python-client to v1.9.2 [(#4038)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4038) * Update dependency google-auth to v1.17.0 [(#4058)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4058) * chore(deps): update dependency google-auth to v1.17.1 [(#4073)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4073) * Update dependency google-auth to v1.17.2 [(#4083)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4083) * Update dependency google-api-python-client to v1.9.3 [(#4057)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4057) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [google-api-python-client](https://togithub.com/googleapis/google-api-python-client) | patch | `==1.9.2` -> `==1.9.3` | --- ### Release Notes
googleapis/google-api-python-client ### [`v1.9.3`](https://togithub.com/googleapis/google-api-python-client/blob/master/CHANGELOG.md#​193-httpswwwgithubcomgoogleapisgoogle-api-python-clientcomparev192v193-2020-06-10) [Compare Source](https://togithub.com/googleapis/google-api-python-client/compare/v1.9.2...v1.9.3)
--- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Never, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#GoogleCloudPlatform/python-docs-samples). * Update dependency google-auth to v1.18.0 [(#4125)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4125) * [monitoring] fix: mitigate flake [(#4153)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4153) fixes #4150 * fix(monitoring): also retry upon DeadlineExceeded [(#4202)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4202) fixes #4180 Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> * Create example for POST check. [(#4082)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4082) * Add create example for POST check. * Small fixes for POST check stuff. * Have create example be one tag block * Syntax fixes * Small fixes. * Ran black linter. Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com> * Update dependency google-auth-httplib2 to v0.0.4 [(#4255)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4255) Co-authored-by: Takashi Matsuo * chore(deps): pin dependencies [(#4280)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4280) * chore(deps): pin dependencies * specify python version for appengine standard Co-authored-by: Leah Cole * chore(deps): update dependency pytest to v5.4.3 [(#4279)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4279) * chore(deps): update dependency pytest to v5.4.3 * specify pytest for python 2 in appengine Co-authored-by: Leah Cole * chore(deps): update dependency mock to v4 [(#4287)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4287) * chore(deps): update dependency mock to v4 * specify mock version for appengine python 2 Co-authored-by: Leah Cole * chore(deps): update dependency google-auth to v1.19.0 [(#4293)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4293) * Update dependency flaky to v3.7.0 [(#4300)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4300) * Update dependency google-api-python-client to v1.10.0 [(#4302)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4302) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [google-api-python-client](https://togithub.com/googleapis/google-api-python-client) | minor | `==1.9.3` -> `==1.10.0` | --- ### Release Notes
googleapis/google-api-python-client ### [`v1.10.0`](https://togithub.com/googleapis/google-api-python-client/blob/master/CHANGELOG.md#​1100-httpswwwgithubcomgoogleapisgoogle-api-python-clientcomparev193v1100-2020-07-15) [Compare Source](https://togithub.com/googleapis/google-api-python-client/compare/v1.9.3...v1.10.0) ##### Features - allow to use 'six.moves.collections_abc.Mapping' in 'client_options.from_dict()' ([#​943](https://www.github.com/googleapis/google-api-python-client/issues/943)) ([21af37b](https://www.github.com/googleapis/google-api-python-client/commit/21af37b11ea2d6a89b3df484e1b2fa1d12849510)) - Build universal wheels ([#​948](https://www.github.com/googleapis/google-api-python-client/issues/948)) ([3e28a1e](https://www.github.com/googleapis/google-api-python-client/commit/3e28a1e0d47f829182cd92f37475ab91fa5e4afc)) - discovery supports retries ([#​967](https://www.github.com/googleapis/google-api-python-client/issues/967)) ([f3348f9](https://www.github.com/googleapis/google-api-python-client/commit/f3348f98bf91a88a28bf61b12b95e391cc3be1ff)), closes [#​848](https://www.github.com/googleapis/google-api-python-client/issues/848) ##### Documentation - consolidating and updating the Contribution Guide ([#​964](https://www.github.com/googleapis/google-api-python-client/issues/964)) ([63f97f3](https://www.github.com/googleapis/google-api-python-client/commit/63f97f37daee37a725eb05df3097b20d5d4eaaf0)), closes [#​963](https://www.github.com/googleapis/google-api-python-client/issues/963) ##### [1.9.3](https://www.github.com/googleapis/google-api-python-client/compare/v1.9.2...v1.9.3) (2020-06-10) ##### Bug Fixes - update GOOGLE_API_USE_MTLS values ([#​940](https://www.github.com/googleapis/google-api-python-client/issues/940)) ([19908ed](https://www.github.com/googleapis/google-api-python-client/commit/19908edcd8a3df1db41e34100acc1f15c3c99397)) ##### [1.9.2](https://www.github.com/googleapis/google-api-python-client/compare/v1.9.1...v1.9.2) (2020-06-04) ##### Bug Fixes - bump api-core version ([#​936](https://www.github.com/googleapis/google-api-python-client/issues/936)) ([ee53b3b](https://www.github.com/googleapis/google-api-python-client/commit/ee53b3b32a050874ba4cfb491fb384f94682c824)) ##### [1.9.1](https://www.github.com/googleapis/google-api-python-client/compare/v1.9.0...v1.9.1) (2020-06-02) ##### Bug Fixes - fix python-api-core dependency issue ([#​931](https://www.github.com/googleapis/google-api-python-client/issues/931)) ([42028ed](https://www.github.com/googleapis/google-api-python-client/commit/42028ed2b2be47f85b70eb813185264f1f573d01))
--- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Never, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#GoogleCloudPlatform/python-docs-samples). * chore(deps): update dependency google-auth to v1.19.1 [(#4304)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4304) * chore(deps): update dependency google-auth to v1.19.2 [(#4321)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4321) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [google-auth](https://togithub.com/googleapis/google-auth-library-python) | patch | `==1.19.1` -> `==1.19.2` | --- ### Release Notes
googleapis/google-auth-library-python ### [`v1.19.2`](https://togithub.com/googleapis/google-auth-library-python/blob/master/CHANGELOG.md#​1192-httpswwwgithubcomgoogleapisgoogle-auth-library-pythoncomparev1191v1192-2020-07-17) [Compare Source](https://togithub.com/googleapis/google-auth-library-python/compare/v1.19.1...v1.19.2)
--- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Never, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#GoogleCloudPlatform/python-docs-samples). * Update dependency google-auth to v1.20.0 [(#4387)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4387) * Update dependency pytest to v6 [(#4390)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4390) * chore(deps): update dependency google-auth to v1.20.1 [(#4452)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4452) * chore(deps): update dependency google-api-python-client to v1.10.1 [(#4557)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4557) * chore(deps): update dependency google-api-python-client to v1.10.1 * Update requirements.txt Co-authored-by: Takashi Matsuo * chore(deps): update dependency google-cloud-monitoring to v1.1.0 [(#4561)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4561) * Update dependency google-auth to v1.21.0 [(#4588)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4588) * Update dependency google-api-python-client to v1.11.0 [(#4587)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4587) Co-authored-by: Takashi Matsuo * chore(deps): update dependency google-auth to v1.21.1 [(#4634)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4634) * chore(deps): update dependency google-auth to v1.21.2 [(#4684)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4684) * fix(monitoring): retry in the test setup [(#4702)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4702) fixes #4687 fixes #4688 fixes #4689 fixes #4690 * chore(deps): update dependency google-api-python-client to v1.12.1 [(#4674)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4674) * chore(deps): update dependency google-auth to v1.21.3 [(#4754)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4754) * chore(deps): update dependency google-api-python-client to v1.12.2 [(#4751)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4751) * chore: update template * chore: add BUILD_SPECIFIC_GCLOUD_PROJECT env var Co-authored-by: Bill Prin Co-authored-by: Bill Prin Co-authored-by: Jon Wayne Parrott Co-authored-by: Greg Taylor Co-authored-by: Jon Wayne Parrott Co-authored-by: DPE bot Co-authored-by: Takashi Matsuo Co-authored-by: michaelawyu Co-authored-by: Campion Fellin Co-authored-by: Frank Natividad Co-authored-by: Jason Dobry Co-authored-by: Jeffrey Rennie Co-authored-by: michaelawyu Co-authored-by: Charles Engelke Co-authored-by: Adam Ross Co-authored-by: Charles Engelke Co-authored-by: Gus Class Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com> Co-authored-by: Doug Mahugh Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com> Co-authored-by: Renovate Bot Co-authored-by: Shi Zhang Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Co-authored-by: gcf-merge-on-green[bot] <60162190+gcf-merge-on-green[bot]@users.noreply.github.com> Co-authored-by: Leah Cole --- monitoring/AUTHORING_GUIDE.md | 1 + monitoring/CONTRIBUTING.md | 1 + .../snippets/v3/alerts-client/.gitignore | 1 + .../snippets/v3/alerts-client/README.rst | 138 +++++++ .../snippets/v3/alerts-client/README.rst.in | 33 ++ .../snippets/v3/alerts-client/noxfile.py | 224 ++++++++++++ .../v3/alerts-client/noxfile_config.py | 42 +++ .../v3/alerts-client/requirements-test.txt | 3 + .../v3/alerts-client/requirements.txt | 2 + .../snippets/v3/alerts-client/snippets.py | 343 ++++++++++++++++++ .../v3/alerts-client/snippets_test.py | 195 ++++++++++ .../v3/alerts-client/test_alert_policy.json | 31 ++ .../test_notification_channel.json | 15 + .../snippets/v3/cloud-client/README.rst | 147 ++++++++ .../snippets/v3/cloud-client/README.rst.in | 35 ++ .../snippets/v3/cloud-client/noxfile.py | 224 ++++++++++++ .../v3/cloud-client/noxfile_config.py | 42 +++ .../snippets/v3/cloud-client/quickstart.py | 43 +++ .../v3/cloud-client/quickstart_test.py | 46 +++ .../v3/cloud-client/requirements-test.txt | 3 + .../snippets/v3/cloud-client/requirements.txt | 1 + .../snippets/v3/cloud-client/snippets.py | 310 ++++++++++++++++ .../snippets/v3/cloud-client/snippets_test.py | 117 ++++++ .../v3/uptime-check-client/README.rst | 115 ++++++ .../v3/uptime-check-client/README.rst.in | 26 ++ .../v3/uptime-check-client/noxfile.py | 224 ++++++++++++ .../uptime-check-client/requirements-test.txt | 2 + .../v3/uptime-check-client/requirements.txt | 2 + .../v3/uptime-check-client/snippets.py | 257 +++++++++++++ .../v3/uptime-check-client/snippets_test.py | 105 ++++++ 30 files changed, 2728 insertions(+) create mode 100644 monitoring/AUTHORING_GUIDE.md create mode 100644 monitoring/CONTRIBUTING.md create mode 100644 monitoring/snippets/v3/alerts-client/.gitignore create mode 100644 monitoring/snippets/v3/alerts-client/README.rst create mode 100644 monitoring/snippets/v3/alerts-client/README.rst.in create mode 100644 monitoring/snippets/v3/alerts-client/noxfile.py create mode 100644 monitoring/snippets/v3/alerts-client/noxfile_config.py create mode 100644 monitoring/snippets/v3/alerts-client/requirements-test.txt create mode 100644 monitoring/snippets/v3/alerts-client/requirements.txt create mode 100644 monitoring/snippets/v3/alerts-client/snippets.py create mode 100644 monitoring/snippets/v3/alerts-client/snippets_test.py create mode 100644 monitoring/snippets/v3/alerts-client/test_alert_policy.json create mode 100644 monitoring/snippets/v3/alerts-client/test_notification_channel.json create mode 100644 monitoring/snippets/v3/cloud-client/README.rst create mode 100644 monitoring/snippets/v3/cloud-client/README.rst.in create mode 100644 monitoring/snippets/v3/cloud-client/noxfile.py create mode 100644 monitoring/snippets/v3/cloud-client/noxfile_config.py create mode 100644 monitoring/snippets/v3/cloud-client/quickstart.py create mode 100644 monitoring/snippets/v3/cloud-client/quickstart_test.py create mode 100644 monitoring/snippets/v3/cloud-client/requirements-test.txt create mode 100644 monitoring/snippets/v3/cloud-client/requirements.txt create mode 100644 monitoring/snippets/v3/cloud-client/snippets.py create mode 100644 monitoring/snippets/v3/cloud-client/snippets_test.py create mode 100644 monitoring/snippets/v3/uptime-check-client/README.rst create mode 100644 monitoring/snippets/v3/uptime-check-client/README.rst.in create mode 100644 monitoring/snippets/v3/uptime-check-client/noxfile.py create mode 100644 monitoring/snippets/v3/uptime-check-client/requirements-test.txt create mode 100644 monitoring/snippets/v3/uptime-check-client/requirements.txt create mode 100644 monitoring/snippets/v3/uptime-check-client/snippets.py create mode 100644 monitoring/snippets/v3/uptime-check-client/snippets_test.py diff --git a/monitoring/AUTHORING_GUIDE.md b/monitoring/AUTHORING_GUIDE.md new file mode 100644 index 00000000000..55c97b32f4c --- /dev/null +++ b/monitoring/AUTHORING_GUIDE.md @@ -0,0 +1 @@ +See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md \ No newline at end of file diff --git a/monitoring/CONTRIBUTING.md b/monitoring/CONTRIBUTING.md new file mode 100644 index 00000000000..34c882b6f1a --- /dev/null +++ b/monitoring/CONTRIBUTING.md @@ -0,0 +1 @@ +See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/CONTRIBUTING.md \ No newline at end of file diff --git a/monitoring/snippets/v3/alerts-client/.gitignore b/monitoring/snippets/v3/alerts-client/.gitignore new file mode 100644 index 00000000000..de0a466d79c --- /dev/null +++ b/monitoring/snippets/v3/alerts-client/.gitignore @@ -0,0 +1 @@ +backup.json diff --git a/monitoring/snippets/v3/alerts-client/README.rst b/monitoring/snippets/v3/alerts-client/README.rst new file mode 100644 index 00000000000..bb59aad5fee --- /dev/null +++ b/monitoring/snippets/v3/alerts-client/README.rst @@ -0,0 +1,138 @@ +.. This file is automatically generated. Do not edit this file directly. + +Google Stackdriver Alerting API Python Samples +=============================================================================== + +.. image:: https://gstatic.com/cloudssh/images/open-btn.png + :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=monitoring/api/v3/alerts-client/README.rst + + +This directory contains samples for Google Stackdriver Alerting API. Stackdriver Monitoring collects metrics, events, and metadata from Google Cloud Platform, Amazon Web Services (AWS), hosted uptime probes, application instrumentation, and a variety of common application components including Cassandra, Nginx, Apache Web Server, Elasticsearch and many others. Stackdriver's Alerting API allows you to create, delete, and make back up copies of your alert policies. + + + + +.. _Google Stackdriver Alerting API: https://cloud.google.com/monitoring/alerts/ + +To run the sample, you need to enable the API at: https://console.cloud.google.com/apis/library/monitoring.googleapis.com + +To run the sample, you need to have `Monitoring Admin` role. + +Please visit [the Cloud Console UI of this API](https://console.cloud.google.com/monitoring) and [create a new Workspace with the same name of your Cloud project](https://cloud.google.com/monitoring/workspaces/create). + + +Setup +------------------------------------------------------------------------------- + + +Authentication +++++++++++++++ + +This sample requires you to have authentication setup. Refer to the +`Authentication Getting Started Guide`_ for instructions on setting up +credentials for applications. + +.. _Authentication Getting Started Guide: + https://cloud.google.com/docs/authentication/getting-started + +Install Dependencies +++++++++++++++++++++ + +#. Clone python-docs-samples and change directory to the sample directory you want to use. + + .. code-block:: bash + + $ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git + +#. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions. + + .. _Python Development Environment Setup Guide: + https://cloud.google.com/python/setup + +#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. + + .. code-block:: bash + + $ virtualenv env + $ source env/bin/activate + +#. Install the dependencies needed to run the samples. + + .. code-block:: bash + + $ pip install -r requirements.txt + +.. _pip: https://pip.pypa.io/ +.. _virtualenv: https://virtualenv.pypa.io/ + +Samples +------------------------------------------------------------------------------- + +Snippets ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +.. image:: https://gstatic.com/cloudssh/images/open-btn.png + :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=monitoring/api/v3/alerts-client/snippets.py,monitoring/api/v3/alerts-client/README.rst + + + + +To run this sample: + +.. code-block:: bash + + $ python snippets.py + + usage: snippets.py [-h] + {list-alert-policies,list-notification-channels,enable-alert-policies,disable-alert-policies,replace-notification-channels,backup,restore} + ... + + Demonstrates AlertPolicy API operations. + + positional arguments: + {list-alert-policies,list-notification-channels,enable-alert-policies,disable-alert-policies,replace-notification-channels,backup,restore} + list-alert-policies + list-notification-channels + enable-alert-policies + Enable or disable alert policies in a project. + Arguments: project_name (str) enable (bool): Enable or + disable the policies. filter_ (str, optional): Only + enable/disable alert policies that match this filter_. + See + https://cloud.google.com/monitoring/api/v3/sorting- + and-filtering + disable-alert-policies + Enable or disable alert policies in a project. + Arguments: project_name (str) enable (bool): Enable or + disable the policies. filter_ (str, optional): Only + enable/disable alert policies that match this filter_. + See + https://cloud.google.com/monitoring/api/v3/sorting- + and-filtering + replace-notification-channels + backup + restore + + optional arguments: + -h, --help show this help message and exit + + + + + +The client library +------------------------------------------------------------------------------- + +This sample uses the `Google Cloud Client Library for Python`_. +You can read the documentation for more details on API usage and use GitHub +to `browse the source`_ and `report issues`_. + +.. _Google Cloud Client Library for Python: + https://googlecloudplatform.github.io/google-cloud-python/ +.. _browse the source: + https://github.com/GoogleCloudPlatform/google-cloud-python +.. _report issues: + https://github.com/GoogleCloudPlatform/google-cloud-python/issues + + +.. _Google Cloud SDK: https://cloud.google.com/sdk/ diff --git a/monitoring/snippets/v3/alerts-client/README.rst.in b/monitoring/snippets/v3/alerts-client/README.rst.in new file mode 100644 index 00000000000..00b280124ea --- /dev/null +++ b/monitoring/snippets/v3/alerts-client/README.rst.in @@ -0,0 +1,33 @@ +# This file is used to generate README.rst + +product: + name: Google Stackdriver Alerting API + short_name: Stackdriver Alerting API + url: https://cloud.google.com/monitoring/alerts/ + description: > + Stackdriver Monitoring collects metrics, events, and metadata from Google + Cloud Platform, Amazon Web Services (AWS), hosted uptime probes, + application instrumentation, and a variety of common application + components including Cassandra, Nginx, Apache Web Server, Elasticsearch + and many others. Stackdriver's Alerting API allows you to create, + delete, and make back up copies of your alert policies. + +required_api_url: https://console.cloud.google.com/apis/library/monitoring.googleapis.com +required_role: Monitoring Admin +other_required_steps: > + Please visit [the Cloud Console UI of this + API](https://console.cloud.google.com/monitoring) and create a new + Workspace with the same name of your Cloud project. + +setup: +- auth +- install_deps + +samples: +- name: Snippets + file: snippets.py + show_help: true + +cloud_client_library: true + +folder: monitoring/api/v3/alerts-client diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py new file mode 100644 index 00000000000..ba55d7ce53c --- /dev/null +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -0,0 +1,224 @@ +# Copyright 2019 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. + +from __future__ import print_function + +import os +from pathlib import Path +import sys + +import nox + + +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING +# DO NOT EDIT THIS FILE EVER! +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING + +# Copy `noxfile_config.py` to your directory and modify it instead. + + +# `TEST_CONFIG` dict is a configuration hook that allows users to +# modify the test configurations. The values here should be in sync +# with `noxfile_config.py`. Users will copy `noxfile_config.py` into +# their directory and modify it. + +TEST_CONFIG = { + # You can opt out from the test for specific Python versions. + 'ignored_versions': ["2.7"], + + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + 'envs': {}, +} + + +try: + # Ensure we can import noxfile_config in the project's directory. + sys.path.append('.') + from noxfile_config import TEST_CONFIG_OVERRIDE +except ImportError as e: + print("No user noxfile_config found: detail: {}".format(e)) + TEST_CONFIG_OVERRIDE = {} + +# Update the TEST_CONFIG with the user supplied values. +TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) + + +def get_pytest_env_vars(): + """Returns a dict for pytest invocation.""" + ret = {} + + # Override the GCLOUD_PROJECT and the alias. + env_key = TEST_CONFIG['gcloud_project_env'] + # This should error out if not set. + ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] + + # Apply user supplied envs. + ret.update(TEST_CONFIG['envs']) + return ret + + +# DO NOT EDIT - automatically generated. +# All versions used to tested samples. +ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] + +# Any default versions that should be ignored. +IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] + +TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) + +INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False)) +# +# Style Checks +# + + +def _determine_local_import_names(start_dir): + """Determines all import names that should be considered "local". + + This is used when running the linter to insure that import order is + properly checked. + """ + file_ext_pairs = [os.path.splitext(path) for path in os.listdir(start_dir)] + return [ + basename + for basename, extension in file_ext_pairs + if extension == ".py" + or os.path.isdir(os.path.join(start_dir, basename)) + and basename not in ("__pycache__") + ] + + +# Linting with flake8. +# +# We ignore the following rules: +# E203: whitespace before ‘:’ +# E266: too many leading ‘#’ for block comment +# E501: line too long +# I202: Additional newline in a section of imports +# +# We also need to specify the rules which are ignored by default: +# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121'] +FLAKE8_COMMON_ARGS = [ + "--show-source", + "--builtin=gettext", + "--max-complexity=20", + "--import-order-style=google", + "--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py", + "--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202", + "--max-line-length=88", +] + + +@nox.session +def lint(session): + session.install("flake8", "flake8-import-order") + + local_names = _determine_local_import_names(".") + args = FLAKE8_COMMON_ARGS + [ + "--application-import-names", + ",".join(local_names), + "." + ] + session.run("flake8", *args) + + +# +# Sample Tests +# + + +PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] + + +def _session_tests(session, post_install=None): + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars() + ) + + +@nox.session(python=ALL_VERSIONS) +def py(session): + """Runs py.test for a sample using the specified version of Python.""" + if session.python in TESTED_VERSIONS: + _session_tests(session) + else: + session.skip("SKIPPED: {} tests are disabled for this sample.".format( + session.python + )) + + +# +# Readmegen +# + + +def _get_repo_root(): + """ Returns the root folder of the project. """ + # Get root of this repository. Assume we don't have directories nested deeper than 10 items. + p = Path(os.getcwd()) + for i in range(10): + if p is None: + break + if Path(p / ".git").exists(): + return str(p) + p = p.parent + raise Exception("Unable to detect repository root.") + + +GENERATED_READMES = sorted([x for x in Path(".").rglob("*.rst.in")]) + + +@nox.session +@nox.parametrize("path", GENERATED_READMES) +def readmegen(session, path): + """(Re-)generates the readme for a sample.""" + session.install("jinja2", "pyyaml") + dir_ = os.path.dirname(path) + + if os.path.exists(os.path.join(dir_, "requirements.txt")): + session.install("-r", os.path.join(dir_, "requirements.txt")) + + in_file = os.path.join(dir_, "README.rst.in") + session.run( + "python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file + ) diff --git a/monitoring/snippets/v3/alerts-client/noxfile_config.py b/monitoring/snippets/v3/alerts-client/noxfile_config.py new file mode 100644 index 00000000000..664c58309d7 --- /dev/null +++ b/monitoring/snippets/v3/alerts-client/noxfile_config.py @@ -0,0 +1,42 @@ +# Copyright 2020 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. + +# Default TEST_CONFIG_OVERRIDE for python repos. + +# You can copy this file into your directory, then it will be inported from +# the noxfile.py. + +# The source of truth: +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py + +TEST_CONFIG_OVERRIDE = { + # You can opt out from the test for specific Python versions. + 'ignored_versions': ["2.7"], + + # Declare optional test sessions you want to opt-in. Currently we + # have the following optional test sessions: + # 'cloud_run' # Test session for Cloud Run application. + 'opt_in_sessions': [], + + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + # 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + 'envs': {}, +} diff --git a/monitoring/snippets/v3/alerts-client/requirements-test.txt b/monitoring/snippets/v3/alerts-client/requirements-test.txt new file mode 100644 index 00000000000..ec623710c6e --- /dev/null +++ b/monitoring/snippets/v3/alerts-client/requirements-test.txt @@ -0,0 +1,3 @@ +pytest==6.0.1 +retrying==1.3.3 +flaky==3.7.0 diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt new file mode 100644 index 00000000000..bc7a2fe57c8 --- /dev/null +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -0,0 +1,2 @@ +google-cloud-monitoring==1.1.0 +tabulate==0.8.7 diff --git a/monitoring/snippets/v3/alerts-client/snippets.py b/monitoring/snippets/v3/alerts-client/snippets.py new file mode 100644 index 00000000000..80254232e6a --- /dev/null +++ b/monitoring/snippets/v3/alerts-client/snippets.py @@ -0,0 +1,343 @@ +# Copyright 2018 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. + +from __future__ import print_function + +import argparse +import json +import os + +from google.cloud import monitoring_v3 +import google.protobuf.json_format +import tabulate + + +# [START monitoring_alert_list_policies] +def list_alert_policies(project_name): + client = monitoring_v3.AlertPolicyServiceClient() + policies = client.list_alert_policies(project_name) + print(tabulate.tabulate( + [(policy.name, policy.display_name) for policy in policies], + ('name', 'display_name'))) +# [END monitoring_alert_list_policies] + + +# [START monitoring_alert_list_channels] +def list_notification_channels(project_name): + client = monitoring_v3.NotificationChannelServiceClient() + channels = client.list_notification_channels(project_name) + print(tabulate.tabulate( + [(channel.name, channel.display_name) for channel in channels], + ('name', 'display_name'))) +# [END monitoring_alert_list_channels] + + +# [START monitoring_alert_enable_policies] +def enable_alert_policies(project_name, enable, filter_=None): + """Enable or disable alert policies in a project. + + Arguments: + project_name (str) + enable (bool): Enable or disable the policies. + filter_ (str, optional): Only enable/disable alert policies that match + this filter_. See + https://cloud.google.com/monitoring/api/v3/sorting-and-filtering + """ + + client = monitoring_v3.AlertPolicyServiceClient() + policies = client.list_alert_policies(project_name, filter_=filter_) + + for policy in policies: + if bool(enable) == policy.enabled.value: + print('Policy', policy.name, 'is already', + 'enabled' if policy.enabled.value else 'disabled') + else: + policy.enabled.value = bool(enable) + mask = monitoring_v3.types.field_mask_pb2.FieldMask() + mask.paths.append('enabled') + client.update_alert_policy(policy, mask) + print('Enabled' if enable else 'Disabled', policy.name) +# [END monitoring_alert_enable_policies] + + +# [START monitoring_alert_replace_channels] +def replace_notification_channels(project_name, alert_policy_id, channel_ids): + _, project_id = project_name.split('/') + alert_client = monitoring_v3.AlertPolicyServiceClient() + channel_client = monitoring_v3.NotificationChannelServiceClient() + policy = monitoring_v3.types.alert_pb2.AlertPolicy() + policy.name = alert_client.alert_policy_path(project_id, alert_policy_id) + + for channel_id in channel_ids: + policy.notification_channels.append( + channel_client.notification_channel_path(project_id, channel_id)) + + mask = monitoring_v3.types.field_mask_pb2.FieldMask() + mask.paths.append('notification_channels') + updated_policy = alert_client.update_alert_policy(policy, mask) + print('Updated', updated_policy.name) +# [END monitoring_alert_replace_channels] + + +# [START monitoring_alert_delete_channel] +def delete_notification_channels(project_name, channel_ids, force=None): + channel_client = monitoring_v3.NotificationChannelServiceClient() + for channel_id in channel_ids: + channel_name = '{}/notificationChannels/{}'.format( + project_name, channel_id) + try: + channel_client.delete_notification_channel( + channel_name, force=force) + print('Channel {} deleted'.format(channel_name)) + except ValueError: + print('The parameters are invalid') + except Exception as e: + print('API call failed: {}'.format(e)) +# [END monitoring_alert_delete_channel] + + +# [START monitoring_alert_backup_policies] +def backup(project_name, backup_filename): + alert_client = monitoring_v3.AlertPolicyServiceClient() + channel_client = monitoring_v3.NotificationChannelServiceClient() + record = {'project_name': project_name, + 'policies': list(alert_client.list_alert_policies(project_name)), + 'channels': list(channel_client.list_notification_channels( + project_name))} + json.dump(record, open(backup_filename, 'wt'), cls=ProtoEncoder, indent=2) + print('Backed up alert policies and notification channels to {}.'.format( + backup_filename) + ) + + +class ProtoEncoder(json.JSONEncoder): + """Uses google.protobuf.json_format to encode protobufs as json.""" + def default(self, obj): + if type(obj) in (monitoring_v3.types.alert_pb2.AlertPolicy, + monitoring_v3.types.notification_pb2. + NotificationChannel): + text = google.protobuf.json_format.MessageToJson(obj) + return json.loads(text) + return super(ProtoEncoder, self).default(obj) +# [END monitoring_alert_backup_policies] + + +# [START monitoring_alert_restore_policies] +# [START monitoring_alert_create_policy] +# [START monitoring_alert_create_channel] +# [START monitoring_alert_update_channel] +# [START monitoring_alert_enable_channel] +def restore(project_name, backup_filename): + print('Loading alert policies and notification channels from {}.'.format( + backup_filename) + ) + record = json.load(open(backup_filename, 'rt')) + is_same_project = project_name == record['project_name'] + # Convert dicts to AlertPolicies. + policies_json = [json.dumps(policy) for policy in record['policies']] + policies = [google.protobuf.json_format.Parse( + policy_json, monitoring_v3.types.alert_pb2.AlertPolicy()) + for policy_json in policies_json] + # Convert dicts to NotificationChannels + channels_json = [json.dumps(channel) for channel in record['channels']] + channels = [google.protobuf.json_format.Parse( + channel_json, monitoring_v3.types.notification_pb2. + NotificationChannel()) for channel_json in channels_json] + + # Restore the channels. + channel_client = monitoring_v3.NotificationChannelServiceClient() + channel_name_map = {} + + for channel in channels: + updated = False + print('Updating channel', channel.display_name) + # This field is immutable and it is illegal to specify a + # non-default value (UNVERIFIED or VERIFIED) in the + # Create() or Update() operations. + channel.verification_status = monitoring_v3.enums.NotificationChannel.\ + VerificationStatus.VERIFICATION_STATUS_UNSPECIFIED + + if is_same_project: + try: + channel_client.update_notification_channel(channel) + updated = True + except google.api_core.exceptions.NotFound: + pass # The channel was deleted. Create it below. + + if not updated: + # The channel no longer exists. Recreate it. + old_name = channel.name + channel.ClearField("name") + new_channel = channel_client.create_notification_channel( + project_name, channel) + channel_name_map[old_name] = new_channel.name + + # Restore the alerts + alert_client = monitoring_v3.AlertPolicyServiceClient() + + for policy in policies: + print('Updating policy', policy.display_name) + # These two fields cannot be set directly, so clear them. + policy.ClearField('creation_record') + policy.ClearField('mutation_record') + + # Update old channel names with new channel names. + for i, channel in enumerate(policy.notification_channels): + new_channel = channel_name_map.get(channel) + if new_channel: + policy.notification_channels[i] = new_channel + + updated = False + + if is_same_project: + try: + alert_client.update_alert_policy(policy) + updated = True + except google.api_core.exceptions.NotFound: + pass # The policy was deleted. Create it below. + except google.api_core.exceptions.InvalidArgument: + # Annoying that API throws InvalidArgument when the policy + # does not exist. Seems like it should throw NotFound. + pass # The policy was deleted. Create it below. + + if not updated: + # The policy no longer exists. Recreate it. + old_name = policy.name + policy.ClearField("name") + for condition in policy.conditions: + condition.ClearField("name") + policy = alert_client.create_alert_policy(project_name, policy) + print('Updated', policy.name) +# [END monitoring_alert_enable_channel] +# [END monitoring_alert_restore_policies] +# [END monitoring_alert_create_policy] +# [END monitoring_alert_create_channel] +# [END monitoring_alert_update_channel] + + +class MissingProjectIdError(Exception): + pass + + +def project_id(): + """Retreieves the project id from the environment variable. + + Raises: + MissingProjectIdError -- When not set. + + Returns: + str -- the project name + """ + project_id = os.environ['GOOGLE_CLOUD_PROJECT'] + + if not project_id: + raise MissingProjectIdError( + 'Set the environment variable ' + + 'GCLOUD_PROJECT to your Google Cloud Project Id.') + return project_id + + +def project_name(): + return 'projects/' + project_id() + + +if __name__ == '__main__': + + parser = argparse.ArgumentParser( + description='Demonstrates AlertPolicy API operations.') + + subparsers = parser.add_subparsers(dest='command') + + list_alert_policies_parser = subparsers.add_parser( + 'list-alert-policies', + help=list_alert_policies.__doc__ + ) + + list_notification_channels_parser = subparsers.add_parser( + 'list-notification-channels', + help=list_alert_policies.__doc__ + ) + + enable_alert_policies_parser = subparsers.add_parser( + 'enable-alert-policies', + help=enable_alert_policies.__doc__ + ) + enable_alert_policies_parser.add_argument( + '--filter', + ) + + disable_alert_policies_parser = subparsers.add_parser( + 'disable-alert-policies', + help=enable_alert_policies.__doc__ + ) + disable_alert_policies_parser.add_argument( + '--filter', + ) + + replace_notification_channels_parser = subparsers.add_parser( + 'replace-notification-channels', + help=replace_notification_channels.__doc__ + ) + replace_notification_channels_parser.add_argument( + '-p', '--alert_policy_id', + required=True + ) + replace_notification_channels_parser.add_argument( + '-c', '--notification_channel_id', + required=True, + action='append' + ) + + backup_parser = subparsers.add_parser( + 'backup', + help=backup.__doc__ + ) + backup_parser.add_argument( + '--backup_to_filename', + required=True + ) + + restore_parser = subparsers.add_parser( + 'restore', + help=restore.__doc__ + ) + restore_parser.add_argument( + '--restore_from_filename', + required=True + ) + + args = parser.parse_args() + + if args.command == 'list-alert-policies': + list_alert_policies(project_name()) + + elif args.command == 'list-notification-channels': + list_notification_channels(project_name()) + + elif args.command == 'enable-alert-policies': + enable_alert_policies(project_name(), enable=True, filter_=args.filter) + + elif args.command == 'disable-alert-policies': + enable_alert_policies(project_name(), enable=False, + filter_=args.filter) + + elif args.command == 'replace-notification-channels': + replace_notification_channels(project_name(), args.alert_policy_id, + args.notification_channel_id) + + elif args.command == 'backup': + backup(project_name(), args.backup_to_filename) + + elif args.command == 'restore': + restore(project_name(), args.restore_from_filename) diff --git a/monitoring/snippets/v3/alerts-client/snippets_test.py b/monitoring/snippets/v3/alerts-client/snippets_test.py new file mode 100644 index 00000000000..550a8dc9759 --- /dev/null +++ b/monitoring/snippets/v3/alerts-client/snippets_test.py @@ -0,0 +1,195 @@ +# Copyright 2018 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. + +from __future__ import print_function + +import random +import string +import time + +from google.api_core.exceptions import Aborted +from google.api_core.exceptions import DeadlineExceeded +from google.api_core.exceptions import NotFound +from google.api_core.exceptions import ServiceUnavailable +from google.cloud import monitoring_v3 +import google.protobuf.json_format +import pytest +from retrying import retry + +import snippets + + +# We assume we have access to good randomness source. +random.seed() + + +def random_name(length): + return ''.join( + [random.choice(string.ascii_lowercase) for i in range(length)]) + + +def retry_on_exceptions(exception): + return isinstance( + exception, (Aborted, ServiceUnavailable, DeadlineExceeded)) + + +def delay_on_aborted(err, *args): + if retry_on_exceptions(err[1]): + # add randomness for avoiding continuous conflict + time.sleep(5 + (random.randint(0, 9) * 0.1)) + return True + return False + + +class PochanFixture: + """A test fixture that creates an alert POlicy and a notification CHANnel, + hence the name, pochan. + """ + + def __init__(self): + self.project_id = snippets.project_id() + self.project_name = snippets.project_name() + self.alert_policy_client = monitoring_v3.AlertPolicyServiceClient() + self.notification_channel_client = ( + monitoring_v3.NotificationChannelServiceClient()) + + def __enter__(self): + @retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, + stop_max_attempt_number=10, + retry_on_exception=retry_on_exceptions) + def setup(): + # Create a policy. + policy = monitoring_v3.types.alert_pb2.AlertPolicy() + json = open('test_alert_policy.json').read() + google.protobuf.json_format.Parse(json, policy) + policy.display_name = 'snippets-test-' + random_name(10) + self.alert_policy = self.alert_policy_client.create_alert_policy( + self.project_name, policy) + # Create a notification channel. + notification_channel = ( + monitoring_v3.types.notification_pb2.NotificationChannel()) + json = open('test_notification_channel.json').read() + google.protobuf.json_format.Parse(json, notification_channel) + notification_channel.display_name = ( + 'snippets-test-' + random_name(10)) + self.notification_channel = ( + self.notification_channel_client.create_notification_channel( + self.project_name, notification_channel)) + setup() + return self + + def __exit__(self, type, value, traceback): + # Delete the policy and channel we created. + @retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, + stop_max_attempt_number=10, + retry_on_exception=retry_on_exceptions) + def teardown(): + try: + self.alert_policy_client.delete_alert_policy( + self.alert_policy.name) + except NotFound: + print("Ignored NotFound when deleting a policy.") + try: + if self.notification_channel.name: + self.notification_channel_client\ + .delete_notification_channel( + self.notification_channel.name) + except NotFound: + print("Ignored NotFound when deleting a channel.") + teardown() + + +@pytest.fixture(scope='session') +def pochan(): + with PochanFixture() as pochan: + yield pochan + + +def test_list_alert_policies(capsys, pochan): + snippets.list_alert_policies(pochan.project_name) + out, _ = capsys.readouterr() + assert pochan.alert_policy.display_name in out + + +@pytest.mark.flaky(rerun_filter=delay_on_aborted, max_runs=5) +def test_enable_alert_policies(capsys, pochan): + # These sleep calls are for mitigating the following error: + # "409 Too many concurrent edits to the project configuration. + # Please try again." + # Having multiple projects will void these `sleep()` calls. + # See also #3310 + time.sleep(2) + snippets.enable_alert_policies(pochan.project_name, True) + out, _ = capsys.readouterr() + assert "Enabled {0}".format(pochan.project_name) in out \ + or "{} is already enabled".format(pochan.alert_policy.name) in out + + time.sleep(2) + snippets.enable_alert_policies(pochan.project_name, False) + out, _ = capsys.readouterr() + assert "Disabled {}".format(pochan.project_name) in out \ + or "{} is already disabled".format(pochan.alert_policy.name) in out + + +@pytest.mark.flaky(rerun_filter=delay_on_aborted, max_runs=5) +def test_replace_channels(capsys, pochan): + alert_policy_id = pochan.alert_policy.name.split('/')[-1] + notification_channel_id = pochan.notification_channel.name.split('/')[-1] + + # This sleep call is for mitigating the following error: + # "409 Too many concurrent edits to the project configuration. + # Please try again." + # Having multiple projects will void this `sleep()` call. + # See also #3310 + time.sleep(2) + snippets.replace_notification_channels( + pochan.project_name, alert_policy_id, [notification_channel_id]) + out, _ = capsys.readouterr() + assert "Updated {0}".format(pochan.alert_policy.name) in out + + +@pytest.mark.flaky(rerun_filter=delay_on_aborted, max_runs=5) +def test_backup_and_restore(capsys, pochan): + # These sleep calls are for mitigating the following error: + # "409 Too many concurrent edits to the project configuration. + # Please try again." + # Having multiple projects will void this `sleep()` call. + # See also #3310 + time.sleep(2) + snippets.backup(pochan.project_name, 'backup.json') + out, _ = capsys.readouterr() + + time.sleep(2) + snippets.restore(pochan.project_name, 'backup.json') + out, _ = capsys.readouterr() + assert "Updated {0}".format(pochan.alert_policy.name) in out + assert "Updating channel {0}".format( + pochan.notification_channel.display_name) in out + + +@pytest.mark.flaky(rerun_filter=delay_on_aborted, max_runs=5) +def test_delete_channels(capsys, pochan): + notification_channel_id = pochan.notification_channel.name.split('/')[-1] + + # This sleep call is for mitigating the following error: + # "409 Too many concurrent edits to the project configuration. + # Please try again." + # Having multiple projects will void these `sleep()` calls. + # See also #3310 + time.sleep(2) + snippets.delete_notification_channels( + pochan.project_name, [notification_channel_id], force=True) + out, _ = capsys.readouterr() + assert "{0} deleted".format(notification_channel_id) in out + pochan.notification_channel.name = '' # So teardown is not tried diff --git a/monitoring/snippets/v3/alerts-client/test_alert_policy.json b/monitoring/snippets/v3/alerts-client/test_alert_policy.json new file mode 100644 index 00000000000..d728949f9bb --- /dev/null +++ b/monitoring/snippets/v3/alerts-client/test_alert_policy.json @@ -0,0 +1,31 @@ +{ + "displayName": "test_alert_policy.json", + "combiner": "OR", + "conditions": [ + { + "conditionThreshold": { + "filter": "metric.label.state=\"blocked\" AND metric.type=\"agent.googleapis.com/processes/count_by_state\" AND resource.type=\"gce_instance\"", + "comparison": "COMPARISON_GT", + "thresholdValue": 100, + "duration": "900s", + "trigger": { + "percent": 0 + }, + "aggregations": [ + { + "alignmentPeriod": "60s", + "perSeriesAligner": "ALIGN_MEAN", + "crossSeriesReducer": "REDUCE_MEAN", + "groupByFields": [ + "project", + "resource.label.instance_id", + "resource.label.zone" + ] + } + ] + }, + "displayName": "test_alert_policy.json" + } + ], + "enabled": false +} \ No newline at end of file diff --git a/monitoring/snippets/v3/alerts-client/test_notification_channel.json b/monitoring/snippets/v3/alerts-client/test_notification_channel.json new file mode 100644 index 00000000000..6a0d53c00cd --- /dev/null +++ b/monitoring/snippets/v3/alerts-client/test_notification_channel.json @@ -0,0 +1,15 @@ +{ + "type": "email", + "displayName": "Email joe.", + "description": "test_notification_channel.json", + "labels": { + "email_address": "joe@example.com" + }, + "userLabels": { + "office": "california_westcoast_usa", + "division": "fulfillment", + "role": "operations", + "level": "5" + }, + "enabled": true +} \ No newline at end of file diff --git a/monitoring/snippets/v3/cloud-client/README.rst b/monitoring/snippets/v3/cloud-client/README.rst new file mode 100644 index 00000000000..280f9c4e0a7 --- /dev/null +++ b/monitoring/snippets/v3/cloud-client/README.rst @@ -0,0 +1,147 @@ +.. This file is automatically generated. Do not edit this file directly. + +Google Stackdriver Monitoring API Python Samples +=============================================================================== + +.. image:: https://gstatic.com/cloudssh/images/open-btn.png + :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=monitoring/api/v3/cloud-client/README.rst + + +This directory contains samples for Google Stackdriver Monitoring API. Stackdriver Monitoring collects metrics, events, and metadata from Google Cloud Platform, Amazon Web Services (AWS), hosted uptime probes, application instrumentation, and a variety of common application components including Cassandra, Nginx, Apache Web Server, Elasticsearch + and many others. Stackdriver ingests that data and generates insights + via dashboards, charts, and alerts. + + + + +.. _Google Stackdriver Monitoring API: https://cloud.google.com/monitoring/docs/ + +To run the sample, you need to enable the API at: https://console.cloud.google.com/apis/library/monitoring.googleapis.com + +To run the sample, you need to have `Monitoring Admin` role. + + +Please visit [the Cloud Console UI of this API](https://console.cloud.google.com/monitoring) and create a new Workspace with the same name of your Cloud project. + + +Setup +------------------------------------------------------------------------------- + + +Authentication +++++++++++++++ + +This sample requires you to have authentication setup. Refer to the +`Authentication Getting Started Guide`_ for instructions on setting up +credentials for applications. + +.. _Authentication Getting Started Guide: + https://cloud.google.com/docs/authentication/getting-started + +Install Dependencies +++++++++++++++++++++ + +#. Clone python-docs-samples and change directory to the sample directory you want to use. + + .. code-block:: bash + + $ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git + +#. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions. + + .. _Python Development Environment Setup Guide: + https://cloud.google.com/python/setup + +#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. + + .. code-block:: bash + + $ virtualenv env + $ source env/bin/activate + +#. Install the dependencies needed to run the samples. + + .. code-block:: bash + + $ pip install -r requirements.txt + +.. _pip: https://pip.pypa.io/ +.. _virtualenv: https://virtualenv.pypa.io/ + +Samples +------------------------------------------------------------------------------- + +Quickstart ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +.. image:: https://gstatic.com/cloudssh/images/open-btn.png + :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=monitoring/api/v3/cloud-client/quickstart.py,monitoring/api/v3/cloud-client/README.rst + + + + +To run this sample: + +.. code-block:: bash + + $ python quickstart.py + + +Snippets ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +.. image:: https://gstatic.com/cloudssh/images/open-btn.png + :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=monitoring/api/v3/cloud-client/snippets.py,monitoring/api/v3/cloud-client/README.rst + + + + +To run this sample: + +.. code-block:: bash + + $ python snippets.py + + usage: snippets.py [-h] + {create-metric-descriptor,list-metric-descriptors,get-metric-descriptor,delete-metric-descriptor,list-resources,get-resource,write-time-series,list-time-series,list-time-series-header,list-time-series-reduce,list-time-series-aggregate} + ... + + Demonstrates Monitoring API operations. + + positional arguments: + {create-metric-descriptor,list-metric-descriptors,get-metric-descriptor,delete-metric-descriptor,list-resources,get-resource,write-time-series,list-time-series,list-time-series-header,list-time-series-reduce,list-time-series-aggregate} + create-metric-descriptor + list-metric-descriptors + get-metric-descriptor + delete-metric-descriptor + list-resources + get-resource + write-time-series + list-time-series + list-time-series-header + list-time-series-reduce + list-time-series-aggregate + + optional arguments: + -h, --help show this help message and exit + + + + + +The client library +------------------------------------------------------------------------------- + +This sample uses the `Google Cloud Client Library for Python`_. +You can read the documentation for more details on API usage and use GitHub +to `browse the source`_ and `report issues`_. + +.. _Google Cloud Client Library for Python: + https://googlecloudplatform.github.io/google-cloud-python/ +.. _browse the source: + https://github.com/GoogleCloudPlatform/google-cloud-python +.. _report issues: + https://github.com/GoogleCloudPlatform/google-cloud-python/issues + + +.. _Google Cloud SDK: https://cloud.google.com/sdk/ \ No newline at end of file diff --git a/monitoring/snippets/v3/cloud-client/README.rst.in b/monitoring/snippets/v3/cloud-client/README.rst.in new file mode 100644 index 00000000000..0ab6b2258b7 --- /dev/null +++ b/monitoring/snippets/v3/cloud-client/README.rst.in @@ -0,0 +1,35 @@ +# This file is used to generate README.rst + +product: + name: Google Stackdriver Monitoring API + short_name: Stackdriver Monitoring API + url: https://cloud.google.com/monitoring/docs/ + description: > + Stackdriver Monitoring collects metrics, events, and metadata from Google + Cloud Platform, Amazon Web Services (AWS), hosted uptime probes, + application instrumentation, and a variety of common application + components including Cassandra, Nginx, Apache Web Server, Elasticsearch + and many others. Stackdriver ingests that data and generates insights + via dashboards, charts, and alerts. + +required_api_url: https://console.cloud.google.com/apis/library/monitoring.googleapis.com +required_role: Monitoring Admin +other_required_steps: > + Please visit [the Cloud Console UI of this + API](https://console.cloud.google.com/monitoring) and create a new + Workspace with the same name of your Cloud project. + +setup: +- auth +- install_deps + +samples: +- name: Quickstart + file: quickstart.py +- name: Snippets + file: snippets.py + show_help: true + +cloud_client_library: true + +folder: monitoring/api/v3/cloud-client diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py new file mode 100644 index 00000000000..ba55d7ce53c --- /dev/null +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -0,0 +1,224 @@ +# Copyright 2019 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. + +from __future__ import print_function + +import os +from pathlib import Path +import sys + +import nox + + +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING +# DO NOT EDIT THIS FILE EVER! +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING + +# Copy `noxfile_config.py` to your directory and modify it instead. + + +# `TEST_CONFIG` dict is a configuration hook that allows users to +# modify the test configurations. The values here should be in sync +# with `noxfile_config.py`. Users will copy `noxfile_config.py` into +# their directory and modify it. + +TEST_CONFIG = { + # You can opt out from the test for specific Python versions. + 'ignored_versions': ["2.7"], + + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + 'envs': {}, +} + + +try: + # Ensure we can import noxfile_config in the project's directory. + sys.path.append('.') + from noxfile_config import TEST_CONFIG_OVERRIDE +except ImportError as e: + print("No user noxfile_config found: detail: {}".format(e)) + TEST_CONFIG_OVERRIDE = {} + +# Update the TEST_CONFIG with the user supplied values. +TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) + + +def get_pytest_env_vars(): + """Returns a dict for pytest invocation.""" + ret = {} + + # Override the GCLOUD_PROJECT and the alias. + env_key = TEST_CONFIG['gcloud_project_env'] + # This should error out if not set. + ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] + + # Apply user supplied envs. + ret.update(TEST_CONFIG['envs']) + return ret + + +# DO NOT EDIT - automatically generated. +# All versions used to tested samples. +ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] + +# Any default versions that should be ignored. +IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] + +TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) + +INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False)) +# +# Style Checks +# + + +def _determine_local_import_names(start_dir): + """Determines all import names that should be considered "local". + + This is used when running the linter to insure that import order is + properly checked. + """ + file_ext_pairs = [os.path.splitext(path) for path in os.listdir(start_dir)] + return [ + basename + for basename, extension in file_ext_pairs + if extension == ".py" + or os.path.isdir(os.path.join(start_dir, basename)) + and basename not in ("__pycache__") + ] + + +# Linting with flake8. +# +# We ignore the following rules: +# E203: whitespace before ‘:’ +# E266: too many leading ‘#’ for block comment +# E501: line too long +# I202: Additional newline in a section of imports +# +# We also need to specify the rules which are ignored by default: +# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121'] +FLAKE8_COMMON_ARGS = [ + "--show-source", + "--builtin=gettext", + "--max-complexity=20", + "--import-order-style=google", + "--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py", + "--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202", + "--max-line-length=88", +] + + +@nox.session +def lint(session): + session.install("flake8", "flake8-import-order") + + local_names = _determine_local_import_names(".") + args = FLAKE8_COMMON_ARGS + [ + "--application-import-names", + ",".join(local_names), + "." + ] + session.run("flake8", *args) + + +# +# Sample Tests +# + + +PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] + + +def _session_tests(session, post_install=None): + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars() + ) + + +@nox.session(python=ALL_VERSIONS) +def py(session): + """Runs py.test for a sample using the specified version of Python.""" + if session.python in TESTED_VERSIONS: + _session_tests(session) + else: + session.skip("SKIPPED: {} tests are disabled for this sample.".format( + session.python + )) + + +# +# Readmegen +# + + +def _get_repo_root(): + """ Returns the root folder of the project. """ + # Get root of this repository. Assume we don't have directories nested deeper than 10 items. + p = Path(os.getcwd()) + for i in range(10): + if p is None: + break + if Path(p / ".git").exists(): + return str(p) + p = p.parent + raise Exception("Unable to detect repository root.") + + +GENERATED_READMES = sorted([x for x in Path(".").rglob("*.rst.in")]) + + +@nox.session +@nox.parametrize("path", GENERATED_READMES) +def readmegen(session, path): + """(Re-)generates the readme for a sample.""" + session.install("jinja2", "pyyaml") + dir_ = os.path.dirname(path) + + if os.path.exists(os.path.join(dir_, "requirements.txt")): + session.install("-r", os.path.join(dir_, "requirements.txt")) + + in_file = os.path.join(dir_, "README.rst.in") + session.run( + "python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file + ) diff --git a/monitoring/snippets/v3/cloud-client/noxfile_config.py b/monitoring/snippets/v3/cloud-client/noxfile_config.py new file mode 100644 index 00000000000..664c58309d7 --- /dev/null +++ b/monitoring/snippets/v3/cloud-client/noxfile_config.py @@ -0,0 +1,42 @@ +# Copyright 2020 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. + +# Default TEST_CONFIG_OVERRIDE for python repos. + +# You can copy this file into your directory, then it will be inported from +# the noxfile.py. + +# The source of truth: +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py + +TEST_CONFIG_OVERRIDE = { + # You can opt out from the test for specific Python versions. + 'ignored_versions': ["2.7"], + + # Declare optional test sessions you want to opt-in. Currently we + # have the following optional test sessions: + # 'cloud_run' # Test session for Cloud Run application. + 'opt_in_sessions': [], + + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + # 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + 'envs': {}, +} diff --git a/monitoring/snippets/v3/cloud-client/quickstart.py b/monitoring/snippets/v3/cloud-client/quickstart.py new file mode 100644 index 00000000000..0527acae545 --- /dev/null +++ b/monitoring/snippets/v3/cloud-client/quickstart.py @@ -0,0 +1,43 @@ +# Copyright 2017 Google Inc. +# +# 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. + + +def run_quickstart(): + # [START monitoring_quickstart] + from google.cloud import monitoring_v3 + + import time + + client = monitoring_v3.MetricServiceClient() + project = 'my-project' # TODO: Update to your project ID. + project_name = client.project_path(project) + + series = monitoring_v3.types.TimeSeries() + series.metric.type = 'custom.googleapis.com/my_metric' + series.resource.type = 'gce_instance' + series.resource.labels['instance_id'] = '1234567890123456789' + series.resource.labels['zone'] = 'us-central1-f' + point = series.points.add() + point.value.double_value = 3.14 + now = time.time() + point.interval.end_time.seconds = int(now) + point.interval.end_time.nanos = int( + (now - point.interval.end_time.seconds) * 10**9) + client.create_time_series(project_name, [series]) + print('Successfully wrote time series.') + # [END monitoring_quickstart] + + +if __name__ == '__main__': + run_quickstart() diff --git a/monitoring/snippets/v3/cloud-client/quickstart_test.py b/monitoring/snippets/v3/cloud-client/quickstart_test.py new file mode 100644 index 00000000000..fd0191aafc1 --- /dev/null +++ b/monitoring/snippets/v3/cloud-client/quickstart_test.py @@ -0,0 +1,46 @@ +# Copyright 2017 Google Inc. +# +# 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. + +import os + +import backoff +import mock +import pytest + +import quickstart + + +PROJECT = os.environ['GOOGLE_CLOUD_PROJECT'] + + +@pytest.fixture +def mock_project_path(): + """Mock out project and replace with project from environment.""" + project_patch = mock.patch( + 'google.cloud.monitoring_v3.MetricServiceClient.' + 'project_path') + + with project_patch as project_mock: + project_mock.return_value = 'projects/{}'.format(PROJECT) + yield project_mock + + +def test_quickstart(capsys, mock_project_path): + @backoff.on_exception(backoff.expo, AssertionError, max_time=60) + def eventually_consistent_test(): + quickstart.run_quickstart() + out, _ = capsys.readouterr() + assert 'wrote' in out + + eventually_consistent_test() diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt new file mode 100644 index 00000000000..b04e65e37c9 --- /dev/null +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -0,0 +1,3 @@ +backoff==1.10.0 +pytest==6.0.1 +mock==4.0.2 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt new file mode 100644 index 00000000000..10c88fc2f9a --- /dev/null +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -0,0 +1 @@ +google-cloud-monitoring==1.1.0 diff --git a/monitoring/snippets/v3/cloud-client/snippets.py b/monitoring/snippets/v3/cloud-client/snippets.py new file mode 100644 index 00000000000..64b3853fd7c --- /dev/null +++ b/monitoring/snippets/v3/cloud-client/snippets.py @@ -0,0 +1,310 @@ +# Copyright 2017 Google Inc. +# +# 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. + +import argparse +import os +import pprint +import time +import uuid + +from google.cloud import monitoring_v3 + + +PROJECT_ID = os.environ['GOOGLE_CLOUD_PROJECT'] + + +def create_metric_descriptor(project_id): + # [START monitoring_create_metric] + client = monitoring_v3.MetricServiceClient() + project_name = client.project_path(project_id) + descriptor = monitoring_v3.types.MetricDescriptor() + descriptor.type = 'custom.googleapis.com/my_metric' + str(uuid.uuid4()) + descriptor.metric_kind = ( + monitoring_v3.enums.MetricDescriptor.MetricKind.GAUGE) + descriptor.value_type = ( + monitoring_v3.enums.MetricDescriptor.ValueType.DOUBLE) + descriptor.description = 'This is a simple example of a custom metric.' + descriptor = client.create_metric_descriptor(project_name, descriptor) + print('Created {}.'.format(descriptor.name)) + # [END monitoring_create_metric] + + +def delete_metric_descriptor(descriptor_name): + # [START monitoring_delete_metric] + client = monitoring_v3.MetricServiceClient() + client.delete_metric_descriptor(descriptor_name) + print('Deleted metric descriptor {}.'.format(descriptor_name)) + # [END monitoring_delete_metric] + + +def write_time_series(project_id): + # [START monitoring_write_timeseries] + client = monitoring_v3.MetricServiceClient() + project_name = client.project_path(project_id) + + series = monitoring_v3.types.TimeSeries() + series.metric.type = 'custom.googleapis.com/my_metric' + str(uuid.uuid4()) + series.resource.type = 'gce_instance' + series.resource.labels['instance_id'] = '1234567890123456789' + series.resource.labels['zone'] = 'us-central1-f' + point = series.points.add() + point.value.double_value = 3.14 + now = time.time() + point.interval.end_time.seconds = int(now) + point.interval.end_time.nanos = int( + (now - point.interval.end_time.seconds) * 10**9) + client.create_time_series(project_name, [series]) + # [END monitoring_write_timeseries] + + +def list_time_series(project_id): + # [START monitoring_read_timeseries_simple] + client = monitoring_v3.MetricServiceClient() + project_name = client.project_path(project_id) + interval = monitoring_v3.types.TimeInterval() + now = time.time() + interval.end_time.seconds = int(now) + interval.end_time.nanos = int( + (now - interval.end_time.seconds) * 10**9) + interval.start_time.seconds = int(now - 1200) + interval.start_time.nanos = interval.end_time.nanos + results = client.list_time_series( + project_name, + 'metric.type = "compute.googleapis.com/instance/cpu/utilization"', + interval, + monitoring_v3.enums.ListTimeSeriesRequest.TimeSeriesView.FULL) + for result in results: + print(result) + # [END monitoring_read_timeseries_simple] + + +def list_time_series_header(project_id): + # [START monitoring_read_timeseries_fields] + client = monitoring_v3.MetricServiceClient() + project_name = client.project_path(project_id) + interval = monitoring_v3.types.TimeInterval() + now = time.time() + interval.end_time.seconds = int(now) + interval.end_time.nanos = int( + (now - interval.end_time.seconds) * 10**9) + interval.start_time.seconds = int(now - 1200) + interval.start_time.nanos = interval.end_time.nanos + results = client.list_time_series( + project_name, + 'metric.type = "compute.googleapis.com/instance/cpu/utilization"', + interval, + monitoring_v3.enums.ListTimeSeriesRequest.TimeSeriesView.HEADERS) + for result in results: + print(result) + # [END monitoring_read_timeseries_fields] + + +def list_time_series_aggregate(project_id): + # [START monitoring_read_timeseries_align] + client = monitoring_v3.MetricServiceClient() + project_name = client.project_path(project_id) + interval = monitoring_v3.types.TimeInterval() + now = time.time() + interval.end_time.seconds = int(now) + interval.end_time.nanos = int( + (now - interval.end_time.seconds) * 10**9) + interval.start_time.seconds = int(now - 3600) + interval.start_time.nanos = interval.end_time.nanos + aggregation = monitoring_v3.types.Aggregation() + aggregation.alignment_period.seconds = 1200 # 20 minutes + aggregation.per_series_aligner = ( + monitoring_v3.enums.Aggregation.Aligner.ALIGN_MEAN) + + results = client.list_time_series( + project_name, + 'metric.type = "compute.googleapis.com/instance/cpu/utilization"', + interval, + monitoring_v3.enums.ListTimeSeriesRequest.TimeSeriesView.FULL, + aggregation) + for result in results: + print(result) + # [END monitoring_read_timeseries_align] + + +def list_time_series_reduce(project_id): + # [START monitoring_read_timeseries_reduce] + client = monitoring_v3.MetricServiceClient() + project_name = client.project_path(project_id) + interval = monitoring_v3.types.TimeInterval() + now = time.time() + interval.end_time.seconds = int(now) + interval.end_time.nanos = int( + (now - interval.end_time.seconds) * 10**9) + interval.start_time.seconds = int(now - 3600) + interval.start_time.nanos = interval.end_time.nanos + aggregation = monitoring_v3.types.Aggregation() + aggregation.alignment_period.seconds = 1200 # 20 minutes + aggregation.per_series_aligner = ( + monitoring_v3.enums.Aggregation.Aligner.ALIGN_MEAN) + aggregation.cross_series_reducer = ( + monitoring_v3.enums.Aggregation.Reducer.REDUCE_MEAN) + aggregation.group_by_fields.append('resource.zone') + + results = client.list_time_series( + project_name, + 'metric.type = "compute.googleapis.com/instance/cpu/utilization"', + interval, + monitoring_v3.enums.ListTimeSeriesRequest.TimeSeriesView.FULL, + aggregation) + for result in results: + print(result) + # [END monitoring_read_timeseries_reduce] + + +def list_metric_descriptors(project_id): + # [START monitoring_list_descriptors] + client = monitoring_v3.MetricServiceClient() + project_name = client.project_path(project_id) + for descriptor in client.list_metric_descriptors(project_name): + print(descriptor.type) + # [END monitoring_list_descriptors] + + +def list_monitored_resources(project_id): + # [START monitoring_list_resources] + client = monitoring_v3.MetricServiceClient() + project_name = client.project_path(project_id) + resource_descriptors = ( + client.list_monitored_resource_descriptors(project_name)) + for descriptor in resource_descriptors: + print(descriptor.type) + # [END monitoring_list_resources] + + +def get_monitored_resource_descriptor(project_id, resource_type_name): + # [START monitoring_get_resource] + client = monitoring_v3.MetricServiceClient() + resource_path = client.monitored_resource_descriptor_path( + project_id, resource_type_name) + pprint.pprint(client.get_monitored_resource_descriptor(resource_path)) + # [END monitoring_get_resource] + + +def get_metric_descriptor(metric_name): + # [START monitoring_get_descriptor] + client = monitoring_v3.MetricServiceClient() + descriptor = client.get_metric_descriptor(metric_name) + pprint.pprint(descriptor) + # [END monitoring_get_descriptor] + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description='Demonstrates Monitoring API operations.') + + subparsers = parser.add_subparsers(dest='command') + + create_metric_descriptor_parser = subparsers.add_parser( + 'create-metric-descriptor', + help=create_metric_descriptor.__doc__ + ) + + list_metric_descriptor_parser = subparsers.add_parser( + 'list-metric-descriptors', + help=list_metric_descriptors.__doc__ + ) + + get_metric_descriptor_parser = subparsers.add_parser( + 'get-metric-descriptor', + help=get_metric_descriptor.__doc__ + ) + + get_metric_descriptor_parser.add_argument( + '--metric-type-name', + help='The metric type of the metric descriptor to see details about.', + required=True + ) + + delete_metric_descriptor_parser = subparsers.add_parser( + 'delete-metric-descriptor', + help=list_metric_descriptors.__doc__ + ) + + delete_metric_descriptor_parser.add_argument( + '--metric-descriptor-name', + help='Metric descriptor to delete', + required=True + ) + + list_resources_parser = subparsers.add_parser( + 'list-resources', + help=list_monitored_resources.__doc__ + ) + + get_resource_parser = subparsers.add_parser( + 'get-resource', + help=get_monitored_resource_descriptor.__doc__ + ) + + get_resource_parser.add_argument( + '--resource-type-name', + help='Monitored resource to view more information about.', + required=True + ) + + write_time_series_parser = subparsers.add_parser( + 'write-time-series', + help=write_time_series.__doc__ + ) + + list_time_series_parser = subparsers.add_parser( + 'list-time-series', + help=list_time_series.__doc__ + ) + + list_time_series_header_parser = subparsers.add_parser( + 'list-time-series-header', + help=list_time_series_header.__doc__ + ) + + read_time_series_reduce = subparsers.add_parser( + 'list-time-series-reduce', + help=list_time_series_reduce.__doc__ + ) + + read_time_series_aggregate = subparsers.add_parser( + 'list-time-series-aggregate', + help=list_time_series_aggregate.__doc__ + ) + + args = parser.parse_args() + + if args.command == 'create-metric-descriptor': + create_metric_descriptor(PROJECT_ID) + if args.command == 'list-metric-descriptors': + list_metric_descriptors(PROJECT_ID) + if args.command == 'get-metric-descriptor': + get_metric_descriptor(args.metric_type_name) + if args.command == 'delete-metric-descriptor': + delete_metric_descriptor(args.metric_descriptor_name) + if args.command == 'list-resources': + list_monitored_resources(PROJECT_ID) + if args.command == 'get-resource': + get_monitored_resource_descriptor( + PROJECT_ID, args.resource_type_name) + if args.command == 'write-time-series': + write_time_series(PROJECT_ID) + if args.command == 'list-time-series': + list_time_series(PROJECT_ID) + if args.command == 'list-time-series-header': + list_time_series_header(PROJECT_ID) + if args.command == 'list-time-series-reduce': + list_time_series_reduce(PROJECT_ID) + if args.command == 'list-time-series-aggregate': + list_time_series_aggregate(PROJECT_ID) diff --git a/monitoring/snippets/v3/cloud-client/snippets_test.py b/monitoring/snippets/v3/cloud-client/snippets_test.py new file mode 100644 index 00000000000..5aabbda8392 --- /dev/null +++ b/monitoring/snippets/v3/cloud-client/snippets_test.py @@ -0,0 +1,117 @@ +# Copyright 2017 Google Inc. +# +# 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. + +import os +import re + +import backoff +from google.api_core.exceptions import InternalServerError +from google.api_core.exceptions import NotFound +import pytest + +import snippets + + +PROJECT_ID = os.environ['GOOGLE_CLOUD_PROJECT'] + + +@pytest.fixture(scope="function") +def custom_metric_descriptor(capsys): + snippets.create_metric_descriptor(PROJECT_ID) + out, _ = capsys.readouterr() + match = re.search(r'Created (.*)\.', out) + metric_name = match.group(1) + yield metric_name + + # teardown + try: + snippets.delete_metric_descriptor(metric_name) + except NotFound: + print("Metric descriptor already deleted") + + +@pytest.fixture(scope="module") +def write_time_series(): + + @backoff.on_exception(backoff.expo, InternalServerError, max_time=120) + def write(): + snippets.write_time_series(PROJECT_ID) + + write() + yield + + +def test_get_delete_metric_descriptor(capsys, custom_metric_descriptor): + try: + @backoff.on_exception( + backoff.expo, (AssertionError, NotFound), max_time=60) + def eventually_consistent_test(): + snippets.get_metric_descriptor(custom_metric_descriptor) + out, _ = capsys.readouterr() + assert 'DOUBLE' in out + + eventually_consistent_test() + finally: + snippets.delete_metric_descriptor(custom_metric_descriptor) + out, _ = capsys.readouterr() + assert 'Deleted metric' in out + + +def test_list_metric_descriptors(capsys): + snippets.list_metric_descriptors(PROJECT_ID) + out, _ = capsys.readouterr() + assert 'logging.googleapis.com/byte_count' in out + + +def test_list_resources(capsys): + snippets.list_monitored_resources(PROJECT_ID) + out, _ = capsys.readouterr() + assert 'pubsub_topic' in out + + +def test_get_resources(capsys): + snippets.get_monitored_resource_descriptor( + PROJECT_ID, 'pubsub_topic') + out, _ = capsys.readouterr() + assert 'A topic in Google Cloud Pub/Sub' in out + + +def test_list_time_series(capsys, write_time_series): + snippets.list_time_series(PROJECT_ID) + out, _ = capsys.readouterr() + assert 'gce_instance' in out + + +def test_list_time_series_header(capsys, write_time_series): + snippets.list_time_series_header(PROJECT_ID) + out, _ = capsys.readouterr() + assert 'gce_instance' in out + + +def test_list_time_series_aggregate(capsys, write_time_series): + snippets.list_time_series_aggregate(PROJECT_ID) + out, _ = capsys.readouterr() + assert 'points' in out + assert 'interval' in out + assert 'start_time' in out + assert 'end_time' in out + + +def test_list_time_series_reduce(capsys, write_time_series): + snippets.list_time_series_reduce(PROJECT_ID) + out, _ = capsys.readouterr() + assert 'points' in out + assert 'interval' in out + assert 'start_time' in out + assert 'end_time' in out diff --git a/monitoring/snippets/v3/uptime-check-client/README.rst b/monitoring/snippets/v3/uptime-check-client/README.rst new file mode 100644 index 00000000000..30046bdef9d --- /dev/null +++ b/monitoring/snippets/v3/uptime-check-client/README.rst @@ -0,0 +1,115 @@ +.. This file is automatically generated. Do not edit this file directly. + +Google Stackdriver Uptime Checks API Python Samples +=============================================================================== + +.. image:: https://gstatic.com/cloudssh/images/open-btn.png + :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=monitoring/api/v3/uptime-check-client/README.rst + + +This directory contains samples for Google Stackdriver Uptime Checks API. Stackdriver Monitoring collects metrics, events, and metadata from Google Cloud Platform, Amazon Web Services (AWS), hosted uptime probes, application instrumentation, and a variety of common application components including Cassandra, Nginx, Apache Web Server, Elasticsearch and many others. Stackdriver's Uptime Checks API allows you to create, delete, and list your project's Uptime Checks. + + + + +.. _Google Stackdriver Uptime Checks API: https://cloud.google.com/monitoring/uptime-checks/management + +Setup +------------------------------------------------------------------------------- + + +Authentication +++++++++++++++ + +This sample requires you to have authentication setup. Refer to the +`Authentication Getting Started Guide`_ for instructions on setting up +credentials for applications. + +.. _Authentication Getting Started Guide: + https://cloud.google.com/docs/authentication/getting-started + +Install Dependencies +++++++++++++++++++++ + +#. Clone python-docs-samples and change directory to the sample directory you want to use. + + .. code-block:: bash + + $ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git + +#. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions. + + .. _Python Development Environment Setup Guide: + https://cloud.google.com/python/setup + +#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. + + .. code-block:: bash + + $ virtualenv env + $ source env/bin/activate + +#. Install the dependencies needed to run the samples. + + .. code-block:: bash + + $ pip install -r requirements.txt + +.. _pip: https://pip.pypa.io/ +.. _virtualenv: https://virtualenv.pypa.io/ + +Samples +------------------------------------------------------------------------------- + +Snippets ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +.. image:: https://gstatic.com/cloudssh/images/open-btn.png + :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=monitoring/api/v3/uptime-check-client/snippets.py,monitoring/api/v3/uptime-check-client/README.rst + + + + +To run this sample: + +.. code-block:: bash + + $ python snippets.py + + usage: snippets.py [-h] + {list-uptime-check-configs,list-uptime-check-ips,create-uptime-check,get-uptime-check-config,delete-uptime-check-config} + ... + + Demonstrates Uptime Check API operations. + + positional arguments: + {list-uptime-check-configs,list-uptime-check-ips,create-uptime-check,get-uptime-check-config,delete-uptime-check-config} + list-uptime-check-configs + list-uptime-check-ips + create-uptime-check + get-uptime-check-config + delete-uptime-check-config + + optional arguments: + -h, --help show this help message and exit + + + + + +The client library +------------------------------------------------------------------------------- + +This sample uses the `Google Cloud Client Library for Python`_. +You can read the documentation for more details on API usage and use GitHub +to `browse the source`_ and `report issues`_. + +.. _Google Cloud Client Library for Python: + https://googlecloudplatform.github.io/google-cloud-python/ +.. _browse the source: + https://github.com/GoogleCloudPlatform/google-cloud-python +.. _report issues: + https://github.com/GoogleCloudPlatform/google-cloud-python/issues + + +.. _Google Cloud SDK: https://cloud.google.com/sdk/ \ No newline at end of file diff --git a/monitoring/snippets/v3/uptime-check-client/README.rst.in b/monitoring/snippets/v3/uptime-check-client/README.rst.in new file mode 100644 index 00000000000..1174962e48d --- /dev/null +++ b/monitoring/snippets/v3/uptime-check-client/README.rst.in @@ -0,0 +1,26 @@ +# This file is used to generate README.rst + +product: + name: Google Stackdriver Uptime Checks API + short_name: Stackdriver Uptime Checks API + url: https://cloud.google.com/monitoring/uptime-checks/management + description: > + Stackdriver Monitoring collects metrics, events, and metadata from Google + Cloud Platform, Amazon Web Services (AWS), hosted uptime probes, + application instrumentation, and a variety of common application + components including Cassandra, Nginx, Apache Web Server, Elasticsearch + and many others. Stackdriver's Uptime Checks API allows you to create, + delete, and list your project's Uptime Checks. + +setup: +- auth +- install_deps + +samples: +- name: Snippets + file: snippets.py + show_help: true + +cloud_client_library: true + +folder: monitoring/api/v3/uptime-check-client \ No newline at end of file diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py new file mode 100644 index 00000000000..ba55d7ce53c --- /dev/null +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -0,0 +1,224 @@ +# Copyright 2019 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. + +from __future__ import print_function + +import os +from pathlib import Path +import sys + +import nox + + +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING +# DO NOT EDIT THIS FILE EVER! +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING + +# Copy `noxfile_config.py` to your directory and modify it instead. + + +# `TEST_CONFIG` dict is a configuration hook that allows users to +# modify the test configurations. The values here should be in sync +# with `noxfile_config.py`. Users will copy `noxfile_config.py` into +# their directory and modify it. + +TEST_CONFIG = { + # You can opt out from the test for specific Python versions. + 'ignored_versions': ["2.7"], + + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + 'envs': {}, +} + + +try: + # Ensure we can import noxfile_config in the project's directory. + sys.path.append('.') + from noxfile_config import TEST_CONFIG_OVERRIDE +except ImportError as e: + print("No user noxfile_config found: detail: {}".format(e)) + TEST_CONFIG_OVERRIDE = {} + +# Update the TEST_CONFIG with the user supplied values. +TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) + + +def get_pytest_env_vars(): + """Returns a dict for pytest invocation.""" + ret = {} + + # Override the GCLOUD_PROJECT and the alias. + env_key = TEST_CONFIG['gcloud_project_env'] + # This should error out if not set. + ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] + + # Apply user supplied envs. + ret.update(TEST_CONFIG['envs']) + return ret + + +# DO NOT EDIT - automatically generated. +# All versions used to tested samples. +ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] + +# Any default versions that should be ignored. +IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] + +TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) + +INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False)) +# +# Style Checks +# + + +def _determine_local_import_names(start_dir): + """Determines all import names that should be considered "local". + + This is used when running the linter to insure that import order is + properly checked. + """ + file_ext_pairs = [os.path.splitext(path) for path in os.listdir(start_dir)] + return [ + basename + for basename, extension in file_ext_pairs + if extension == ".py" + or os.path.isdir(os.path.join(start_dir, basename)) + and basename not in ("__pycache__") + ] + + +# Linting with flake8. +# +# We ignore the following rules: +# E203: whitespace before ‘:’ +# E266: too many leading ‘#’ for block comment +# E501: line too long +# I202: Additional newline in a section of imports +# +# We also need to specify the rules which are ignored by default: +# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121'] +FLAKE8_COMMON_ARGS = [ + "--show-source", + "--builtin=gettext", + "--max-complexity=20", + "--import-order-style=google", + "--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py", + "--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202", + "--max-line-length=88", +] + + +@nox.session +def lint(session): + session.install("flake8", "flake8-import-order") + + local_names = _determine_local_import_names(".") + args = FLAKE8_COMMON_ARGS + [ + "--application-import-names", + ",".join(local_names), + "." + ] + session.run("flake8", *args) + + +# +# Sample Tests +# + + +PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] + + +def _session_tests(session, post_install=None): + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars() + ) + + +@nox.session(python=ALL_VERSIONS) +def py(session): + """Runs py.test for a sample using the specified version of Python.""" + if session.python in TESTED_VERSIONS: + _session_tests(session) + else: + session.skip("SKIPPED: {} tests are disabled for this sample.".format( + session.python + )) + + +# +# Readmegen +# + + +def _get_repo_root(): + """ Returns the root folder of the project. """ + # Get root of this repository. Assume we don't have directories nested deeper than 10 items. + p = Path(os.getcwd()) + for i in range(10): + if p is None: + break + if Path(p / ".git").exists(): + return str(p) + p = p.parent + raise Exception("Unable to detect repository root.") + + +GENERATED_READMES = sorted([x for x in Path(".").rglob("*.rst.in")]) + + +@nox.session +@nox.parametrize("path", GENERATED_READMES) +def readmegen(session, path): + """(Re-)generates the readme for a sample.""" + session.install("jinja2", "pyyaml") + dir_ = os.path.dirname(path) + + if os.path.exists(os.path.join(dir_, "requirements.txt")): + session.install("-r", os.path.join(dir_, "requirements.txt")) + + in_file = os.path.join(dir_, "README.rst.in") + session.run( + "python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file + ) diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt new file mode 100644 index 00000000000..d0029c6de49 --- /dev/null +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -0,0 +1,2 @@ +backoff==1.10.0 +pytest==6.0.1 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt new file mode 100644 index 00000000000..bc7a2fe57c8 --- /dev/null +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -0,0 +1,2 @@ +google-cloud-monitoring==1.1.0 +tabulate==0.8.7 diff --git a/monitoring/snippets/v3/uptime-check-client/snippets.py b/monitoring/snippets/v3/uptime-check-client/snippets.py new file mode 100644 index 00000000000..dcde3b58650 --- /dev/null +++ b/monitoring/snippets/v3/uptime-check-client/snippets.py @@ -0,0 +1,257 @@ +# Copyright 2018 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. + +from __future__ import print_function + +import argparse +import os +import pprint + +from google.cloud import monitoring_v3 +import tabulate + + +# [START monitoring_uptime_check_create] +def create_uptime_check_config_get(project_name, host_name=None, display_name=None): + config = monitoring_v3.types.uptime_pb2.UptimeCheckConfig() + config.display_name = display_name or "New GET uptime check" + config.monitored_resource.type = "uptime_url" + config.monitored_resource.labels.update({"host": host_name or "example.com"}) + config.http_check.request_method = ( + monitoring_v3.enums.UptimeCheckConfig.HttpCheck.RequestMethod.GET + ) + config.http_check.path = "/" + config.http_check.port = 80 + config.timeout.seconds = 10 + config.period.seconds = 300 + + client = monitoring_v3.UptimeCheckServiceClient() + new_config = client.create_uptime_check_config(project_name, config) + pprint.pprint(new_config) + return new_config + + +def create_uptime_check_config_post(project_name, host_name=None, display_name=None): + config = monitoring_v3.types.uptime_pb2.UptimeCheckConfig() + config.display_name = display_name or "New POST uptime check" + config.monitored_resource.type = "uptime_url" + config.monitored_resource.labels.update({"host": host_name or "example.com"}) + config.http_check.request_method = ( + monitoring_v3.enums.UptimeCheckConfig.HttpCheck.RequestMethod.POST + ) + config.http_check.content_type = ( + monitoring_v3.enums.UptimeCheckConfig.HttpCheck.ContentType.URL_ENCODED + ) + config.http_check.body = "foo=bar".encode("utf-8") + config.http_check.path = "/" + config.http_check.port = 80 + config.timeout.seconds = 10 + config.period.seconds = 300 + + client = monitoring_v3.UptimeCheckServiceClient() + new_config = client.create_uptime_check_config(project_name, config) + pprint.pprint(new_config) + return new_config + + +# [END monitoring_uptime_check_create] + +# [START monitoring_uptime_check_update] +def update_uptime_check_config( + config_name, new_display_name=None, new_http_check_path=None +): + client = monitoring_v3.UptimeCheckServiceClient() + config = client.get_uptime_check_config(config_name) + field_mask = monitoring_v3.types.FieldMask() + if new_display_name: + field_mask.paths.append("display_name") + config.display_name = new_display_name + if new_http_check_path: + field_mask.paths.append("http_check.path") + config.http_check.path = new_http_check_path + client.update_uptime_check_config(config, field_mask) + + +# [END monitoring_uptime_check_update] + + +# [START monitoring_uptime_check_list_configs] +def list_uptime_check_configs(project_name): + client = monitoring_v3.UptimeCheckServiceClient() + configs = client.list_uptime_check_configs(project_name) + + for config in configs: + pprint.pprint(config) + + +# [END monitoring_uptime_check_list_configs] + + +# [START monitoring_uptime_check_list_ips] +def list_uptime_check_ips(): + client = monitoring_v3.UptimeCheckServiceClient() + ips = client.list_uptime_check_ips() + print( + tabulate.tabulate( + [(ip.region, ip.location, ip.ip_address) for ip in ips], + ("region", "location", "ip_address"), + ) + ) + + +# [END monitoring_uptime_check_list_ips] + + +# [START monitoring_uptime_check_get] +def get_uptime_check_config(config_name): + client = monitoring_v3.UptimeCheckServiceClient() + config = client.get_uptime_check_config(config_name) + pprint.pprint(config) + + +# [END monitoring_uptime_check_get] + + +# [START monitoring_uptime_check_delete] +# `config_name` is the `name` field of an UptimeCheckConfig. +# See https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.uptimeCheckConfigs#UptimeCheckConfig. +def delete_uptime_check_config(config_name): + client = monitoring_v3.UptimeCheckServiceClient() + client.delete_uptime_check_config(config_name) + print("Deleted ", config_name) + + +# [END monitoring_uptime_check_delete] + + +class MissingProjectIdError(Exception): + pass + + +def project_id(): + """Retreieves the project id from the environment variable. + + Raises: + MissingProjectIdError -- When not set. + + Returns: + str -- the project name + """ + project_id = os.environ["GOOGLE_CLOUD_PROJECT"] + + if not project_id: + raise MissingProjectIdError( + "Set the environment variable " + + "GCLOUD_PROJECT to your Google Cloud Project Id." + ) + return project_id + + +def project_name(): + return "projects/" + project_id() + + +if __name__ == "__main__": + + parser = argparse.ArgumentParser( + description="Demonstrates Uptime Check API operations." + ) + + subparsers = parser.add_subparsers(dest="command") + + list_uptime_check_configs_parser = subparsers.add_parser( + "list-uptime-check-configs", help=list_uptime_check_configs.__doc__ + ) + + list_uptime_check_ips_parser = subparsers.add_parser( + "list-uptime-check-ips", help=list_uptime_check_ips.__doc__ + ) + + create_uptime_check_config_get_parser = subparsers.add_parser( + "create-uptime-check-get", help=create_uptime_check_config_get.__doc__ + ) + create_uptime_check_config_get_parser.add_argument( + "-d", "--display_name", required=False, + ) + create_uptime_check_config_get_parser.add_argument( + "-o", "--host_name", required=False, + ) + + create_uptime_check_config_post_parser = subparsers.add_parser( + "create-uptime-check-post", help=create_uptime_check_config_post.__doc__ + ) + create_uptime_check_config_post_parser.add_argument( + "-d", "--display_name", required=False, + ) + create_uptime_check_config_post_parser.add_argument( + "-o", "--host_name", required=False, + ) + + get_uptime_check_config_parser = subparsers.add_parser( + "get-uptime-check-config", help=get_uptime_check_config.__doc__ + ) + get_uptime_check_config_parser.add_argument( + "-m", "--name", required=True, + ) + + delete_uptime_check_config_parser = subparsers.add_parser( + "delete-uptime-check-config", help=delete_uptime_check_config.__doc__ + ) + delete_uptime_check_config_parser.add_argument( + "-m", "--name", required=True, + ) + + update_uptime_check_config_parser = subparsers.add_parser( + "update-uptime-check-config", help=update_uptime_check_config.__doc__ + ) + update_uptime_check_config_parser.add_argument( + "-m", "--name", required=True, + ) + update_uptime_check_config_parser.add_argument( + "-d", "--display_name", required=False, + ) + update_uptime_check_config_parser.add_argument( + "-p", "--uptime_check_path", required=False, + ) + + args = parser.parse_args() + + if args.command == "list-uptime-check-configs": + list_uptime_check_configs(project_name()) + + elif args.command == "list-uptime-check-ips": + list_uptime_check_ips() + + elif args.command == "create-uptime-check-get": + create_uptime_check_config_get( + project_name(), args.host_name, args.display_name + ) + elif args.command == "create-uptime-check-post": + create_uptime_check_config_post( + project_name(), args.host_name, args.display_name + ) + + elif args.command == "get-uptime-check-config": + get_uptime_check_config(args.name) + + elif args.command == "delete-uptime-check-config": + delete_uptime_check_config(args.name) + + elif args.command == "update-uptime-check-config": + if not args.display_name and not args.uptime_check_path: + print("Nothing to update. Pass --display_name or " "--uptime_check_path.") + else: + update_uptime_check_config( + args.name, args.display_name, args.uptime_check_path + ) diff --git a/monitoring/snippets/v3/uptime-check-client/snippets_test.py b/monitoring/snippets/v3/uptime-check-client/snippets_test.py new file mode 100644 index 00000000000..81d2b247372 --- /dev/null +++ b/monitoring/snippets/v3/uptime-check-client/snippets_test.py @@ -0,0 +1,105 @@ +# Copyright 2018 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. + +from __future__ import print_function + +import random +import string + +import backoff +from google.api_core.exceptions import DeadlineExceeded +import pytest + +import snippets + + +def random_name(length): + return "".join([random.choice(string.ascii_lowercase) for i in range(length)]) + + +class UptimeFixture: + """A test fixture that creates uptime check config. + """ + + def __init__(self): + self.project_id = snippets.project_id() + self.project_name = snippets.project_name() + + def __enter__(self): + # Create an uptime check config (GET request). + self.config_get = snippets.create_uptime_check_config_get( + self.project_name, display_name=random_name(10) + ) + # Create an uptime check config (POST request). + self.config_post = snippets.create_uptime_check_config_post( + self.project_name, display_name=random_name(10) + ) + return self + + def __exit__(self, type, value, traceback): + # Delete the config. + snippets.delete_uptime_check_config(self.config_get.name) + snippets.delete_uptime_check_config(self.config_post.name) + + +@pytest.fixture(scope="session") +def uptime(): + with UptimeFixture() as uptime: + yield uptime + + +def test_create_and_delete(capsys): + # create and delete happen in uptime fixture. + with UptimeFixture(): + pass + + +def test_update_uptime_config(capsys): + # create and delete happen in uptime fixture. + new_display_name = random_name(10) + new_uptime_check_path = "/" + random_name(10) + with UptimeFixture() as fixture: + # We sometimes see the permission error saying the resource + # may not exist. Weirdly DeadlineExceeded instance is raised + # in this case. + @backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=120) + def call_sample(): + snippets.update_uptime_check_config( + fixture.config_get.name, new_display_name, new_uptime_check_path) + + call_sample() + + out, _ = capsys.readouterr() + snippets.get_uptime_check_config(fixture.config_get.name) + out, _ = capsys.readouterr() + assert new_display_name in out + assert new_uptime_check_path in out + + +def test_get_uptime_check_config(capsys, uptime): + snippets.get_uptime_check_config(uptime.config_get.name) + out, _ = capsys.readouterr() + assert uptime.config_get.display_name in out + + +def test_list_uptime_check_configs(capsys, uptime): + snippets.list_uptime_check_configs(uptime.project_name) + out, _ = capsys.readouterr() + assert uptime.config_get.display_name in out + + +def test_list_uptime_check_ips(capsys): + snippets.list_uptime_check_ips() + out, _ = capsys.readouterr() + assert "Singapore" in out From f42fb464bf9474878f9986582b476726f4be7ba0 Mon Sep 17 00:00:00 2001 From: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Date: Tue, 6 Oct 2020 12:11:53 -0700 Subject: [PATCH 02/77] feat!: move to use microgen (#54) * feat!: move to use microgen * update * Update google/cloud/monitoring_v3/query.py Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> * Update google/cloud/monitoring_v3/query.py Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> --- .../snippets/v3/alerts-client/snippets.py | 263 +++++++++------- .../v3/alerts-client/snippets_test.py | 97 +++--- .../snippets/v3/cloud-client/quickstart.py | 34 +- .../v3/cloud-client/quickstart_test.py | 22 +- .../snippets/v3/cloud-client/snippets.py | 296 ++++++++++-------- .../snippets/v3/cloud-client/snippets_test.py | 42 ++- .../v3/uptime-check-client/snippets.py | 69 ++-- 7 files changed, 432 insertions(+), 391 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/snippets.py b/monitoring/snippets/v3/alerts-client/snippets.py index 80254232e6a..fa9c2d9fb54 100644 --- a/monitoring/snippets/v3/alerts-client/snippets.py +++ b/monitoring/snippets/v3/alerts-client/snippets.py @@ -18,28 +18,40 @@ import json import os +import google.api_core.exceptions from google.cloud import monitoring_v3 -import google.protobuf.json_format +from google.protobuf import field_mask_pb2 as field_mask +import proto import tabulate # [START monitoring_alert_list_policies] def list_alert_policies(project_name): client = monitoring_v3.AlertPolicyServiceClient() - policies = client.list_alert_policies(project_name) - print(tabulate.tabulate( - [(policy.name, policy.display_name) for policy in policies], - ('name', 'display_name'))) + policies = client.list_alert_policies(name=project_name) + print( + tabulate.tabulate( + [(policy.name, policy.display_name) for policy in policies], + ("name", "display_name"), + ) + ) + + # [END monitoring_alert_list_policies] # [START monitoring_alert_list_channels] def list_notification_channels(project_name): client = monitoring_v3.NotificationChannelServiceClient() - channels = client.list_notification_channels(project_name) - print(tabulate.tabulate( - [(channel.name, channel.display_name) for channel in channels], - ('name', 'display_name'))) + channels = client.list_notification_channels(name=project_name) + print( + tabulate.tabulate( + [(channel.name, channel.display_name) for channel in channels], + ("name", "display_name"), + ) + ) + + # [END monitoring_alert_list_channels] @@ -56,37 +68,50 @@ def enable_alert_policies(project_name, enable, filter_=None): """ client = monitoring_v3.AlertPolicyServiceClient() - policies = client.list_alert_policies(project_name, filter_=filter_) + policies = client.list_alert_policies( + request={"name": project_name, "filter": filter_} + ) for policy in policies: - if bool(enable) == policy.enabled.value: - print('Policy', policy.name, 'is already', - 'enabled' if policy.enabled.value else 'disabled') + if bool(enable) == policy.enabled: + print( + "Policy", + policy.name, + "is already", + "enabled" if policy.enabled else "disabled", + ) else: - policy.enabled.value = bool(enable) - mask = monitoring_v3.types.field_mask_pb2.FieldMask() - mask.paths.append('enabled') - client.update_alert_policy(policy, mask) - print('Enabled' if enable else 'Disabled', policy.name) + policy.enabled = bool(enable) + mask = field_mask.FieldMask() + mask.paths.append("enabled") + client.update_alert_policy(alert_policy=policy, update_mask=mask) + print("Enabled" if enable else "Disabled", policy.name) + + # [END monitoring_alert_enable_policies] # [START monitoring_alert_replace_channels] def replace_notification_channels(project_name, alert_policy_id, channel_ids): - _, project_id = project_name.split('/') + _, project_id = project_name.split("/") alert_client = monitoring_v3.AlertPolicyServiceClient() channel_client = monitoring_v3.NotificationChannelServiceClient() - policy = monitoring_v3.types.alert_pb2.AlertPolicy() + policy = monitoring_v3.AlertPolicy() policy.name = alert_client.alert_policy_path(project_id, alert_policy_id) for channel_id in channel_ids: policy.notification_channels.append( - channel_client.notification_channel_path(project_id, channel_id)) + channel_client.notification_channel_path(project_id, channel_id) + ) + + mask = field_mask.FieldMask() + mask.paths.append("notification_channels") + updated_policy = alert_client.update_alert_policy( + alert_policy=policy, update_mask=mask + ) + print("Updated", updated_policy.name) + - mask = monitoring_v3.types.field_mask_pb2.FieldMask() - mask.paths.append('notification_channels') - updated_policy = alert_client.update_alert_policy(policy, mask) - print('Updated', updated_policy.name) # [END monitoring_alert_replace_channels] @@ -94,16 +119,16 @@ def replace_notification_channels(project_name, alert_policy_id, channel_ids): def delete_notification_channels(project_name, channel_ids, force=None): channel_client = monitoring_v3.NotificationChannelServiceClient() for channel_id in channel_ids: - channel_name = '{}/notificationChannels/{}'.format( - project_name, channel_id) + channel_name = "{}/notificationChannels/{}".format(project_name, channel_id) try: - channel_client.delete_notification_channel( - channel_name, force=force) - print('Channel {} deleted'.format(channel_name)) + channel_client.delete_notification_channel(name=channel_name, force=force) + print("Channel {} deleted".format(channel_name)) except ValueError: - print('The parameters are invalid') + print("The parameters are invalid") except Exception as e: - print('API call failed: {}'.format(e)) + print("API call failed: {}".format(e)) + + # [END monitoring_alert_delete_channel] @@ -111,25 +136,29 @@ def delete_notification_channels(project_name, channel_ids, force=None): def backup(project_name, backup_filename): alert_client = monitoring_v3.AlertPolicyServiceClient() channel_client = monitoring_v3.NotificationChannelServiceClient() - record = {'project_name': project_name, - 'policies': list(alert_client.list_alert_policies(project_name)), - 'channels': list(channel_client.list_notification_channels( - project_name))} - json.dump(record, open(backup_filename, 'wt'), cls=ProtoEncoder, indent=2) - print('Backed up alert policies and notification channels to {}.'.format( - backup_filename) + record = { + "project_name": project_name, + "policies": list(alert_client.list_alert_policies(name=project_name)), + "channels": list(channel_client.list_notification_channels(name=project_name)), + } + json.dump(record, open(backup_filename, "wt"), cls=ProtoEncoder, indent=2) + print( + "Backed up alert policies and notification channels to {}.".format( + backup_filename + ) ) class ProtoEncoder(json.JSONEncoder): - """Uses google.protobuf.json_format to encode protobufs as json.""" + """Encode protobufs as json.""" + def default(self, obj): - if type(obj) in (monitoring_v3.types.alert_pb2.AlertPolicy, - monitoring_v3.types.notification_pb2. - NotificationChannel): - text = google.protobuf.json_format.MessageToJson(obj) + if type(obj) in (monitoring_v3.AlertPolicy, monitoring_v3.NotificationChannel): + text = proto.Message.to_json(obj) return json.loads(text) return super(ProtoEncoder, self).default(obj) + + # [END monitoring_alert_backup_policies] @@ -139,21 +168,25 @@ def default(self, obj): # [START monitoring_alert_update_channel] # [START monitoring_alert_enable_channel] def restore(project_name, backup_filename): - print('Loading alert policies and notification channels from {}.'.format( - backup_filename) + print( + "Loading alert policies and notification channels from {}.".format( + backup_filename + ) ) - record = json.load(open(backup_filename, 'rt')) - is_same_project = project_name == record['project_name'] + record = json.load(open(backup_filename, "rt")) + is_same_project = project_name == record["project_name"] # Convert dicts to AlertPolicies. - policies_json = [json.dumps(policy) for policy in record['policies']] - policies = [google.protobuf.json_format.Parse( - policy_json, monitoring_v3.types.alert_pb2.AlertPolicy()) - for policy_json in policies_json] + policies_json = [json.dumps(policy) for policy in record["policies"]] + policies = [ + monitoring_v3.AlertPolicy.from_json(policy_json) + for policy_json in policies_json + ] # Convert dicts to NotificationChannels - channels_json = [json.dumps(channel) for channel in record['channels']] - channels = [google.protobuf.json_format.Parse( - channel_json, monitoring_v3.types.notification_pb2. - NotificationChannel()) for channel_json in channels_json] + channels_json = [json.dumps(channel) for channel in record["channels"]] + channels = [ + monitoring_v3.NotificationChannel.from_json(channel_json) + for channel_json in channels_json + ] # Restore the channels. channel_client = monitoring_v3.NotificationChannelServiceClient() @@ -161,16 +194,17 @@ def restore(project_name, backup_filename): for channel in channels: updated = False - print('Updating channel', channel.display_name) + print("Updating channel", channel.display_name) # This field is immutable and it is illegal to specify a # non-default value (UNVERIFIED or VERIFIED) in the # Create() or Update() operations. - channel.verification_status = monitoring_v3.enums.NotificationChannel.\ - VerificationStatus.VERIFICATION_STATUS_UNSPECIFIED + channel.verification_status = ( + monitoring_v3.NotificationChannel.VerificationStatus.VERIFICATION_STATUS_UNSPECIFIED + ) if is_same_project: try: - channel_client.update_notification_channel(channel) + channel_client.update_notification_channel(notification_channel=channel) updated = True except google.api_core.exceptions.NotFound: pass # The channel was deleted. Create it below. @@ -178,19 +212,20 @@ def restore(project_name, backup_filename): if not updated: # The channel no longer exists. Recreate it. old_name = channel.name - channel.ClearField("name") + del channel.name new_channel = channel_client.create_notification_channel( - project_name, channel) + name=project_name, notification_channel=channel + ) channel_name_map[old_name] = new_channel.name # Restore the alerts alert_client = monitoring_v3.AlertPolicyServiceClient() for policy in policies: - print('Updating policy', policy.display_name) + print("Updating policy", policy.display_name) # These two fields cannot be set directly, so clear them. - policy.ClearField('creation_record') - policy.ClearField('mutation_record') + del policy.creation_record + del policy.mutation_record # Update old channel names with new channel names. for i, channel in enumerate(policy.notification_channels): @@ -202,7 +237,7 @@ def restore(project_name, backup_filename): if is_same_project: try: - alert_client.update_alert_policy(policy) + alert_client.update_alert_policy(alert_policy=policy) updated = True except google.api_core.exceptions.NotFound: pass # The policy was deleted. Create it below. @@ -214,11 +249,15 @@ def restore(project_name, backup_filename): if not updated: # The policy no longer exists. Recreate it. old_name = policy.name - policy.ClearField("name") + del policy.name for condition in policy.conditions: - condition.ClearField("name") - policy = alert_client.create_alert_policy(project_name, policy) - print('Updated', policy.name) + del condition.name + policy = alert_client.create_alert_policy( + name=project_name, alert_policy=policy + ) + print("Updated", policy.name) + + # [END monitoring_alert_enable_channel] # [END monitoring_alert_restore_policies] # [END monitoring_alert_create_policy] @@ -239,105 +278,87 @@ def project_id(): Returns: str -- the project name """ - project_id = os.environ['GOOGLE_CLOUD_PROJECT'] + project_id = os.environ["GOOGLE_CLOUD_PROJECT"] if not project_id: raise MissingProjectIdError( - 'Set the environment variable ' + - 'GCLOUD_PROJECT to your Google Cloud Project Id.') + "Set the environment variable " + + "GCLOUD_PROJECT to your Google Cloud Project Id." + ) return project_id def project_name(): - return 'projects/' + project_id() + return "projects/" + project_id() -if __name__ == '__main__': +if __name__ == "__main__": parser = argparse.ArgumentParser( - description='Demonstrates AlertPolicy API operations.') + description="Demonstrates AlertPolicy API operations." + ) - subparsers = parser.add_subparsers(dest='command') + subparsers = parser.add_subparsers(dest="command") list_alert_policies_parser = subparsers.add_parser( - 'list-alert-policies', - help=list_alert_policies.__doc__ + "list-alert-policies", help=list_alert_policies.__doc__ ) list_notification_channels_parser = subparsers.add_parser( - 'list-notification-channels', - help=list_alert_policies.__doc__ + "list-notification-channels", help=list_alert_policies.__doc__ ) enable_alert_policies_parser = subparsers.add_parser( - 'enable-alert-policies', - help=enable_alert_policies.__doc__ + "enable-alert-policies", help=enable_alert_policies.__doc__ ) enable_alert_policies_parser.add_argument( - '--filter', + "--filter", ) disable_alert_policies_parser = subparsers.add_parser( - 'disable-alert-policies', - help=enable_alert_policies.__doc__ + "disable-alert-policies", help=enable_alert_policies.__doc__ ) disable_alert_policies_parser.add_argument( - '--filter', + "--filter", ) replace_notification_channels_parser = subparsers.add_parser( - 'replace-notification-channels', - help=replace_notification_channels.__doc__ + "replace-notification-channels", help=replace_notification_channels.__doc__ ) replace_notification_channels_parser.add_argument( - '-p', '--alert_policy_id', - required=True + "-p", "--alert_policy_id", required=True ) replace_notification_channels_parser.add_argument( - '-c', '--notification_channel_id', - required=True, - action='append' + "-c", "--notification_channel_id", required=True, action="append" ) - backup_parser = subparsers.add_parser( - 'backup', - help=backup.__doc__ - ) - backup_parser.add_argument( - '--backup_to_filename', - required=True - ) + backup_parser = subparsers.add_parser("backup", help=backup.__doc__) + backup_parser.add_argument("--backup_to_filename", required=True) - restore_parser = subparsers.add_parser( - 'restore', - help=restore.__doc__ - ) - restore_parser.add_argument( - '--restore_from_filename', - required=True - ) + restore_parser = subparsers.add_parser("restore", help=restore.__doc__) + restore_parser.add_argument("--restore_from_filename", required=True) args = parser.parse_args() - if args.command == 'list-alert-policies': + if args.command == "list-alert-policies": list_alert_policies(project_name()) - elif args.command == 'list-notification-channels': + elif args.command == "list-notification-channels": list_notification_channels(project_name()) - elif args.command == 'enable-alert-policies': + elif args.command == "enable-alert-policies": enable_alert_policies(project_name(), enable=True, filter_=args.filter) - elif args.command == 'disable-alert-policies': - enable_alert_policies(project_name(), enable=False, - filter_=args.filter) + elif args.command == "disable-alert-policies": + enable_alert_policies(project_name(), enable=False, filter_=args.filter) - elif args.command == 'replace-notification-channels': - replace_notification_channels(project_name(), args.alert_policy_id, - args.notification_channel_id) + elif args.command == "replace-notification-channels": + replace_notification_channels( + project_name(), args.alert_policy_id, args.notification_channel_id + ) - elif args.command == 'backup': + elif args.command == "backup": backup(project_name(), args.backup_to_filename) - elif args.command == 'restore': + elif args.command == "restore": restore(project_name(), args.restore_from_filename) diff --git a/monitoring/snippets/v3/alerts-client/snippets_test.py b/monitoring/snippets/v3/alerts-client/snippets_test.py index 550a8dc9759..ca90a1709fe 100644 --- a/monitoring/snippets/v3/alerts-client/snippets_test.py +++ b/monitoring/snippets/v3/alerts-client/snippets_test.py @@ -23,7 +23,6 @@ from google.api_core.exceptions import NotFound from google.api_core.exceptions import ServiceUnavailable from google.cloud import monitoring_v3 -import google.protobuf.json_format import pytest from retrying import retry @@ -35,13 +34,11 @@ def random_name(length): - return ''.join( - [random.choice(string.ascii_lowercase) for i in range(length)]) + return "".join([random.choice(string.ascii_lowercase) for i in range(length)]) def retry_on_exceptions(exception): - return isinstance( - exception, (Aborted, ServiceUnavailable, DeadlineExceeded)) + return isinstance(exception, (Aborted, ServiceUnavailable, DeadlineExceeded)) def delay_on_aborted(err, *args): @@ -54,7 +51,7 @@ def delay_on_aborted(err, *args): class PochanFixture: """A test fixture that creates an alert POlicy and a notification CHANnel, - hence the name, pochan. + hence the name, pochan. """ def __init__(self): @@ -62,55 +59,64 @@ def __init__(self): self.project_name = snippets.project_name() self.alert_policy_client = monitoring_v3.AlertPolicyServiceClient() self.notification_channel_client = ( - monitoring_v3.NotificationChannelServiceClient()) + monitoring_v3.NotificationChannelServiceClient() + ) def __enter__(self): - @retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, - stop_max_attempt_number=10, - retry_on_exception=retry_on_exceptions) + @retry( + wait_exponential_multiplier=1000, + wait_exponential_max=10000, + stop_max_attempt_number=10, + retry_on_exception=retry_on_exceptions, + ) def setup(): # Create a policy. - policy = monitoring_v3.types.alert_pb2.AlertPolicy() - json = open('test_alert_policy.json').read() - google.protobuf.json_format.Parse(json, policy) - policy.display_name = 'snippets-test-' + random_name(10) + json = open("test_alert_policy.json").read() + policy = monitoring_v3.AlertPolicy.from_json(json) + policy.display_name = "snippets-test-" + random_name(10) self.alert_policy = self.alert_policy_client.create_alert_policy( - self.project_name, policy) + name=self.project_name, alert_policy=policy + ) # Create a notification channel. - notification_channel = ( - monitoring_v3.types.notification_pb2.NotificationChannel()) - json = open('test_notification_channel.json').read() - google.protobuf.json_format.Parse(json, notification_channel) - notification_channel.display_name = ( - 'snippets-test-' + random_name(10)) + json = open("test_notification_channel.json").read() + notification_channel = monitoring_v3.NotificationChannel.from_json(json) + notification_channel.display_name = "snippets-test-" + random_name(10) self.notification_channel = ( self.notification_channel_client.create_notification_channel( - self.project_name, notification_channel)) + name=self.project_name, notification_channel=notification_channel + ) + ) + setup() return self def __exit__(self, type, value, traceback): # Delete the policy and channel we created. - @retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, - stop_max_attempt_number=10, - retry_on_exception=retry_on_exceptions) + @retry( + wait_exponential_multiplier=1000, + wait_exponential_max=10000, + stop_max_attempt_number=10, + retry_on_exception=retry_on_exceptions, + ) def teardown(): try: self.alert_policy_client.delete_alert_policy( - self.alert_policy.name) + name=self.alert_policy.name + ) except NotFound: print("Ignored NotFound when deleting a policy.") try: if self.notification_channel.name: - self.notification_channel_client\ - .delete_notification_channel( - self.notification_channel.name) + self.notification_channel_client.delete_notification_channel( + self.notification_channel.name + ) except NotFound: print("Ignored NotFound when deleting a channel.") + teardown() -@pytest.fixture(scope='session') +@pytest.fixture(scope="session") def pochan(): with PochanFixture() as pochan: yield pochan @@ -132,20 +138,24 @@ def test_enable_alert_policies(capsys, pochan): time.sleep(2) snippets.enable_alert_policies(pochan.project_name, True) out, _ = capsys.readouterr() - assert "Enabled {0}".format(pochan.project_name) in out \ + assert ( + "Enabled {0}".format(pochan.project_name) in out or "{} is already enabled".format(pochan.alert_policy.name) in out + ) time.sleep(2) snippets.enable_alert_policies(pochan.project_name, False) out, _ = capsys.readouterr() - assert "Disabled {}".format(pochan.project_name) in out \ + assert ( + "Disabled {}".format(pochan.project_name) in out or "{} is already disabled".format(pochan.alert_policy.name) in out + ) @pytest.mark.flaky(rerun_filter=delay_on_aborted, max_runs=5) def test_replace_channels(capsys, pochan): - alert_policy_id = pochan.alert_policy.name.split('/')[-1] - notification_channel_id = pochan.notification_channel.name.split('/')[-1] + alert_policy_id = pochan.alert_policy.name.split("/")[-1] + notification_channel_id = pochan.notification_channel.name.split("/")[-1] # This sleep call is for mitigating the following error: # "409 Too many concurrent edits to the project configuration. @@ -154,7 +164,8 @@ def test_replace_channels(capsys, pochan): # See also #3310 time.sleep(2) snippets.replace_notification_channels( - pochan.project_name, alert_policy_id, [notification_channel_id]) + pochan.project_name, alert_policy_id, [notification_channel_id] + ) out, _ = capsys.readouterr() assert "Updated {0}".format(pochan.alert_policy.name) in out @@ -167,20 +178,21 @@ def test_backup_and_restore(capsys, pochan): # Having multiple projects will void this `sleep()` call. # See also #3310 time.sleep(2) - snippets.backup(pochan.project_name, 'backup.json') + snippets.backup(pochan.project_name, "backup.json") out, _ = capsys.readouterr() time.sleep(2) - snippets.restore(pochan.project_name, 'backup.json') + snippets.restore(pochan.project_name, "backup.json") out, _ = capsys.readouterr() assert "Updated {0}".format(pochan.alert_policy.name) in out - assert "Updating channel {0}".format( - pochan.notification_channel.display_name) in out + assert ( + "Updating channel {0}".format(pochan.notification_channel.display_name) in out + ) @pytest.mark.flaky(rerun_filter=delay_on_aborted, max_runs=5) def test_delete_channels(capsys, pochan): - notification_channel_id = pochan.notification_channel.name.split('/')[-1] + notification_channel_id = pochan.notification_channel.name.split("/")[-1] # This sleep call is for mitigating the following error: # "409 Too many concurrent edits to the project configuration. @@ -189,7 +201,8 @@ def test_delete_channels(capsys, pochan): # See also #3310 time.sleep(2) snippets.delete_notification_channels( - pochan.project_name, [notification_channel_id], force=True) + pochan.project_name, [notification_channel_id], force=True + ) out, _ = capsys.readouterr() assert "{0} deleted".format(notification_channel_id) in out - pochan.notification_channel.name = '' # So teardown is not tried + pochan.notification_channel.name = "" # So teardown is not tried diff --git a/monitoring/snippets/v3/cloud-client/quickstart.py b/monitoring/snippets/v3/cloud-client/quickstart.py index 0527acae545..78088dbad9b 100644 --- a/monitoring/snippets/v3/cloud-client/quickstart.py +++ b/monitoring/snippets/v3/cloud-client/quickstart.py @@ -13,31 +13,33 @@ # limitations under the License. -def run_quickstart(): +def run_quickstart(project=""): # [START monitoring_quickstart] from google.cloud import monitoring_v3 import time client = monitoring_v3.MetricServiceClient() - project = 'my-project' # TODO: Update to your project ID. - project_name = client.project_path(project) + # project = 'my-project' # TODO: Update to your project ID. + project_name = f"projects/{project}" - series = monitoring_v3.types.TimeSeries() - series.metric.type = 'custom.googleapis.com/my_metric' - series.resource.type = 'gce_instance' - series.resource.labels['instance_id'] = '1234567890123456789' - series.resource.labels['zone'] = 'us-central1-f' - point = series.points.add() - point.value.double_value = 3.14 + series = monitoring_v3.TimeSeries() + series.metric.type = "custom.googleapis.com/my_metric" + series.resource.type = "gce_instance" + series.resource.labels["instance_id"] = "1234567890123456789" + series.resource.labels["zone"] = "us-central1-f" now = time.time() - point.interval.end_time.seconds = int(now) - point.interval.end_time.nanos = int( - (now - point.interval.end_time.seconds) * 10**9) - client.create_time_series(project_name, [series]) - print('Successfully wrote time series.') + seconds = int(now) + nanos = int((now - seconds) * 10 ** 9) + interval = monitoring_v3.TimeInterval( + {"end_time": {"seconds": seconds, "nanos": nanos}} + ) + point = monitoring_v3.Point({"interval": interval, "value": {"double_value": 3.14}}) + series.points = [point] + client.create_time_series(request={"name": project_name, "time_series": [series]}) + print("Successfully wrote time series.") # [END monitoring_quickstart] -if __name__ == '__main__': +if __name__ == "__main__": run_quickstart() diff --git a/monitoring/snippets/v3/cloud-client/quickstart_test.py b/monitoring/snippets/v3/cloud-client/quickstart_test.py index fd0191aafc1..d7826e92ce5 100644 --- a/monitoring/snippets/v3/cloud-client/quickstart_test.py +++ b/monitoring/snippets/v3/cloud-client/quickstart_test.py @@ -15,32 +15,18 @@ import os import backoff -import mock -import pytest import quickstart -PROJECT = os.environ['GOOGLE_CLOUD_PROJECT'] +PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] -@pytest.fixture -def mock_project_path(): - """Mock out project and replace with project from environment.""" - project_patch = mock.patch( - 'google.cloud.monitoring_v3.MetricServiceClient.' - 'project_path') - - with project_patch as project_mock: - project_mock.return_value = 'projects/{}'.format(PROJECT) - yield project_mock - - -def test_quickstart(capsys, mock_project_path): +def test_quickstart(capsys): @backoff.on_exception(backoff.expo, AssertionError, max_time=60) def eventually_consistent_test(): - quickstart.run_quickstart() + quickstart.run_quickstart(PROJECT) out, _ = capsys.readouterr() - assert 'wrote' in out + assert "wrote" in out eventually_consistent_test() diff --git a/monitoring/snippets/v3/cloud-client/snippets.py b/monitoring/snippets/v3/cloud-client/snippets.py index 64b3853fd7c..1c0407a2bc0 100644 --- a/monitoring/snippets/v3/cloud-client/snippets.py +++ b/monitoring/snippets/v3/cloud-client/snippets.py @@ -18,72 +18,83 @@ import time import uuid +from google.api import metric_pb2 as ga_metric from google.cloud import monitoring_v3 -PROJECT_ID = os.environ['GOOGLE_CLOUD_PROJECT'] +PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"] def create_metric_descriptor(project_id): # [START monitoring_create_metric] client = monitoring_v3.MetricServiceClient() - project_name = client.project_path(project_id) - descriptor = monitoring_v3.types.MetricDescriptor() - descriptor.type = 'custom.googleapis.com/my_metric' + str(uuid.uuid4()) - descriptor.metric_kind = ( - monitoring_v3.enums.MetricDescriptor.MetricKind.GAUGE) - descriptor.value_type = ( - monitoring_v3.enums.MetricDescriptor.ValueType.DOUBLE) - descriptor.description = 'This is a simple example of a custom metric.' - descriptor = client.create_metric_descriptor(project_name, descriptor) - print('Created {}.'.format(descriptor.name)) + project_name = f"projects/{project_id}" + descriptor = ga_metric.MetricDescriptor() + descriptor.type = "custom.googleapis.com/my_metric" + str(uuid.uuid4()) + descriptor.metric_kind = ga_metric.MetricDescriptor.MetricKind.GAUGE + descriptor.value_type = ga_metric.MetricDescriptor.ValueType.DOUBLE + descriptor.description = "This is a simple example of a custom metric." + descriptor = client.create_metric_descriptor( + name=project_name, metric_descriptor=descriptor + ) + print("Created {}.".format(descriptor.name)) # [END monitoring_create_metric] def delete_metric_descriptor(descriptor_name): # [START monitoring_delete_metric] client = monitoring_v3.MetricServiceClient() - client.delete_metric_descriptor(descriptor_name) - print('Deleted metric descriptor {}.'.format(descriptor_name)) + client.delete_metric_descriptor(name=descriptor_name) + print("Deleted metric descriptor {}.".format(descriptor_name)) # [END monitoring_delete_metric] def write_time_series(project_id): # [START monitoring_write_timeseries] client = monitoring_v3.MetricServiceClient() - project_name = client.project_path(project_id) - - series = monitoring_v3.types.TimeSeries() - series.metric.type = 'custom.googleapis.com/my_metric' + str(uuid.uuid4()) - series.resource.type = 'gce_instance' - series.resource.labels['instance_id'] = '1234567890123456789' - series.resource.labels['zone'] = 'us-central1-f' - point = series.points.add() - point.value.double_value = 3.14 + project_name = f"projects/{project_id}" + + series = monitoring_v3.TimeSeries() + series.metric.type = "custom.googleapis.com/my_metric" + str(uuid.uuid4()) + series.resource.type = "gce_instance" + series.resource.labels["instance_id"] = "1234567890123456789" + series.resource.labels["zone"] = "us-central1-f" now = time.time() - point.interval.end_time.seconds = int(now) - point.interval.end_time.nanos = int( - (now - point.interval.end_time.seconds) * 10**9) - client.create_time_series(project_name, [series]) + seconds = int(now) + nanos = int((now - seconds) * 10 ** 9) + interval = monitoring_v3.TimeInterval( + {"end_time": {"seconds": seconds, "nanos": nanos}} + ) + point = monitoring_v3.Point({"interval": interval, "value": {"double_value": 3.14}}) + series.points = [point] + client.create_time_series(name=project_name, time_series=[series]) # [END monitoring_write_timeseries] def list_time_series(project_id): # [START monitoring_read_timeseries_simple] client = monitoring_v3.MetricServiceClient() - project_name = client.project_path(project_id) - interval = monitoring_v3.types.TimeInterval() + project_name = f"projects/{project_id}" + interval = monitoring_v3.TimeInterval() + now = time.time() - interval.end_time.seconds = int(now) - interval.end_time.nanos = int( - (now - interval.end_time.seconds) * 10**9) - interval.start_time.seconds = int(now - 1200) - interval.start_time.nanos = interval.end_time.nanos + seconds = int(now) + nanos = int((now - seconds) * 10 ** 9) + interval = monitoring_v3.TimeInterval( + { + "end_time": {"seconds": seconds, "nanos": nanos}, + "start_time": {"seconds": (seconds - 1200), "nanos": nanos}, + } + ) + results = client.list_time_series( - project_name, - 'metric.type = "compute.googleapis.com/instance/cpu/utilization"', - interval, - monitoring_v3.enums.ListTimeSeriesRequest.TimeSeriesView.FULL) + request={ + "name": project_name, + "filter": 'metric.type = "compute.googleapis.com/instance/cpu/utilization"', + "interval": interval, + "view": monitoring_v3.ListTimeSeriesRequest.TimeSeriesView.FULL, + } + ) for result in results: print(result) # [END monitoring_read_timeseries_simple] @@ -92,19 +103,24 @@ def list_time_series(project_id): def list_time_series_header(project_id): # [START monitoring_read_timeseries_fields] client = monitoring_v3.MetricServiceClient() - project_name = client.project_path(project_id) - interval = monitoring_v3.types.TimeInterval() + project_name = f"projects/{project_id}" now = time.time() - interval.end_time.seconds = int(now) - interval.end_time.nanos = int( - (now - interval.end_time.seconds) * 10**9) - interval.start_time.seconds = int(now - 1200) - interval.start_time.nanos = interval.end_time.nanos + seconds = int(now) + nanos = int((now - seconds) * 10 ** 9) + interval = monitoring_v3.TimeInterval( + { + "end_time": {"seconds": seconds, "nanos": nanos}, + "start_time": {"seconds": (seconds - 1200), "nanos": nanos}, + } + ) results = client.list_time_series( - project_name, - 'metric.type = "compute.googleapis.com/instance/cpu/utilization"', - interval, - monitoring_v3.enums.ListTimeSeriesRequest.TimeSeriesView.HEADERS) + request={ + "name": project_name, + "filter": 'metric.type = "compute.googleapis.com/instance/cpu/utilization"', + "interval": interval, + "view": monitoring_v3.ListTimeSeriesRequest.TimeSeriesView.HEADERS, + } + ) for result in results: print(result) # [END monitoring_read_timeseries_fields] @@ -113,25 +129,33 @@ def list_time_series_header(project_id): def list_time_series_aggregate(project_id): # [START monitoring_read_timeseries_align] client = monitoring_v3.MetricServiceClient() - project_name = client.project_path(project_id) - interval = monitoring_v3.types.TimeInterval() + project_name = f"projects/{project_id}" + now = time.time() - interval.end_time.seconds = int(now) - interval.end_time.nanos = int( - (now - interval.end_time.seconds) * 10**9) - interval.start_time.seconds = int(now - 3600) - interval.start_time.nanos = interval.end_time.nanos - aggregation = monitoring_v3.types.Aggregation() - aggregation.alignment_period.seconds = 1200 # 20 minutes - aggregation.per_series_aligner = ( - monitoring_v3.enums.Aggregation.Aligner.ALIGN_MEAN) + seconds = int(now) + nanos = int((now - seconds) * 10 ** 9) + interval = monitoring_v3.TimeInterval( + { + "end_time": {"seconds": seconds, "nanos": nanos}, + "start_time": {"seconds": (seconds - 3600), "nanos": nanos}, + } + ) + aggregation = monitoring_v3.Aggregation( + { + "alignment_period": {"seconds": 1200}, # 20 minutes + "per_series_aligner": monitoring_v3.Aggregation.Aligner.ALIGN_MEAN, + } + ) results = client.list_time_series( - project_name, - 'metric.type = "compute.googleapis.com/instance/cpu/utilization"', - interval, - monitoring_v3.enums.ListTimeSeriesRequest.TimeSeriesView.FULL, - aggregation) + request={ + "name": project_name, + "filter": 'metric.type = "compute.googleapis.com/instance/cpu/utilization"', + "interval": interval, + "view": monitoring_v3.ListTimeSeriesRequest.TimeSeriesView.FULL, + "aggregation": aggregation, + } + ) for result in results: print(result) # [END monitoring_read_timeseries_align] @@ -140,28 +164,35 @@ def list_time_series_aggregate(project_id): def list_time_series_reduce(project_id): # [START monitoring_read_timeseries_reduce] client = monitoring_v3.MetricServiceClient() - project_name = client.project_path(project_id) - interval = monitoring_v3.types.TimeInterval() + project_name = f"projects/{project_id}" + now = time.time() - interval.end_time.seconds = int(now) - interval.end_time.nanos = int( - (now - interval.end_time.seconds) * 10**9) - interval.start_time.seconds = int(now - 3600) - interval.start_time.nanos = interval.end_time.nanos - aggregation = monitoring_v3.types.Aggregation() - aggregation.alignment_period.seconds = 1200 # 20 minutes - aggregation.per_series_aligner = ( - monitoring_v3.enums.Aggregation.Aligner.ALIGN_MEAN) - aggregation.cross_series_reducer = ( - monitoring_v3.enums.Aggregation.Reducer.REDUCE_MEAN) - aggregation.group_by_fields.append('resource.zone') + seconds = int(now) + nanos = int((now - seconds) * 10 ** 9) + interval = monitoring_v3.TimeInterval( + { + "end_time": {"seconds": seconds, "nanos": nanos}, + "start_time": {"seconds": (seconds - 3600), "nanos": nanos}, + } + ) + aggregation = monitoring_v3.Aggregation( + { + "alignment_period": {"seconds": 1200}, # 20 minutes + "per_series_aligner": monitoring_v3.Aggregation.Aligner.ALIGN_MEAN, + "cross_series_reducer": monitoring_v3.Aggregation.Reducer.REDUCE_MEAN, + "group_by_fields": ["resource.zone"], + } + ) results = client.list_time_series( - project_name, - 'metric.type = "compute.googleapis.com/instance/cpu/utilization"', - interval, - monitoring_v3.enums.ListTimeSeriesRequest.TimeSeriesView.FULL, - aggregation) + request={ + "name": project_name, + "filter": 'metric.type = "compute.googleapis.com/instance/cpu/utilization"', + "interval": interval, + "view": monitoring_v3.ListTimeSeriesRequest.TimeSeriesView.FULL, + "aggregation": aggregation, + } + ) for result in results: print(result) # [END monitoring_read_timeseries_reduce] @@ -170,8 +201,8 @@ def list_time_series_reduce(project_id): def list_metric_descriptors(project_id): # [START monitoring_list_descriptors] client = monitoring_v3.MetricServiceClient() - project_name = client.project_path(project_id) - for descriptor in client.list_metric_descriptors(project_name): + project_name = f"projects/{project_id}" + for descriptor in client.list_metric_descriptors(name=project_name): print(descriptor.type) # [END monitoring_list_descriptors] @@ -179,9 +210,8 @@ def list_metric_descriptors(project_id): def list_monitored_resources(project_id): # [START monitoring_list_resources] client = monitoring_v3.MetricServiceClient() - project_name = client.project_path(project_id) - resource_descriptors = ( - client.list_monitored_resource_descriptors(project_name)) + project_name = f"projects/{project_id}" + resource_descriptors = client.list_monitored_resource_descriptors(name=project_name) for descriptor in resource_descriptors: print(descriptor.type) # [END monitoring_list_resources] @@ -190,121 +220,109 @@ def list_monitored_resources(project_id): def get_monitored_resource_descriptor(project_id, resource_type_name): # [START monitoring_get_resource] client = monitoring_v3.MetricServiceClient() - resource_path = client.monitored_resource_descriptor_path( - project_id, resource_type_name) - pprint.pprint(client.get_monitored_resource_descriptor(resource_path)) + resource_path = ( + f"projects/{project_id}/monitoredResourceDescriptors/{resource_type_name}" + ) + pprint.pprint(client.get_monitored_resource_descriptor(name=resource_path)) # [END monitoring_get_resource] def get_metric_descriptor(metric_name): # [START monitoring_get_descriptor] client = monitoring_v3.MetricServiceClient() - descriptor = client.get_metric_descriptor(metric_name) + descriptor = client.get_metric_descriptor(name=metric_name) pprint.pprint(descriptor) # [END monitoring_get_descriptor] -if __name__ == '__main__': +if __name__ == "__main__": parser = argparse.ArgumentParser( - description='Demonstrates Monitoring API operations.') + description="Demonstrates Monitoring API operations." + ) - subparsers = parser.add_subparsers(dest='command') + subparsers = parser.add_subparsers(dest="command") create_metric_descriptor_parser = subparsers.add_parser( - 'create-metric-descriptor', - help=create_metric_descriptor.__doc__ + "create-metric-descriptor", help=create_metric_descriptor.__doc__ ) list_metric_descriptor_parser = subparsers.add_parser( - 'list-metric-descriptors', - help=list_metric_descriptors.__doc__ + "list-metric-descriptors", help=list_metric_descriptors.__doc__ ) get_metric_descriptor_parser = subparsers.add_parser( - 'get-metric-descriptor', - help=get_metric_descriptor.__doc__ + "get-metric-descriptor", help=get_metric_descriptor.__doc__ ) get_metric_descriptor_parser.add_argument( - '--metric-type-name', - help='The metric type of the metric descriptor to see details about.', - required=True + "--metric-type-name", + help="The metric type of the metric descriptor to see details about.", + required=True, ) delete_metric_descriptor_parser = subparsers.add_parser( - 'delete-metric-descriptor', - help=list_metric_descriptors.__doc__ + "delete-metric-descriptor", help=list_metric_descriptors.__doc__ ) delete_metric_descriptor_parser.add_argument( - '--metric-descriptor-name', - help='Metric descriptor to delete', - required=True + "--metric-descriptor-name", help="Metric descriptor to delete", required=True ) list_resources_parser = subparsers.add_parser( - 'list-resources', - help=list_monitored_resources.__doc__ + "list-resources", help=list_monitored_resources.__doc__ ) get_resource_parser = subparsers.add_parser( - 'get-resource', - help=get_monitored_resource_descriptor.__doc__ + "get-resource", help=get_monitored_resource_descriptor.__doc__ ) get_resource_parser.add_argument( - '--resource-type-name', - help='Monitored resource to view more information about.', - required=True + "--resource-type-name", + help="Monitored resource to view more information about.", + required=True, ) write_time_series_parser = subparsers.add_parser( - 'write-time-series', - help=write_time_series.__doc__ + "write-time-series", help=write_time_series.__doc__ ) list_time_series_parser = subparsers.add_parser( - 'list-time-series', - help=list_time_series.__doc__ + "list-time-series", help=list_time_series.__doc__ ) list_time_series_header_parser = subparsers.add_parser( - 'list-time-series-header', - help=list_time_series_header.__doc__ + "list-time-series-header", help=list_time_series_header.__doc__ ) read_time_series_reduce = subparsers.add_parser( - 'list-time-series-reduce', - help=list_time_series_reduce.__doc__ + "list-time-series-reduce", help=list_time_series_reduce.__doc__ ) read_time_series_aggregate = subparsers.add_parser( - 'list-time-series-aggregate', - help=list_time_series_aggregate.__doc__ + "list-time-series-aggregate", help=list_time_series_aggregate.__doc__ ) args = parser.parse_args() - if args.command == 'create-metric-descriptor': + if args.command == "create-metric-descriptor": create_metric_descriptor(PROJECT_ID) - if args.command == 'list-metric-descriptors': + if args.command == "list-metric-descriptors": list_metric_descriptors(PROJECT_ID) - if args.command == 'get-metric-descriptor': + if args.command == "get-metric-descriptor": get_metric_descriptor(args.metric_type_name) - if args.command == 'delete-metric-descriptor': + if args.command == "delete-metric-descriptor": delete_metric_descriptor(args.metric_descriptor_name) - if args.command == 'list-resources': + if args.command == "list-resources": list_monitored_resources(PROJECT_ID) - if args.command == 'get-resource': - get_monitored_resource_descriptor( - PROJECT_ID, args.resource_type_name) - if args.command == 'write-time-series': + if args.command == "get-resource": + get_monitored_resource_descriptor(PROJECT_ID, args.resource_type_name) + if args.command == "write-time-series": write_time_series(PROJECT_ID) - if args.command == 'list-time-series': + if args.command == "list-time-series": list_time_series(PROJECT_ID) - if args.command == 'list-time-series-header': + if args.command == "list-time-series-header": list_time_series_header(PROJECT_ID) - if args.command == 'list-time-series-reduce': + if args.command == "list-time-series-reduce": list_time_series_reduce(PROJECT_ID) - if args.command == 'list-time-series-aggregate': + if args.command == "list-time-series-aggregate": list_time_series_aggregate(PROJECT_ID) diff --git a/monitoring/snippets/v3/cloud-client/snippets_test.py b/monitoring/snippets/v3/cloud-client/snippets_test.py index 5aabbda8392..d6c7d07adf4 100644 --- a/monitoring/snippets/v3/cloud-client/snippets_test.py +++ b/monitoring/snippets/v3/cloud-client/snippets_test.py @@ -23,14 +23,14 @@ import snippets -PROJECT_ID = os.environ['GOOGLE_CLOUD_PROJECT'] +PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"] @pytest.fixture(scope="function") def custom_metric_descriptor(capsys): snippets.create_metric_descriptor(PROJECT_ID) out, _ = capsys.readouterr() - match = re.search(r'Created (.*)\.', out) + match = re.search(r"Created (.*)\.", out) metric_name = match.group(1) yield metric_name @@ -43,7 +43,6 @@ def custom_metric_descriptor(capsys): @pytest.fixture(scope="module") def write_time_series(): - @backoff.on_exception(backoff.expo, InternalServerError, max_time=120) def write(): snippets.write_time_series(PROJECT_ID) @@ -54,64 +53,63 @@ def write(): def test_get_delete_metric_descriptor(capsys, custom_metric_descriptor): try: - @backoff.on_exception( - backoff.expo, (AssertionError, NotFound), max_time=60) + + @backoff.on_exception(backoff.expo, (AssertionError, NotFound), max_time=60) def eventually_consistent_test(): snippets.get_metric_descriptor(custom_metric_descriptor) out, _ = capsys.readouterr() - assert 'DOUBLE' in out + assert "DOUBLE" in out eventually_consistent_test() finally: snippets.delete_metric_descriptor(custom_metric_descriptor) out, _ = capsys.readouterr() - assert 'Deleted metric' in out + assert "Deleted metric" in out def test_list_metric_descriptors(capsys): snippets.list_metric_descriptors(PROJECT_ID) out, _ = capsys.readouterr() - assert 'logging.googleapis.com/byte_count' in out + assert "logging.googleapis.com/byte_count" in out def test_list_resources(capsys): snippets.list_monitored_resources(PROJECT_ID) out, _ = capsys.readouterr() - assert 'pubsub_topic' in out + assert "pubsub_topic" in out def test_get_resources(capsys): - snippets.get_monitored_resource_descriptor( - PROJECT_ID, 'pubsub_topic') + snippets.get_monitored_resource_descriptor(PROJECT_ID, "pubsub_topic") out, _ = capsys.readouterr() - assert 'A topic in Google Cloud Pub/Sub' in out + assert "A topic in Google Cloud Pub/Sub" in out def test_list_time_series(capsys, write_time_series): snippets.list_time_series(PROJECT_ID) out, _ = capsys.readouterr() - assert 'gce_instance' in out + assert "gce_instance" in out def test_list_time_series_header(capsys, write_time_series): snippets.list_time_series_header(PROJECT_ID) out, _ = capsys.readouterr() - assert 'gce_instance' in out + assert "gce_instance" in out def test_list_time_series_aggregate(capsys, write_time_series): snippets.list_time_series_aggregate(PROJECT_ID) out, _ = capsys.readouterr() - assert 'points' in out - assert 'interval' in out - assert 'start_time' in out - assert 'end_time' in out + assert "points" in out + assert "interval" in out + assert "start_time" in out + assert "end_time" in out def test_list_time_series_reduce(capsys, write_time_series): snippets.list_time_series_reduce(PROJECT_ID) out, _ = capsys.readouterr() - assert 'points' in out - assert 'interval' in out - assert 'start_time' in out - assert 'end_time' in out + assert "points" in out + assert "interval" in out + assert "start_time" in out + assert "end_time" in out diff --git a/monitoring/snippets/v3/uptime-check-client/snippets.py b/monitoring/snippets/v3/uptime-check-client/snippets.py index dcde3b58650..0970b8e7b8c 100644 --- a/monitoring/snippets/v3/uptime-check-client/snippets.py +++ b/monitoring/snippets/v3/uptime-check-client/snippets.py @@ -19,48 +19,51 @@ import pprint from google.cloud import monitoring_v3 +from google.protobuf import field_mask_pb2 import tabulate # [START monitoring_uptime_check_create] def create_uptime_check_config_get(project_name, host_name=None, display_name=None): - config = monitoring_v3.types.uptime_pb2.UptimeCheckConfig() + config = monitoring_v3.UptimeCheckConfig() config.display_name = display_name or "New GET uptime check" - config.monitored_resource.type = "uptime_url" - config.monitored_resource.labels.update({"host": host_name or "example.com"}) - config.http_check.request_method = ( - monitoring_v3.enums.UptimeCheckConfig.HttpCheck.RequestMethod.GET - ) - config.http_check.path = "/" - config.http_check.port = 80 - config.timeout.seconds = 10 - config.period.seconds = 300 + config.monitored_resource = { + "type": "uptime_url", + "labels": {"host": host_name or "example.com"} + } + config.http_check = { + "request_method": monitoring_v3.UptimeCheckConfig.HttpCheck.RequestMethod.GET, + "path": "/", + "port": 80 + } + config.timeout = {"seconds": 10} + config.period = {"seconds": 300} client = monitoring_v3.UptimeCheckServiceClient() - new_config = client.create_uptime_check_config(project_name, config) + new_config = client.create_uptime_check_config(request={"parent": project_name, "uptime_check_config": config}) pprint.pprint(new_config) return new_config def create_uptime_check_config_post(project_name, host_name=None, display_name=None): - config = monitoring_v3.types.uptime_pb2.UptimeCheckConfig() + config = monitoring_v3.UptimeCheckConfig() config.display_name = display_name or "New POST uptime check" - config.monitored_resource.type = "uptime_url" - config.monitored_resource.labels.update({"host": host_name or "example.com"}) - config.http_check.request_method = ( - monitoring_v3.enums.UptimeCheckConfig.HttpCheck.RequestMethod.POST - ) - config.http_check.content_type = ( - monitoring_v3.enums.UptimeCheckConfig.HttpCheck.ContentType.URL_ENCODED - ) - config.http_check.body = "foo=bar".encode("utf-8") - config.http_check.path = "/" - config.http_check.port = 80 - config.timeout.seconds = 10 - config.period.seconds = 300 + config.monitored_resource = { + "type": "uptime_url", + "labels": {"host": host_name or "example.com"} + } + config.http_check = { + "request_method": monitoring_v3.UptimeCheckConfig.HttpCheck.RequestMethod.POST, + "content_type": monitoring_v3.UptimeCheckConfig.HttpCheck.ContentType.URL_ENCODED, + "body": "foo=bar".encode("utf-8"), + "path": "/", + "port": 80 + } + config.timeout = {"seconds": 10} + config.period = {"seconds": 300} client = monitoring_v3.UptimeCheckServiceClient() - new_config = client.create_uptime_check_config(project_name, config) + new_config = client.create_uptime_check_config(request={"parent": project_name, "uptime_check_config": config}) pprint.pprint(new_config) return new_config @@ -72,15 +75,15 @@ def update_uptime_check_config( config_name, new_display_name=None, new_http_check_path=None ): client = monitoring_v3.UptimeCheckServiceClient() - config = client.get_uptime_check_config(config_name) - field_mask = monitoring_v3.types.FieldMask() + config = client.get_uptime_check_config(request={"name": config_name}) + field_mask = field_mask_pb2.FieldMask() if new_display_name: field_mask.paths.append("display_name") config.display_name = new_display_name if new_http_check_path: field_mask.paths.append("http_check.path") config.http_check.path = new_http_check_path - client.update_uptime_check_config(config, field_mask) + client.update_uptime_check_config(request={"uptime_check_config": config, "update_mask": field_mask}) # [END monitoring_uptime_check_update] @@ -89,7 +92,7 @@ def update_uptime_check_config( # [START monitoring_uptime_check_list_configs] def list_uptime_check_configs(project_name): client = monitoring_v3.UptimeCheckServiceClient() - configs = client.list_uptime_check_configs(project_name) + configs = client.list_uptime_check_configs(request={"parent": project_name}) for config in configs: pprint.pprint(config) @@ -101,7 +104,7 @@ def list_uptime_check_configs(project_name): # [START monitoring_uptime_check_list_ips] def list_uptime_check_ips(): client = monitoring_v3.UptimeCheckServiceClient() - ips = client.list_uptime_check_ips() + ips = client.list_uptime_check_ips(request={}) print( tabulate.tabulate( [(ip.region, ip.location, ip.ip_address) for ip in ips], @@ -116,7 +119,7 @@ def list_uptime_check_ips(): # [START monitoring_uptime_check_get] def get_uptime_check_config(config_name): client = monitoring_v3.UptimeCheckServiceClient() - config = client.get_uptime_check_config(config_name) + config = client.get_uptime_check_config(request={"name": config_name}) pprint.pprint(config) @@ -128,7 +131,7 @@ def get_uptime_check_config(config_name): # See https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.uptimeCheckConfigs#UptimeCheckConfig. def delete_uptime_check_config(config_name): client = monitoring_v3.UptimeCheckServiceClient() - client.delete_uptime_check_config(config_name) + client.delete_uptime_check_config(request={"name": config_name}) print("Deleted ", config_name) From 25cc22b5c9b0e4dab64129e0f9ddcf25293de2d1 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 8 Oct 2020 01:26:57 +0200 Subject: [PATCH 03/77] chore(deps): update dependency google-cloud-monitoring to v2 (#56) --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index bc7a2fe57c8..4db0730a1eb 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==1.1.0 +google-cloud-monitoring==2.0.0 tabulate==0.8.7 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 10c88fc2f9a..e664e634110 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==1.1.0 +google-cloud-monitoring==2.0.0 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index bc7a2fe57c8..4db0730a1eb 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==1.1.0 +google-cloud-monitoring==2.0.0 tabulate==0.8.7 From 8d9e5d3ecef24375f768d435e65d68fcc55c2544 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 29 Dec 2020 12:19:25 -0800 Subject: [PATCH 04/77] fix: remove gRPC send/recv limits and expose client transport (#62) --- .../snippets/v3/alerts-client/noxfile.py | 39 +++++++++++++++---- .../snippets/v3/cloud-client/noxfile.py | 39 +++++++++++++++---- .../v3/uptime-check-client/noxfile.py | 39 +++++++++++++++---- 3 files changed, 93 insertions(+), 24 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index ba55d7ce53c..bca0522ec4d 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -17,6 +17,7 @@ import os from pathlib import Path import sys +from typing import Callable, Dict, List, Optional import nox @@ -39,6 +40,10 @@ # You can opt out from the test for specific Python versions. 'ignored_versions': ["2.7"], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + 'enforce_type_hints': False, + # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string @@ -64,7 +69,7 @@ TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) -def get_pytest_env_vars(): +def get_pytest_env_vars() -> Dict[str, str]: """Returns a dict for pytest invocation.""" ret = {} @@ -93,7 +98,7 @@ def get_pytest_env_vars(): # -def _determine_local_import_names(start_dir): +def _determine_local_import_names(start_dir: str) -> List[str]: """Determines all import names that should be considered "local". This is used when running the linter to insure that import order is @@ -131,8 +136,11 @@ def _determine_local_import_names(start_dir): @nox.session -def lint(session): - session.install("flake8", "flake8-import-order") +def lint(session: nox.sessions.Session) -> None: + if not TEST_CONFIG['enforce_type_hints']: + session.install("flake8", "flake8-import-order") + else: + session.install("flake8", "flake8-import-order", "flake8-annotations") local_names = _determine_local_import_names(".") args = FLAKE8_COMMON_ARGS + [ @@ -141,8 +149,18 @@ def lint(session): "." ] session.run("flake8", *args) +# +# Black +# +@nox.session +def blacken(session: nox.sessions.Session) -> None: + session.install("black") + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + session.run("black", *python_files) + # # Sample Tests # @@ -151,7 +169,7 @@ def lint(session): PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] -def _session_tests(session, post_install=None): +def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): session.install("-r", "requirements.txt") @@ -177,7 +195,7 @@ def _session_tests(session, post_install=None): @nox.session(python=ALL_VERSIONS) -def py(session): +def py(session: nox.sessions.Session) -> None: """Runs py.test for a sample using the specified version of Python.""" if session.python in TESTED_VERSIONS: _session_tests(session) @@ -192,7 +210,7 @@ def py(session): # -def _get_repo_root(): +def _get_repo_root() -> Optional[str]: """ Returns the root folder of the project. """ # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) @@ -201,6 +219,11 @@ def _get_repo_root(): break if Path(p / ".git").exists(): return str(p) + # .git is not available in repos cloned via Cloud Build + # setup.py is always in the library's root, so use that instead + # https://github.com/googleapis/synthtool/issues/792 + if Path(p / "setup.py").exists(): + return str(p) p = p.parent raise Exception("Unable to detect repository root.") @@ -210,7 +233,7 @@ def _get_repo_root(): @nox.session @nox.parametrize("path", GENERATED_READMES) -def readmegen(session, path): +def readmegen(session: nox.sessions.Session, path: str) -> None: """(Re-)generates the readme for a sample.""" session.install("jinja2", "pyyaml") dir_ = os.path.dirname(path) diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index ba55d7ce53c..bca0522ec4d 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -17,6 +17,7 @@ import os from pathlib import Path import sys +from typing import Callable, Dict, List, Optional import nox @@ -39,6 +40,10 @@ # You can opt out from the test for specific Python versions. 'ignored_versions': ["2.7"], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + 'enforce_type_hints': False, + # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string @@ -64,7 +69,7 @@ TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) -def get_pytest_env_vars(): +def get_pytest_env_vars() -> Dict[str, str]: """Returns a dict for pytest invocation.""" ret = {} @@ -93,7 +98,7 @@ def get_pytest_env_vars(): # -def _determine_local_import_names(start_dir): +def _determine_local_import_names(start_dir: str) -> List[str]: """Determines all import names that should be considered "local". This is used when running the linter to insure that import order is @@ -131,8 +136,11 @@ def _determine_local_import_names(start_dir): @nox.session -def lint(session): - session.install("flake8", "flake8-import-order") +def lint(session: nox.sessions.Session) -> None: + if not TEST_CONFIG['enforce_type_hints']: + session.install("flake8", "flake8-import-order") + else: + session.install("flake8", "flake8-import-order", "flake8-annotations") local_names = _determine_local_import_names(".") args = FLAKE8_COMMON_ARGS + [ @@ -141,8 +149,18 @@ def lint(session): "." ] session.run("flake8", *args) +# +# Black +# +@nox.session +def blacken(session: nox.sessions.Session) -> None: + session.install("black") + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + session.run("black", *python_files) + # # Sample Tests # @@ -151,7 +169,7 @@ def lint(session): PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] -def _session_tests(session, post_install=None): +def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): session.install("-r", "requirements.txt") @@ -177,7 +195,7 @@ def _session_tests(session, post_install=None): @nox.session(python=ALL_VERSIONS) -def py(session): +def py(session: nox.sessions.Session) -> None: """Runs py.test for a sample using the specified version of Python.""" if session.python in TESTED_VERSIONS: _session_tests(session) @@ -192,7 +210,7 @@ def py(session): # -def _get_repo_root(): +def _get_repo_root() -> Optional[str]: """ Returns the root folder of the project. """ # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) @@ -201,6 +219,11 @@ def _get_repo_root(): break if Path(p / ".git").exists(): return str(p) + # .git is not available in repos cloned via Cloud Build + # setup.py is always in the library's root, so use that instead + # https://github.com/googleapis/synthtool/issues/792 + if Path(p / "setup.py").exists(): + return str(p) p = p.parent raise Exception("Unable to detect repository root.") @@ -210,7 +233,7 @@ def _get_repo_root(): @nox.session @nox.parametrize("path", GENERATED_READMES) -def readmegen(session, path): +def readmegen(session: nox.sessions.Session, path: str) -> None: """(Re-)generates the readme for a sample.""" session.install("jinja2", "pyyaml") dir_ = os.path.dirname(path) diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index ba55d7ce53c..bca0522ec4d 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -17,6 +17,7 @@ import os from pathlib import Path import sys +from typing import Callable, Dict, List, Optional import nox @@ -39,6 +40,10 @@ # You can opt out from the test for specific Python versions. 'ignored_versions': ["2.7"], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + 'enforce_type_hints': False, + # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string @@ -64,7 +69,7 @@ TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) -def get_pytest_env_vars(): +def get_pytest_env_vars() -> Dict[str, str]: """Returns a dict for pytest invocation.""" ret = {} @@ -93,7 +98,7 @@ def get_pytest_env_vars(): # -def _determine_local_import_names(start_dir): +def _determine_local_import_names(start_dir: str) -> List[str]: """Determines all import names that should be considered "local". This is used when running the linter to insure that import order is @@ -131,8 +136,11 @@ def _determine_local_import_names(start_dir): @nox.session -def lint(session): - session.install("flake8", "flake8-import-order") +def lint(session: nox.sessions.Session) -> None: + if not TEST_CONFIG['enforce_type_hints']: + session.install("flake8", "flake8-import-order") + else: + session.install("flake8", "flake8-import-order", "flake8-annotations") local_names = _determine_local_import_names(".") args = FLAKE8_COMMON_ARGS + [ @@ -141,8 +149,18 @@ def lint(session): "." ] session.run("flake8", *args) +# +# Black +# +@nox.session +def blacken(session: nox.sessions.Session) -> None: + session.install("black") + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + session.run("black", *python_files) + # # Sample Tests # @@ -151,7 +169,7 @@ def lint(session): PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] -def _session_tests(session, post_install=None): +def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): session.install("-r", "requirements.txt") @@ -177,7 +195,7 @@ def _session_tests(session, post_install=None): @nox.session(python=ALL_VERSIONS) -def py(session): +def py(session: nox.sessions.Session) -> None: """Runs py.test for a sample using the specified version of Python.""" if session.python in TESTED_VERSIONS: _session_tests(session) @@ -192,7 +210,7 @@ def py(session): # -def _get_repo_root(): +def _get_repo_root() -> Optional[str]: """ Returns the root folder of the project. """ # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) @@ -201,6 +219,11 @@ def _get_repo_root(): break if Path(p / ".git").exists(): return str(p) + # .git is not available in repos cloned via Cloud Build + # setup.py is always in the library's root, so use that instead + # https://github.com/googleapis/synthtool/issues/792 + if Path(p / "setup.py").exists(): + return str(p) p = p.parent raise Exception("Unable to detect repository root.") @@ -210,7 +233,7 @@ def _get_repo_root(): @nox.session @nox.parametrize("path", GENERATED_READMES) -def readmegen(session, path): +def readmegen(session: nox.sessions.Session, path: str) -> None: """(Re-)generates the readme for a sample.""" session.install("jinja2", "pyyaml") dir_ = os.path.dirname(path) From 2f1a4f4266026912b7db524603f21402316c8f73 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Sat, 20 Feb 2021 06:57:11 +0100 Subject: [PATCH 05/77] chore(deps): update dependency google-cloud-monitoring to v2.0.1 (#85) --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index 4db0730a1eb..d5c9844e646 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.0.0 +google-cloud-monitoring==2.0.1 tabulate==0.8.7 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index e664e634110..2155b35767c 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.0.0 +google-cloud-monitoring==2.0.1 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index 4db0730a1eb..d5c9844e646 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.0.0 +google-cloud-monitoring==2.0.1 tabulate==0.8.7 From ead8954957e2d0180114a17d62fbe9eeae3f061c Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 22 Feb 2021 17:05:05 +0100 Subject: [PATCH 06/77] chore(deps): update dependency tabulate to v0.8.9 (#84) --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index d5c9844e646..71e5cabc989 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ google-cloud-monitoring==2.0.1 -tabulate==0.8.7 +tabulate==0.8.9 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index d5c9844e646..71e5cabc989 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ google-cloud-monitoring==2.0.1 -tabulate==0.8.7 +tabulate==0.8.9 From 74471827f01225ce312dbd5dfb8392c38f36dfa3 Mon Sep 17 00:00:00 2001 From: Vinay B S Date: Tue, 2 Mar 2021 16:12:04 -0500 Subject: [PATCH 07/77] feat: Adding labels to the metric descriptor in the snippets.py (#88) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This helps understand how to add labels for custom metrics [1]. [1] https://cloud.google.com/monitoring/custom-metrics/creating-metrics#create-metric-desc Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-monitoring/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [x] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #86 🦕 --- monitoring/snippets/v3/cloud-client/snippets.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/monitoring/snippets/v3/cloud-client/snippets.py b/monitoring/snippets/v3/cloud-client/snippets.py index 1c0407a2bc0..19654e32f37 100644 --- a/monitoring/snippets/v3/cloud-client/snippets.py +++ b/monitoring/snippets/v3/cloud-client/snippets.py @@ -19,6 +19,7 @@ import uuid from google.api import metric_pb2 as ga_metric +from google.api import label_pb2 as ga_label from google.cloud import monitoring_v3 @@ -34,6 +35,13 @@ def create_metric_descriptor(project_id): descriptor.metric_kind = ga_metric.MetricDescriptor.MetricKind.GAUGE descriptor.value_type = ga_metric.MetricDescriptor.ValueType.DOUBLE descriptor.description = "This is a simple example of a custom metric." + + labels = ga_label.LabelDescriptor() + labels.key = "TestLabel" + labels.value_type = ga_label.LabelDescriptor.ValueType.STRING + labels.description = "This is a test label" + descriptor.labels.append(labels) + descriptor = client.create_metric_descriptor( name=project_name, metric_descriptor=descriptor ) From 1a1c7b57c414907eafa3a93d423d689256c62408 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Date: Thu, 11 Mar 2021 17:42:19 -0700 Subject: [PATCH 08/77] fix: fix `as_dataframe` (#91) --- monitoring/snippets/v3/cloud-client/snippets.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/cloud-client/snippets.py b/monitoring/snippets/v3/cloud-client/snippets.py index 19654e32f37..9b47e5da780 100644 --- a/monitoring/snippets/v3/cloud-client/snippets.py +++ b/monitoring/snippets/v3/cloud-client/snippets.py @@ -18,8 +18,8 @@ import time import uuid -from google.api import metric_pb2 as ga_metric from google.api import label_pb2 as ga_label +from google.api import metric_pb2 as ga_metric from google.cloud import monitoring_v3 @@ -35,13 +35,13 @@ def create_metric_descriptor(project_id): descriptor.metric_kind = ga_metric.MetricDescriptor.MetricKind.GAUGE descriptor.value_type = ga_metric.MetricDescriptor.ValueType.DOUBLE descriptor.description = "This is a simple example of a custom metric." - + labels = ga_label.LabelDescriptor() labels.key = "TestLabel" labels.value_type = ga_label.LabelDescriptor.ValueType.STRING labels.description = "This is a test label" descriptor.labels.append(labels) - + descriptor = client.create_metric_descriptor( name=project_name, metric_descriptor=descriptor ) From 14a98457fecd1dd1e51097eba38eadd6f7022d0e Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Fri, 12 Mar 2021 11:19:37 -0800 Subject: [PATCH 09/77] chore: Updating testing, linting, etc (#94) * fix: fixed config for Python and Java grpc lib * chore(python): fix column sizing issue in docs * chore(python): use 'http' in LICENSE * chore(python): skip docfx in main presubmit * chore(python): skip docfx in main presubmit * fix: properly template the repo name * chore: add missing quotation mark * chore: add 3.9 to noxfile template * build(python): make `NOX_SESSION` optional * chore: Add header checker config to python library synth * chore: add noxfile parameters for extra dependencies * build: migrate to flakybot * chore(python): include py.typed files in release * docs: update python contributing guide * build(python): enable flakybot on library unit and system tests * test: install pyopenssl for mtls testing --- monitoring/snippets/v3/alerts-client/noxfile.py | 2 +- monitoring/snippets/v3/cloud-client/noxfile.py | 2 +- monitoring/snippets/v3/uptime-check-client/noxfile.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index bca0522ec4d..97bf7da80e3 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -85,7 +85,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to tested samples. -ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] +ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index bca0522ec4d..97bf7da80e3 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -85,7 +85,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to tested samples. -ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] +ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index bca0522ec4d..97bf7da80e3 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -85,7 +85,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to tested samples. -ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] +ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] From ae039ba55b457982c97fd669176d4a98034f8cdc Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 16 Mar 2021 18:50:05 +0100 Subject: [PATCH 10/77] chore(deps): update dependency google-cloud-monitoring to v2.1.0 (#96) --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index 71e5cabc989..33f4a5bf3be 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.0.1 +google-cloud-monitoring==2.1.0 tabulate==0.8.9 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 2155b35767c..833611c98ed 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.0.1 +google-cloud-monitoring==2.1.0 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index 71e5cabc989..33f4a5bf3be 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.0.1 +google-cloud-monitoring==2.1.0 tabulate==0.8.9 From 46707b795c0fb67211bb3baa54ab2768c5a5fc02 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Fri, 26 Mar 2021 00:34:15 +0100 Subject: [PATCH 11/77] chore(deps): update dependency google-cloud-monitoring to v2.2.0 (#104) --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index 33f4a5bf3be..a78e8be338d 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.1.0 +google-cloud-monitoring==2.2.0 tabulate==0.8.9 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 833611c98ed..536c0dcc144 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.1.0 +google-cloud-monitoring==2.2.0 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index 33f4a5bf3be..a78e8be338d 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.1.0 +google-cloud-monitoring==2.2.0 tabulate==0.8.9 From d3b3bc423fb2ad4925a8fcd2b9c0ff8cf754dc18 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 29 Mar 2021 19:41:50 +0200 Subject: [PATCH 12/77] chore(deps): update dependency google-cloud-monitoring to v2.2.1 (#108) --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index a78e8be338d..c5595e35f9a 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.2.0 +google-cloud-monitoring==2.2.1 tabulate==0.8.9 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 536c0dcc144..91cad4b1899 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.2.0 +google-cloud-monitoring==2.2.1 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index a78e8be338d..c5595e35f9a 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.2.0 +google-cloud-monitoring==2.2.1 tabulate==0.8.9 From b6ae2c41bd082b37787d24bc393dc0687420f55b Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Sun, 11 Apr 2021 05:30:20 -0700 Subject: [PATCH 13/77] chore: add constraints file check for python samples (#118) * chore: add constraints file check for python samples This is the sibling PR to https://github.com/GoogleCloudPlatform/python-docs-samples/pull/5611 and this is the issue opened for it https://github.com/GoogleCloudPlatform/python-docs-samples/issues/5549 --- monitoring/snippets/v3/alerts-client/noxfile.py | 10 ++++++++-- monitoring/snippets/v3/cloud-client/noxfile.py | 10 ++++++++-- monitoring/snippets/v3/uptime-check-client/noxfile.py | 10 ++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index 97bf7da80e3..956cdf4f925 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -172,10 +172,16 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): - session.install("-r", "requirements.txt") + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") if os.path.exists("requirements-test.txt"): - session.install("-r", "requirements-test.txt") + if os.path.exists("constraints-test.txt"): + session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") + else: + session.install("-r", "requirements-test.txt") if INSTALL_LIBRARY_FROM_SOURCE: session.install("-e", _get_repo_root()) diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index 97bf7da80e3..956cdf4f925 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -172,10 +172,16 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): - session.install("-r", "requirements.txt") + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") if os.path.exists("requirements-test.txt"): - session.install("-r", "requirements-test.txt") + if os.path.exists("constraints-test.txt"): + session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") + else: + session.install("-r", "requirements-test.txt") if INSTALL_LIBRARY_FROM_SOURCE: session.install("-e", _get_repo_root()) diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index 97bf7da80e3..956cdf4f925 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -172,10 +172,16 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): - session.install("-r", "requirements.txt") + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") if os.path.exists("requirements-test.txt"): - session.install("-r", "requirements-test.txt") + if os.path.exists("constraints-test.txt"): + session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") + else: + session.install("-r", "requirements-test.txt") if INSTALL_LIBRARY_FROM_SOURCE: session.install("-e", _get_repo_root()) From 79a7fb4fc0f4dc866ae79c1265c997666371a68e Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 13 Apr 2021 19:17:52 +0200 Subject: [PATCH 14/77] chore(deps): update dependency pytest to v6.2.3 (#122) --- monitoring/snippets/v3/alerts-client/requirements-test.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- .../snippets/v3/uptime-check-client/requirements-test.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements-test.txt b/monitoring/snippets/v3/alerts-client/requirements-test.txt index ec623710c6e..e8480d9693b 100644 --- a/monitoring/snippets/v3/alerts-client/requirements-test.txt +++ b/monitoring/snippets/v3/alerts-client/requirements-test.txt @@ -1,3 +1,3 @@ -pytest==6.0.1 +pytest==6.2.3 retrying==1.3.3 flaky==3.7.0 diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index b04e65e37c9..5898b14439b 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ backoff==1.10.0 -pytest==6.0.1 +pytest==6.2.3 mock==4.0.2 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt index d0029c6de49..93f50ad1397 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -1,2 +1,2 @@ backoff==1.10.0 -pytest==6.0.1 +pytest==6.2.3 From 3262877c2add49367d47b8eb3f2fe380336f98ee Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Wed, 12 May 2021 22:28:14 +0200 Subject: [PATCH 15/77] chore(deps): update dependency mock to v4.0.3 (#134) --- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index 5898b14439b..e2b5efdc8c8 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ backoff==1.10.0 pytest==6.2.3 -mock==4.0.2 +mock==4.0.3 From e61ab23301cec4e55b451947ae41b3fc180d0efb Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Sat, 15 May 2021 04:32:04 +0200 Subject: [PATCH 16/77] chore(deps): update dependency pytest to v6.2.4 (#135) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [pytest](https://docs.pytest.org/en/latest/) ([source](https://togithub.com/pytest-dev/pytest), [changelog](https://docs.pytest.org/en/stable/changelog.html)) | `==6.2.3` -> `==6.2.4` | [![age](https://badges.renovateapi.com/packages/pypi/pytest/6.2.4/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/pytest/6.2.4/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/pytest/6.2.4/compatibility-slim/6.2.3)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/pytest/6.2.4/confidence-slim/6.2.3)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
pytest-dev/pytest ### [`v6.2.4`](https://togithub.com/pytest-dev/pytest/releases/6.2.4) [Compare Source](https://togithub.com/pytest-dev/pytest/compare/6.2.3...6.2.4) # pytest 6.2.4 (2021-05-04) ## Bug Fixes - [#​8539](https://togithub.com/pytest-dev/pytest/issues/8539): Fixed assertion rewriting on Python 3.10.
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻️ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/python-monitoring). --- monitoring/snippets/v3/alerts-client/requirements-test.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- .../snippets/v3/uptime-check-client/requirements-test.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements-test.txt b/monitoring/snippets/v3/alerts-client/requirements-test.txt index e8480d9693b..58f68136d5f 100644 --- a/monitoring/snippets/v3/alerts-client/requirements-test.txt +++ b/monitoring/snippets/v3/alerts-client/requirements-test.txt @@ -1,3 +1,3 @@ -pytest==6.2.3 +pytest==6.2.4 retrying==1.3.3 flaky==3.7.0 diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index e2b5efdc8c8..6f3b18720ee 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ backoff==1.10.0 -pytest==6.2.3 +pytest==6.2.4 mock==4.0.3 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt index 93f50ad1397..766a8035d69 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -1,2 +1,2 @@ backoff==1.10.0 -pytest==6.2.3 +pytest==6.2.4 From 6efcc18802f91d5451b1476ddc185e2d3a9da3da Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Sat, 22 May 2021 09:18:14 +0000 Subject: [PATCH 17/77] chore: new owl bot post processor docker image (#142) gcr.io/repo-automation-bots/owlbot-python:latest@sha256:3c3a445b3ddc99ccd5d31edc4b4519729635d20693900db32c4f587ed51f7479 --- monitoring/snippets/v3/alerts-client/noxfile.py | 8 +++++++- monitoring/snippets/v3/cloud-client/noxfile.py | 8 +++++++- monitoring/snippets/v3/uptime-check-client/noxfile.py | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index 956cdf4f925..5ff9e1db580 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -50,7 +50,10 @@ # to use your own Cloud project. 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - + # If you need to use a specific version of pip, + # change pip_version_override to the string representation + # of the version number, for example, "20.2.4" + "pip_version_override": None, # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. 'envs': {}, @@ -170,6 +173,9 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): if os.path.exists("constraints.txt"): diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index 956cdf4f925..5ff9e1db580 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -50,7 +50,10 @@ # to use your own Cloud project. 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - + # If you need to use a specific version of pip, + # change pip_version_override to the string representation + # of the version number, for example, "20.2.4" + "pip_version_override": None, # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. 'envs': {}, @@ -170,6 +173,9 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): if os.path.exists("constraints.txt"): diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index 956cdf4f925..5ff9e1db580 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -50,7 +50,10 @@ # to use your own Cloud project. 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - + # If you need to use a specific version of pip, + # change pip_version_override to the string representation + # of the version number, for example, "20.2.4" + "pip_version_override": None, # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. 'envs': {}, @@ -170,6 +173,9 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): if os.path.exists("constraints.txt"): From 24c6303e8a122c33a42fa5d462919c43d44dc420 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 18 Jun 2021 09:46:04 -0400 Subject: [PATCH 18/77] chore: fix flaky samples test due to truncated string (#156) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR fixes the flaky test reported in #149 where string `'snippets-test-enclcibdnr'`, as an example, is not found in string `'snippets-test-enclci...jects/'` because the string is truncated. We can avoid the issue by casting to `str()` before calling `print()`. Fixes #149 🦕 --- monitoring/snippets/v3/alerts-client/snippets.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/snippets.py b/monitoring/snippets/v3/alerts-client/snippets.py index fa9c2d9fb54..d34e039095a 100644 --- a/monitoring/snippets/v3/alerts-client/snippets.py +++ b/monitoring/snippets/v3/alerts-client/snippets.py @@ -30,9 +30,11 @@ def list_alert_policies(project_name): client = monitoring_v3.AlertPolicyServiceClient() policies = client.list_alert_policies(name=project_name) print( - tabulate.tabulate( - [(policy.name, policy.display_name) for policy in policies], - ("name", "display_name"), + str( + tabulate.tabulate( + [(policy.name, policy.display_name) for policy in policies], + ("name", "display_name"), + ) ) ) From d42123b298c79792cd2ef3be5890994c45b8deee Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 18 Jun 2021 10:58:03 -0400 Subject: [PATCH 19/77] chore: only enable/disable a single policy in test_enable_alert_policies (#157) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR attempts to resolve #150 by only enabling/ disabling a single alert policy, rather than enabling/ disabling all alert polices in the specified project in order to reduce the output that we need to parse for the expected result. From the build log in #150 :`'"snippets-test-ugrikrch..."projects/python-docs-samples-tests-py37'`, the `...` indicates that information is being truncated which would cause flaky results. Fixes #150 🦕 --- monitoring/snippets/v3/alerts-client/snippets_test.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/snippets_test.py b/monitoring/snippets/v3/alerts-client/snippets_test.py index ca90a1709fe..198ac8d5eb3 100644 --- a/monitoring/snippets/v3/alerts-client/snippets_test.py +++ b/monitoring/snippets/v3/alerts-client/snippets_test.py @@ -125,7 +125,9 @@ def pochan(): def test_list_alert_policies(capsys, pochan): snippets.list_alert_policies(pochan.project_name) out, _ = capsys.readouterr() - assert pochan.alert_policy.display_name in out + # Only check up to the first 20 characters of the display name + # as long strings printed to the console are truncated. + assert pochan.alert_policy.display_name[0:20] in out @pytest.mark.flaky(rerun_filter=delay_on_aborted, max_runs=5) @@ -136,7 +138,7 @@ def test_enable_alert_policies(capsys, pochan): # Having multiple projects will void these `sleep()` calls. # See also #3310 time.sleep(2) - snippets.enable_alert_policies(pochan.project_name, True) + snippets.enable_alert_policies(pochan.project_name, True, "name='{}'".format(pochan.alert_policy.name)) out, _ = capsys.readouterr() assert ( "Enabled {0}".format(pochan.project_name) in out @@ -144,7 +146,7 @@ def test_enable_alert_policies(capsys, pochan): ) time.sleep(2) - snippets.enable_alert_policies(pochan.project_name, False) + snippets.enable_alert_policies(pochan.project_name, False, "name='{}'".format(pochan.alert_policy.name)) out, _ = capsys.readouterr() assert ( "Disabled {}".format(pochan.project_name) in out From 0e2cc18242167eddb5408a67b68c4d566ddc26ea Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Fri, 18 Jun 2021 20:17:00 +0200 Subject: [PATCH 20/77] chore(deps): update dependency google-cloud-monitoring to v2.3.0 (#158) --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index c5595e35f9a..cdc33156b16 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.2.1 +google-cloud-monitoring==2.3.0 tabulate==0.8.9 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 91cad4b1899..6e571c26e01 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.2.1 +google-cloud-monitoring==2.3.0 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index c5595e35f9a..cdc33156b16 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.2.1 +google-cloud-monitoring==2.3.0 tabulate==0.8.9 From 83c152ff9b6158b9a9bcd2eb4744138fc388c831 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Mon, 21 Jun 2021 11:57:34 -0400 Subject: [PATCH 21/77] chore: add retry in test_list_alert_policies snippets test (#163) --- .../v3/alerts-client/snippets_test.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/snippets_test.py b/monitoring/snippets/v3/alerts-client/snippets_test.py index 198ac8d5eb3..c6316533589 100644 --- a/monitoring/snippets/v3/alerts-client/snippets_test.py +++ b/monitoring/snippets/v3/alerts-client/snippets_test.py @@ -123,11 +123,20 @@ def pochan(): def test_list_alert_policies(capsys, pochan): - snippets.list_alert_policies(pochan.project_name) - out, _ = capsys.readouterr() - # Only check up to the first 20 characters of the display name - # as long strings printed to the console are truncated. - assert pochan.alert_policy.display_name[0:20] in out + # Query snippets.list_alert_policies() for up to 5 seconds + # to allow the newly created policy to appear in the list. + retry = 5 + while retry: + snippets.list_alert_policies(pochan.project_name) + out, _ = capsys.readouterr() + # Only check up to the first 20 characters of the display name + # as long strings printed to the console are truncated. + if pochan.alert_policy.display_name[0:20] in out: + break + retry = retry - 1 + time.sleep(1) + + assert retry > 0 @pytest.mark.flaky(rerun_filter=delay_on_aborted, max_runs=5) From 499c5da6b8859863f403bb518a13586a8fffd739 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sat, 26 Jun 2021 07:50:22 -0400 Subject: [PATCH 22/77] chore: attempt to fix flaky snippet test test_list_alert_policies (#167) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #149 🦕 --- monitoring/snippets/v3/alerts-client/snippets_test.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/snippets_test.py b/monitoring/snippets/v3/alerts-client/snippets_test.py index c6316533589..7acc98123e1 100644 --- a/monitoring/snippets/v3/alerts-client/snippets_test.py +++ b/monitoring/snippets/v3/alerts-client/snippets_test.py @@ -123,18 +123,16 @@ def pochan(): def test_list_alert_policies(capsys, pochan): - # Query snippets.list_alert_policies() for up to 5 seconds + # Query snippets.list_alert_policies() for up to 50 seconds # to allow the newly created policy to appear in the list. retry = 5 while retry: snippets.list_alert_policies(pochan.project_name) out, _ = capsys.readouterr() - # Only check up to the first 20 characters of the display name - # as long strings printed to the console are truncated. - if pochan.alert_policy.display_name[0:20] in out: + if pochan.alert_policy.display_name in out: break retry = retry - 1 - time.sleep(1) + time.sleep(10) assert retry > 0 From 9a4e9517196fef9639ac743ad1df2c09a8103125 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 29 Jun 2021 19:58:23 -0400 Subject: [PATCH 23/77] chore: clean up alert policies older than 1 hour in snippets test (#170) As a next step in troubleshooting the failure from #149, I'd like to clean up the existing alert policies in the test environment before running tests. --- .../snippets/v3/alerts-client/snippets_test.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/monitoring/snippets/v3/alerts-client/snippets_test.py b/monitoring/snippets/v3/alerts-client/snippets_test.py index 7acc98123e1..b1c62af2fb6 100644 --- a/monitoring/snippets/v3/alerts-client/snippets_test.py +++ b/monitoring/snippets/v3/alerts-client/snippets_test.py @@ -14,6 +14,7 @@ from __future__ import print_function +from datetime import datetime import random import string import time @@ -62,6 +63,17 @@ def __init__(self): monitoring_v3.NotificationChannelServiceClient() ) + # delete all existing policies older than 1 hour prior to testing + for policy in self.alert_policy_client.list_alert_policies(name=self.project_name): + seconds_since_creation = datetime.timestamp(datetime.utcnow())-datetime.timestamp(policy.creation_record.mutate_time) + if seconds_since_creation > 3600: + try: + self.alert_policy_client.delete_alert_policy( + name=policy.name + ) + except NotFound: + print("Ignored NotFound when deleting a policy.") + def __enter__(self): @retry( wait_exponential_multiplier=1000, From 47da66504e3d22634f1a0bcb5a57f402b4508c1c Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 12 Jul 2021 22:08:13 +0200 Subject: [PATCH 24/77] chore(deps): update dependency backoff to v1.11.0 (#174) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [backoff](https://togithub.com/litl/backoff) | `==1.10.0` -> `==1.11.0` | [![age](https://badges.renovateapi.com/packages/pypi/backoff/1.11.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/backoff/1.11.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/backoff/1.11.0/compatibility-slim/1.10.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/backoff/1.11.0/confidence-slim/1.10.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
litl/backoff ### [`v1.11.0`](https://togithub.com/litl/backoff/blob/master/CHANGELOG.md#v1110-2021-07-12) [Compare Source](https://togithub.com/litl/backoff/compare/v1.10.0...v1.11.0) ##### Changed - Configurable logging levels for backoff and giveup events - Minor documentation fixes ##### NOTE THIS WILL BE THE FINAL PYTHON 2.7 COMPATIBLE RELEASE.
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/python-monitoring). --- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- .../snippets/v3/uptime-check-client/requirements-test.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index 6f3b18720ee..305700136f3 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ -backoff==1.10.0 +backoff==1.11.0 pytest==6.2.4 mock==4.0.3 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt index 766a8035d69..b179d9b00ce 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -1,2 +1,2 @@ -backoff==1.10.0 +backoff==1.11.0 pytest==6.2.4 From b978995b04bebefbfe9d1c4dcd9a55e086c2ae57 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 12 Jul 2021 22:10:12 +0200 Subject: [PATCH 25/77] chore(deps): update dependency google-cloud-monitoring to v2.4.0 (#172) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [google-cloud-monitoring](https://togithub.com/googleapis/python-monitoring) | `==2.3.0` -> `==2.4.0` | [![age](https://badges.renovateapi.com/packages/pypi/google-cloud-monitoring/2.4.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/google-cloud-monitoring/2.4.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/google-cloud-monitoring/2.4.0/compatibility-slim/2.3.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/google-cloud-monitoring/2.4.0/confidence-slim/2.3.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
googleapis/python-monitoring ### [`v2.4.0`](https://togithub.com/googleapis/python-monitoring/blob/master/CHANGELOG.md#​240-httpswwwgithubcomgoogleapispython-monitoringcomparev230v240-2021-07-01) [Compare Source](https://togithub.com/googleapis/python-monitoring/compare/v2.3.0...v2.4.0) ##### Features - add always_use_jwt_access ([#​165](https://www.github.com/googleapis/python-monitoring/issues/165)) ([064f1e0](https://www.github.com/googleapis/python-monitoring/commit/064f1e0a8df02c04bdae6b13c645f2b399c2c1ef)) ##### Bug Fixes - disable always_use_jwt_access ([#​171](https://www.github.com/googleapis/python-monitoring/issues/171)) ([c194a00](https://www.github.com/googleapis/python-monitoring/commit/c194a00031763153bcc67346328a02b85fabc359)) ##### Documentation - omit mention of Python 2.7 in 'CONTRIBUTING.rst' ([#​1127](https://www.github.com/googleapis/python-monitoring/issues/1127)) ([#​159](https://www.github.com/googleapis/python-monitoring/issues/159)) ([adc82c9](https://www.github.com/googleapis/python-monitoring/commit/adc82c9d1812fb0efe00cbfa09f19e8c04277881)), closes [#​1126](https://www.github.com/googleapis/python-monitoring/issues/1126)
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/python-monitoring). --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index cdc33156b16..812b773c75d 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.3.0 +google-cloud-monitoring==2.4.0 tabulate==0.8.9 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 6e571c26e01..1f497d5a4de 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.3.0 +google-cloud-monitoring==2.4.0 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index cdc33156b16..812b773c75d 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.3.0 +google-cloud-monitoring==2.4.0 tabulate==0.8.9 From 35f54380fd8482de679b7a91d251e102a663953d Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 22 Jul 2021 13:48:16 +0000 Subject: [PATCH 26/77] feat: add Samples section to CONTRIBUTING.rst (#184) Source-Link: https://github.com/googleapis/synthtool/commit/52e4e46eff2a0b70e3ff5506a02929d089d077d4 Post-Processor: gcr.io/repo-automation-bots/owlbot-python:latest@sha256:6186535cbdbf6b9fe61f00294929221d060634dae4a0795c1cefdbc995b2d605 --- monitoring/snippets/v3/alerts-client/noxfile.py | 5 +++-- monitoring/snippets/v3/cloud-client/noxfile.py | 5 +++-- monitoring/snippets/v3/uptime-check-client/noxfile.py | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index 5ff9e1db580..6a8ccdae22c 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -28,8 +28,9 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -# Copy `noxfile_config.py` to your directory and modify it instead. +BLACK_VERSION = "black==19.10b0" +# Copy `noxfile_config.py` to your directory and modify it instead. # `TEST_CONFIG` dict is a configuration hook that allows users to # modify the test configurations. The values here should be in sync @@ -159,7 +160,7 @@ def lint(session: nox.sessions.Session) -> None: @nox.session def blacken(session: nox.sessions.Session) -> None: - session.install("black") + session.install(BLACK_VERSION) python_files = [path for path in os.listdir(".") if path.endswith(".py")] session.run("black", *python_files) diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index 5ff9e1db580..6a8ccdae22c 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -28,8 +28,9 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -# Copy `noxfile_config.py` to your directory and modify it instead. +BLACK_VERSION = "black==19.10b0" +# Copy `noxfile_config.py` to your directory and modify it instead. # `TEST_CONFIG` dict is a configuration hook that allows users to # modify the test configurations. The values here should be in sync @@ -159,7 +160,7 @@ def lint(session: nox.sessions.Session) -> None: @nox.session def blacken(session: nox.sessions.Session) -> None: - session.install("black") + session.install(BLACK_VERSION) python_files = [path for path in os.listdir(".") if path.endswith(".py")] session.run("black", *python_files) diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index 5ff9e1db580..6a8ccdae22c 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -28,8 +28,9 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -# Copy `noxfile_config.py` to your directory and modify it instead. +BLACK_VERSION = "black==19.10b0" +# Copy `noxfile_config.py` to your directory and modify it instead. # `TEST_CONFIG` dict is a configuration hook that allows users to # modify the test configurations. The values here should be in sync @@ -159,7 +160,7 @@ def lint(session: nox.sessions.Session) -> None: @nox.session def blacken(session: nox.sessions.Session) -> None: - session.install("black") + session.install(BLACK_VERSION) python_files = [path for path in os.listdir(".") if path.endswith(".py")] session.run("black", *python_files) From ae7c6861207bf303f04f1f04463a63257852c08a Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 22 Jul 2021 16:00:36 +0200 Subject: [PATCH 27/77] chore(deps): update dependency google-cloud-monitoring to v2.4.1 (#187) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [google-cloud-monitoring](https://togithub.com/googleapis/python-monitoring) | `==2.4.0` -> `==2.4.1` | [![age](https://badges.renovateapi.com/packages/pypi/google-cloud-monitoring/2.4.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/google-cloud-monitoring/2.4.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/google-cloud-monitoring/2.4.1/compatibility-slim/2.4.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/google-cloud-monitoring/2.4.1/confidence-slim/2.4.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
googleapis/python-monitoring ### [`v2.4.1`](https://togithub.com/googleapis/python-monitoring/blob/master/CHANGELOG.md#​241-httpswwwgithubcomgoogleapispython-monitoringcomparev240v241-2021-07-20) [Compare Source](https://togithub.com/googleapis/python-monitoring/compare/v2.4.0...v2.4.1)
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/python-monitoring). --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index 812b773c75d..01e2b081169 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.4.0 +google-cloud-monitoring==2.4.1 tabulate==0.8.9 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 1f497d5a4de..543c5c11e51 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.4.0 +google-cloud-monitoring==2.4.1 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index 812b773c75d..01e2b081169 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.4.0 +google-cloud-monitoring==2.4.1 tabulate==0.8.9 From 863d821ff6bf6e974a541c7c2a98a1460048a866 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 22 Jul 2021 16:02:28 +0200 Subject: [PATCH 28/77] chore(deps): update dependency backoff to v1.11.1 (#181) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [backoff](https://togithub.com/litl/backoff) | `==1.11.0` -> `==1.11.1` | [![age](https://badges.renovateapi.com/packages/pypi/backoff/1.11.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/backoff/1.11.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/backoff/1.11.1/compatibility-slim/1.11.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/backoff/1.11.1/confidence-slim/1.11.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
litl/backoff ### [`v1.11.1`](https://togithub.com/litl/backoff/blob/master/CHANGELOG.md#v1111-2021-07-14) [Compare Source](https://togithub.com/litl/backoff/compare/v1.11.0...v1.11.1) ##### Changed - Update **version** in backoff module
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/python-monitoring). --- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- .../snippets/v3/uptime-check-client/requirements-test.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index 305700136f3..2fd84fd1081 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ -backoff==1.11.0 +backoff==1.11.1 pytest==6.2.4 mock==4.0.3 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt index b179d9b00ce..0db5cc446cf 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -1,2 +1,2 @@ -backoff==1.11.0 +backoff==1.11.1 pytest==6.2.4 From 15bc691cf9ed1d8dfe5f2e3a01f8500de8d7603b Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Wed, 28 Jul 2021 16:54:59 +0200 Subject: [PATCH 29/77] chore(deps): update dependency google-cloud-monitoring to v2.4.2 (#193) --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index 01e2b081169..5710bb26b34 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.4.1 +google-cloud-monitoring==2.4.2 tabulate==0.8.9 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 543c5c11e51..39fb037020b 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.4.1 +google-cloud-monitoring==2.4.2 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index 01e2b081169..5710bb26b34 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.4.1 +google-cloud-monitoring==2.4.2 tabulate==0.8.9 From 9ce16cbe5ad3fa978a6a80f4811430fca3ebe48e Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 11 Aug 2021 16:32:39 +0000 Subject: [PATCH 30/77] chore: fix INSTALL_LIBRARY_FROM_SOURCE in noxfile.py (#197) Source-Link: https://github.com/googleapis/synthtool/commit/6252f2cd074c38f37b44abe5e96d128733eb1b61 Post-Processor: gcr.io/repo-automation-bots/owlbot-python:latest@sha256:50e35228649c47b6ca82aa0be3ff9eb2afce51c82b66c4a03fe4afeb5ff6c0fc --- monitoring/snippets/v3/alerts-client/noxfile.py | 2 +- monitoring/snippets/v3/cloud-client/noxfile.py | 2 +- monitoring/snippets/v3/uptime-check-client/noxfile.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index 6a8ccdae22c..125bb619cc4 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -96,7 +96,7 @@ def get_pytest_env_vars() -> Dict[str, str]: TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) -INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False)) +INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ("True", "true") # # Style Checks # diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index 6a8ccdae22c..125bb619cc4 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -96,7 +96,7 @@ def get_pytest_env_vars() -> Dict[str, str]: TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) -INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False)) +INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ("True", "true") # # Style Checks # diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index 6a8ccdae22c..125bb619cc4 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -96,7 +96,7 @@ def get_pytest_env_vars() -> Dict[str, str]: TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) -INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False)) +INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ("True", "true") # # Style Checks # From 712d80d986f788b706d93d79a5674c914b97cc70 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 13 Aug 2021 11:44:58 -0400 Subject: [PATCH 31/77] chore: drop mention of Python 2.7 from templates (#199) Source-Link: https://github.com/googleapis/synthtool/commit/facee4cc1ea096cd8bcc008bb85929daa7c414c0 Post-Processor: gcr.io/repo-automation-bots/owlbot-python:latest@sha256:9743664022bd63a8084be67f144898314c7ca12f0a03e422ac17c733c129d803 Co-authored-by: Owl Bot --- monitoring/snippets/v3/alerts-client/noxfile.py | 6 +++--- monitoring/snippets/v3/cloud-client/noxfile.py | 6 +++--- monitoring/snippets/v3/uptime-check-client/noxfile.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index 125bb619cc4..e73436a1562 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -39,7 +39,7 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - 'ignored_versions': ["2.7"], + 'ignored_versions': [], # Old samples are opted out of enforcing Python type hints # All new samples should feature them @@ -88,8 +88,8 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. -# All versions used to tested samples. -ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"] +# All versions used to test samples. +ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index 125bb619cc4..e73436a1562 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -39,7 +39,7 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - 'ignored_versions': ["2.7"], + 'ignored_versions': [], # Old samples are opted out of enforcing Python type hints # All new samples should feature them @@ -88,8 +88,8 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. -# All versions used to tested samples. -ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"] +# All versions used to test samples. +ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index 125bb619cc4..e73436a1562 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -39,7 +39,7 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - 'ignored_versions': ["2.7"], + 'ignored_versions': [], # Old samples are opted out of enforcing Python type hints # All new samples should feature them @@ -88,8 +88,8 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. -# All versions used to tested samples. -ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"] +# All versions used to test samples. +ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] From 16faf6611e7d98d2007c593c4ccebf26523d2867 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Fri, 27 Aug 2021 10:04:14 -0700 Subject: [PATCH 32/77] docs(samples): include example writing of label data (#202) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit adding label example when writing a timeseries in python Remaking this due to the commit lint failure in #200 and it being easier to just make a new PR. Closing #200. Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [✔️] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-monitoring/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [✔️ for linter, unable to run the nox tests because of issues unrelated] Ensure the tests and linter pass - [✔️] Code coverage does not decrease (if any source code was changed) - [✔️, no doc updates required ] Appropriate docs were updated (if necessary) Fixes #200 🦕 --- monitoring/snippets/v3/cloud-client/snippets.py | 1 + 1 file changed, 1 insertion(+) diff --git a/monitoring/snippets/v3/cloud-client/snippets.py b/monitoring/snippets/v3/cloud-client/snippets.py index 9b47e5da780..41ced1c643b 100644 --- a/monitoring/snippets/v3/cloud-client/snippets.py +++ b/monitoring/snippets/v3/cloud-client/snippets.py @@ -67,6 +67,7 @@ def write_time_series(project_id): series.resource.type = "gce_instance" series.resource.labels["instance_id"] = "1234567890123456789" series.resource.labels["zone"] = "us-central1-f" + series.metric.labels["TestLabel"] = "My Label Data" now = time.time() seconds = int(now) nanos = int((now - seconds) * 10 ** 9) From ce44cbfdbaf041075b8219af682a6af7e146939a Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 31 Aug 2021 16:21:30 +0200 Subject: [PATCH 33/77] chore(deps): update dependency google-cloud-monitoring to v2.5.0 (#210) --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index 5710bb26b34..8eee4bfb5eb 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.4.2 +google-cloud-monitoring==2.5.0 tabulate==0.8.9 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 39fb037020b..98e3db3ac42 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.4.2 +google-cloud-monitoring==2.5.0 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index 5710bb26b34..8eee4bfb5eb 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.4.2 +google-cloud-monitoring==2.5.0 tabulate==0.8.9 From 70325ce9fb1d293a524177abd2be52c1af703960 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 31 Aug 2021 17:09:40 +0200 Subject: [PATCH 34/77] chore(deps): update dependency pytest to v6.2.5 (#208) Co-authored-by: Anthonios Partheniou --- monitoring/snippets/v3/alerts-client/requirements-test.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- .../snippets/v3/uptime-check-client/requirements-test.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements-test.txt b/monitoring/snippets/v3/alerts-client/requirements-test.txt index 58f68136d5f..27f0578cea7 100644 --- a/monitoring/snippets/v3/alerts-client/requirements-test.txt +++ b/monitoring/snippets/v3/alerts-client/requirements-test.txt @@ -1,3 +1,3 @@ -pytest==6.2.4 +pytest==6.2.5 retrying==1.3.3 flaky==3.7.0 diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index 2fd84fd1081..c8884b24251 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ backoff==1.11.1 -pytest==6.2.4 +pytest==6.2.5 mock==4.0.3 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt index 0db5cc446cf..fbe6c1c5cfc 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -1,2 +1,2 @@ backoff==1.11.1 -pytest==6.2.4 +pytest==6.2.5 From 24798b9ffcb29f284096518f6ec4615c2228134d Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 14 Sep 2021 13:37:41 -0700 Subject: [PATCH 35/77] chore(smaples): added imports into snippet (#216) --- .../snippets/v3/cloud-client/snippets.py | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/monitoring/snippets/v3/cloud-client/snippets.py b/monitoring/snippets/v3/cloud-client/snippets.py index 41ced1c643b..aa9eae62331 100644 --- a/monitoring/snippets/v3/cloud-client/snippets.py +++ b/monitoring/snippets/v3/cloud-client/snippets.py @@ -18,16 +18,15 @@ import time import uuid -from google.api import label_pb2 as ga_label -from google.api import metric_pb2 as ga_metric -from google.cloud import monitoring_v3 - - PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"] def create_metric_descriptor(project_id): # [START monitoring_create_metric] + from google.api import label_pb2 as ga_label + from google.api import metric_pb2 as ga_metric + from google.cloud import monitoring_v3 + client = monitoring_v3.MetricServiceClient() project_name = f"projects/{project_id}" descriptor = ga_metric.MetricDescriptor() @@ -51,6 +50,8 @@ def create_metric_descriptor(project_id): def delete_metric_descriptor(descriptor_name): # [START monitoring_delete_metric] + from google.cloud import monitoring_v3 + client = monitoring_v3.MetricServiceClient() client.delete_metric_descriptor(name=descriptor_name) print("Deleted metric descriptor {}.".format(descriptor_name)) @@ -59,6 +60,8 @@ def delete_metric_descriptor(descriptor_name): def write_time_series(project_id): # [START monitoring_write_timeseries] + from google.cloud import monitoring_v3 + client = monitoring_v3.MetricServiceClient() project_name = f"projects/{project_id}" @@ -82,6 +85,8 @@ def write_time_series(project_id): def list_time_series(project_id): # [START monitoring_read_timeseries_simple] + from google.cloud import monitoring_v3 + client = monitoring_v3.MetricServiceClient() project_name = f"projects/{project_id}" interval = monitoring_v3.TimeInterval() @@ -111,6 +116,8 @@ def list_time_series(project_id): def list_time_series_header(project_id): # [START monitoring_read_timeseries_fields] + from google.cloud import monitoring_v3 + client = monitoring_v3.MetricServiceClient() project_name = f"projects/{project_id}" now = time.time() @@ -137,6 +144,8 @@ def list_time_series_header(project_id): def list_time_series_aggregate(project_id): # [START monitoring_read_timeseries_align] + from google.cloud import monitoring_v3 + client = monitoring_v3.MetricServiceClient() project_name = f"projects/{project_id}" @@ -172,6 +181,8 @@ def list_time_series_aggregate(project_id): def list_time_series_reduce(project_id): # [START monitoring_read_timeseries_reduce] + from google.cloud import monitoring_v3 + client = monitoring_v3.MetricServiceClient() project_name = f"projects/{project_id}" @@ -209,6 +220,8 @@ def list_time_series_reduce(project_id): def list_metric_descriptors(project_id): # [START monitoring_list_descriptors] + from google.cloud import monitoring_v3 + client = monitoring_v3.MetricServiceClient() project_name = f"projects/{project_id}" for descriptor in client.list_metric_descriptors(name=project_name): @@ -218,6 +231,8 @@ def list_metric_descriptors(project_id): def list_monitored_resources(project_id): # [START monitoring_list_resources] + from google.cloud import monitoring_v3 + client = monitoring_v3.MetricServiceClient() project_name = f"projects/{project_id}" resource_descriptors = client.list_monitored_resource_descriptors(name=project_name) @@ -228,6 +243,8 @@ def list_monitored_resources(project_id): def get_monitored_resource_descriptor(project_id, resource_type_name): # [START monitoring_get_resource] + from google.cloud import monitoring_v3 + client = monitoring_v3.MetricServiceClient() resource_path = ( f"projects/{project_id}/monitoredResourceDescriptors/{resource_type_name}" @@ -238,6 +255,8 @@ def get_monitored_resource_descriptor(project_id, resource_type_name): def get_metric_descriptor(metric_name): # [START monitoring_get_descriptor] + from google.cloud import monitoring_v3 + client = monitoring_v3.MetricServiceClient() descriptor = client.get_metric_descriptor(name=metric_name) pprint.pprint(descriptor) From bc9ec5c04fde8ee160364f58f2a461363304caff Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 17 Sep 2021 15:36:40 +0000 Subject: [PATCH 36/77] chore: blacken samples noxfile template (#217) --- .../snippets/v3/alerts-client/noxfile.py | 44 +++++++++++-------- .../snippets/v3/cloud-client/noxfile.py | 44 +++++++++++-------- .../v3/uptime-check-client/noxfile.py | 44 +++++++++++-------- 3 files changed, 75 insertions(+), 57 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index e73436a1562..b008613f03f 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -39,17 +39,15 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - 'ignored_versions': [], - + "ignored_versions": [], # Old samples are opted out of enforcing Python type hints # All new samples should feature them - 'enforce_type_hints': False, - + "enforce_type_hints": False, # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string # to use your own Cloud project. - 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', # If you need to use a specific version of pip, # change pip_version_override to the string representation @@ -57,13 +55,13 @@ "pip_version_override": None, # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. - 'envs': {}, + "envs": {}, } try: # Ensure we can import noxfile_config in the project's directory. - sys.path.append('.') + sys.path.append(".") from noxfile_config import TEST_CONFIG_OVERRIDE except ImportError as e: print("No user noxfile_config found: detail: {}".format(e)) @@ -78,12 +76,12 @@ def get_pytest_env_vars() -> Dict[str, str]: ret = {} # Override the GCLOUD_PROJECT and the alias. - env_key = TEST_CONFIG['gcloud_project_env'] + env_key = TEST_CONFIG["gcloud_project_env"] # This should error out if not set. - ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] + ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] # Apply user supplied envs. - ret.update(TEST_CONFIG['envs']) + ret.update(TEST_CONFIG["envs"]) return ret @@ -92,11 +90,14 @@ def get_pytest_env_vars() -> Dict[str, str]: ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. -IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] +IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) -INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ("True", "true") +INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ( + "True", + "true", +) # # Style Checks # @@ -141,7 +142,7 @@ def _determine_local_import_names(start_dir: str) -> List[str]: @nox.session def lint(session: nox.sessions.Session) -> None: - if not TEST_CONFIG['enforce_type_hints']: + if not TEST_CONFIG["enforce_type_hints"]: session.install("flake8", "flake8-import-order") else: session.install("flake8", "flake8-import-order", "flake8-annotations") @@ -150,9 +151,11 @@ def lint(session: nox.sessions.Session) -> None: args = FLAKE8_COMMON_ARGS + [ "--application-import-names", ",".join(local_names), - "." + ".", ] session.run("flake8", *args) + + # # Black # @@ -165,6 +168,7 @@ def blacken(session: nox.sessions.Session) -> None: session.run("black", *python_files) + # # Sample Tests # @@ -173,7 +177,9 @@ def blacken(session: nox.sessions.Session) -> None: PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] -def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: +def _session_tests( + session: nox.sessions.Session, post_install: Callable = None +) -> None: if TEST_CONFIG["pip_version_override"]: pip_version = TEST_CONFIG["pip_version_override"] session.install(f"pip=={pip_version}") @@ -203,7 +209,7 @@ def _session_tests(session: nox.sessions.Session, post_install: Callable = None) # on travis where slow and flaky tests are excluded. # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html success_codes=[0, 5], - env=get_pytest_env_vars() + env=get_pytest_env_vars(), ) @@ -213,9 +219,9 @@ def py(session: nox.sessions.Session) -> None: if session.python in TESTED_VERSIONS: _session_tests(session) else: - session.skip("SKIPPED: {} tests are disabled for this sample.".format( - session.python - )) + session.skip( + "SKIPPED: {} tests are disabled for this sample.".format(session.python) + ) # diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index e73436a1562..b008613f03f 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -39,17 +39,15 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - 'ignored_versions': [], - + "ignored_versions": [], # Old samples are opted out of enforcing Python type hints # All new samples should feature them - 'enforce_type_hints': False, - + "enforce_type_hints": False, # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string # to use your own Cloud project. - 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', # If you need to use a specific version of pip, # change pip_version_override to the string representation @@ -57,13 +55,13 @@ "pip_version_override": None, # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. - 'envs': {}, + "envs": {}, } try: # Ensure we can import noxfile_config in the project's directory. - sys.path.append('.') + sys.path.append(".") from noxfile_config import TEST_CONFIG_OVERRIDE except ImportError as e: print("No user noxfile_config found: detail: {}".format(e)) @@ -78,12 +76,12 @@ def get_pytest_env_vars() -> Dict[str, str]: ret = {} # Override the GCLOUD_PROJECT and the alias. - env_key = TEST_CONFIG['gcloud_project_env'] + env_key = TEST_CONFIG["gcloud_project_env"] # This should error out if not set. - ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] + ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] # Apply user supplied envs. - ret.update(TEST_CONFIG['envs']) + ret.update(TEST_CONFIG["envs"]) return ret @@ -92,11 +90,14 @@ def get_pytest_env_vars() -> Dict[str, str]: ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. -IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] +IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) -INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ("True", "true") +INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ( + "True", + "true", +) # # Style Checks # @@ -141,7 +142,7 @@ def _determine_local_import_names(start_dir: str) -> List[str]: @nox.session def lint(session: nox.sessions.Session) -> None: - if not TEST_CONFIG['enforce_type_hints']: + if not TEST_CONFIG["enforce_type_hints"]: session.install("flake8", "flake8-import-order") else: session.install("flake8", "flake8-import-order", "flake8-annotations") @@ -150,9 +151,11 @@ def lint(session: nox.sessions.Session) -> None: args = FLAKE8_COMMON_ARGS + [ "--application-import-names", ",".join(local_names), - "." + ".", ] session.run("flake8", *args) + + # # Black # @@ -165,6 +168,7 @@ def blacken(session: nox.sessions.Session) -> None: session.run("black", *python_files) + # # Sample Tests # @@ -173,7 +177,9 @@ def blacken(session: nox.sessions.Session) -> None: PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] -def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: +def _session_tests( + session: nox.sessions.Session, post_install: Callable = None +) -> None: if TEST_CONFIG["pip_version_override"]: pip_version = TEST_CONFIG["pip_version_override"] session.install(f"pip=={pip_version}") @@ -203,7 +209,7 @@ def _session_tests(session: nox.sessions.Session, post_install: Callable = None) # on travis where slow and flaky tests are excluded. # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html success_codes=[0, 5], - env=get_pytest_env_vars() + env=get_pytest_env_vars(), ) @@ -213,9 +219,9 @@ def py(session: nox.sessions.Session) -> None: if session.python in TESTED_VERSIONS: _session_tests(session) else: - session.skip("SKIPPED: {} tests are disabled for this sample.".format( - session.python - )) + session.skip( + "SKIPPED: {} tests are disabled for this sample.".format(session.python) + ) # diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index e73436a1562..b008613f03f 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -39,17 +39,15 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - 'ignored_versions': [], - + "ignored_versions": [], # Old samples are opted out of enforcing Python type hints # All new samples should feature them - 'enforce_type_hints': False, - + "enforce_type_hints": False, # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string # to use your own Cloud project. - 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', # If you need to use a specific version of pip, # change pip_version_override to the string representation @@ -57,13 +55,13 @@ "pip_version_override": None, # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. - 'envs': {}, + "envs": {}, } try: # Ensure we can import noxfile_config in the project's directory. - sys.path.append('.') + sys.path.append(".") from noxfile_config import TEST_CONFIG_OVERRIDE except ImportError as e: print("No user noxfile_config found: detail: {}".format(e)) @@ -78,12 +76,12 @@ def get_pytest_env_vars() -> Dict[str, str]: ret = {} # Override the GCLOUD_PROJECT and the alias. - env_key = TEST_CONFIG['gcloud_project_env'] + env_key = TEST_CONFIG["gcloud_project_env"] # This should error out if not set. - ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] + ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] # Apply user supplied envs. - ret.update(TEST_CONFIG['envs']) + ret.update(TEST_CONFIG["envs"]) return ret @@ -92,11 +90,14 @@ def get_pytest_env_vars() -> Dict[str, str]: ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. -IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] +IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) -INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ("True", "true") +INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ( + "True", + "true", +) # # Style Checks # @@ -141,7 +142,7 @@ def _determine_local_import_names(start_dir: str) -> List[str]: @nox.session def lint(session: nox.sessions.Session) -> None: - if not TEST_CONFIG['enforce_type_hints']: + if not TEST_CONFIG["enforce_type_hints"]: session.install("flake8", "flake8-import-order") else: session.install("flake8", "flake8-import-order", "flake8-annotations") @@ -150,9 +151,11 @@ def lint(session: nox.sessions.Session) -> None: args = FLAKE8_COMMON_ARGS + [ "--application-import-names", ",".join(local_names), - "." + ".", ] session.run("flake8", *args) + + # # Black # @@ -165,6 +168,7 @@ def blacken(session: nox.sessions.Session) -> None: session.run("black", *python_files) + # # Sample Tests # @@ -173,7 +177,9 @@ def blacken(session: nox.sessions.Session) -> None: PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] -def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: +def _session_tests( + session: nox.sessions.Session, post_install: Callable = None +) -> None: if TEST_CONFIG["pip_version_override"]: pip_version = TEST_CONFIG["pip_version_override"] session.install(f"pip=={pip_version}") @@ -203,7 +209,7 @@ def _session_tests(session: nox.sessions.Session, post_install: Callable = None) # on travis where slow and flaky tests are excluded. # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html success_codes=[0, 5], - env=get_pytest_env_vars() + env=get_pytest_env_vars(), ) @@ -213,9 +219,9 @@ def py(session: nox.sessions.Session) -> None: if session.python in TESTED_VERSIONS: _session_tests(session) else: - session.skip("SKIPPED: {} tests are disabled for this sample.".format( - session.python - )) + session.skip( + "SKIPPED: {} tests are disabled for this sample.".format(session.python) + ) # From ed5abafd7872ff543c931b80e063cbd5ceadab65 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 27 Sep 2021 19:51:47 +0200 Subject: [PATCH 37/77] chore(deps): update dependency google-cloud-monitoring to v2.5.1 (#223) --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index 8eee4bfb5eb..d1445c0bc75 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.5.0 +google-cloud-monitoring==2.5.1 tabulate==0.8.9 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 98e3db3ac42..c6843f589b0 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.5.0 +google-cloud-monitoring==2.5.1 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index 8eee4bfb5eb..d1445c0bc75 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.5.0 +google-cloud-monitoring==2.5.1 tabulate==0.8.9 From fb5f8106396a47562b76f190f7b285ab922e0515 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 30 Sep 2021 15:44:19 +0000 Subject: [PATCH 38/77] chore: fail samples nox session if python version is missing (#226) --- monitoring/snippets/v3/alerts-client/noxfile.py | 4 ++++ monitoring/snippets/v3/cloud-client/noxfile.py | 4 ++++ monitoring/snippets/v3/uptime-check-client/noxfile.py | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index b008613f03f..1fd8956fbf0 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -98,6 +98,10 @@ def get_pytest_env_vars() -> Dict[str, str]: "True", "true", ) + +# Error if a python version is missing +nox.options.error_on_missing_interpreters = True + # # Style Checks # diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index b008613f03f..1fd8956fbf0 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -98,6 +98,10 @@ def get_pytest_env_vars() -> Dict[str, str]: "True", "true", ) + +# Error if a python version is missing +nox.options.error_on_missing_interpreters = True + # # Style Checks # diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index b008613f03f..1fd8956fbf0 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -98,6 +98,10 @@ def get_pytest_env_vars() -> Dict[str, str]: "True", "true", ) + +# Error if a python version is missing +nox.options.error_on_missing_interpreters = True + # # Style Checks # From 313f3e2d6ec8b6c8d5f497ad72691ad71c4a556e Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 7 Oct 2021 14:13:52 +0200 Subject: [PATCH 39/77] chore(deps): update dependency google-cloud-monitoring to v2.6.0 (#232) --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index d1445c0bc75..898dfbe1623 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.5.1 +google-cloud-monitoring==2.6.0 tabulate==0.8.9 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index c6843f589b0..2c0b4af96e1 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.5.1 +google-cloud-monitoring==2.6.0 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index d1445c0bc75..898dfbe1623 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.5.1 +google-cloud-monitoring==2.6.0 tabulate==0.8.9 From 54d2e47e1a46026f0400fda2a169a8c4a7fed1e3 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Sat, 9 Oct 2021 10:54:09 -0400 Subject: [PATCH 40/77] chore(python): Add kokoro configs for python 3.10 samples testing (#237) Source-Link: https://github.com/googleapis/synthtool/commit/c6e69c4726a233ad8d496961ec265d29e54010b7 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:58f73ba196b5414782605236dd0712a73541b44ff2ff4d3a36ec41092dd6fa5b Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- monitoring/snippets/v3/alerts-client/noxfile.py | 2 +- monitoring/snippets/v3/cloud-client/noxfile.py | 2 +- monitoring/snippets/v3/uptime-check-client/noxfile.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index 1fd8956fbf0..93a9122cc45 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -87,7 +87,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to test samples. -ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] +ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index 1fd8956fbf0..93a9122cc45 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -87,7 +87,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to test samples. -ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] +ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index 1fd8956fbf0..93a9122cc45 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -87,7 +87,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to test samples. -ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] +ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] From 1a0b4fcc98d2ce2f79e786439acfdf30c686f5aa Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 11 Nov 2021 02:09:08 +0100 Subject: [PATCH 41/77] chore(deps): update dependency google-cloud-monitoring to v2.7.0 (#249) Co-authored-by: Anthonios Partheniou --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index 898dfbe1623..35eb18e6f8d 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.6.0 +google-cloud-monitoring==2.7.0 tabulate==0.8.9 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 2c0b4af96e1..525fc00aaad 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.6.0 +google-cloud-monitoring==2.7.0 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index 898dfbe1623..35eb18e6f8d 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.6.0 +google-cloud-monitoring==2.7.0 tabulate==0.8.9 From dfaa9740d664d458a6e68314dadc0e228aeea1c0 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Sat, 20 Nov 2021 01:11:29 +0100 Subject: [PATCH 42/77] chore(deps): update dependency google-cloud-monitoring to v2.8.0 (#255) Co-authored-by: Anthonios Partheniou --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index 35eb18e6f8d..b0c91d20913 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.7.0 +google-cloud-monitoring==2.8.0 tabulate==0.8.9 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 525fc00aaad..1b5777875af 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.7.0 +google-cloud-monitoring==2.8.0 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index 35eb18e6f8d..b0c91d20913 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.7.0 +google-cloud-monitoring==2.8.0 tabulate==0.8.9 From c51e992c93902d57a7f2dad73dd256cef6ee413d Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 21 Dec 2021 11:19:23 -0500 Subject: [PATCH 43/77] chore: update python-docs-samples link to main branch (#256) Source-Link: https://github.com/googleapis/synthtool/commit/0941ef32b18aff0be34a40404f3971d9f51996e9 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:2f90537dd7df70f6b663cd654b1fa5dee483cf6a4edcfd46072b2775be8a23ec Co-authored-by: Owl Bot --- monitoring/AUTHORING_GUIDE.md | 2 +- monitoring/CONTRIBUTING.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/monitoring/AUTHORING_GUIDE.md b/monitoring/AUTHORING_GUIDE.md index 55c97b32f4c..8249522ffc2 100644 --- a/monitoring/AUTHORING_GUIDE.md +++ b/monitoring/AUTHORING_GUIDE.md @@ -1 +1 @@ -See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md \ No newline at end of file +See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md \ No newline at end of file diff --git a/monitoring/CONTRIBUTING.md b/monitoring/CONTRIBUTING.md index 34c882b6f1a..f5fe2e6baf1 100644 --- a/monitoring/CONTRIBUTING.md +++ b/monitoring/CONTRIBUTING.md @@ -1 +1 @@ -See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/CONTRIBUTING.md \ No newline at end of file +See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/CONTRIBUTING.md \ No newline at end of file From 8dd24a5eabe9f4a2f3cc4804059a71036f0ad54e Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 11 Jan 2022 07:43:06 -0500 Subject: [PATCH 44/77] chore(samples): Add check for tests in directory (#263) Source-Link: https://github.com/googleapis/synthtool/commit/52aef91f8d25223d9dbdb4aebd94ba8eea2101f3 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:36a95b8f494e4674dc9eee9af98961293b51b86b3649942aac800ae6c1f796d4 Co-authored-by: Owl Bot --- .../snippets/v3/alerts-client/noxfile.py | 70 +++++++++++-------- .../snippets/v3/cloud-client/noxfile.py | 70 +++++++++++-------- .../v3/uptime-check-client/noxfile.py | 70 +++++++++++-------- 3 files changed, 117 insertions(+), 93 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index 93a9122cc45..3bbef5d54f4 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -14,6 +14,7 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys @@ -184,37 +185,44 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + if len(test_list) == 0: + print("No tests found, skipping directory.") + else: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index 93a9122cc45..3bbef5d54f4 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -14,6 +14,7 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys @@ -184,37 +185,44 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + if len(test_list) == 0: + print("No tests found, skipping directory.") + else: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index 93a9122cc45..3bbef5d54f4 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -14,6 +14,7 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys @@ -184,37 +185,44 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + if len(test_list) == 0: + print("No tests found, skipping directory.") + else: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) From 65961902a5c55c0b1122232060214e0da4bd1c4b Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 18 Jan 2022 20:29:12 -0500 Subject: [PATCH 45/77] chore(python): Noxfile recognizes that tests can live in a folder (#267) Source-Link: https://github.com/googleapis/synthtool/commit/4760d8dce1351d93658cb11d02a1b7ceb23ae5d7 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f0e4b51deef56bed74d3e2359c583fc104a8d6367da3984fc5c66938db738828 Co-authored-by: Owl Bot --- monitoring/snippets/v3/alerts-client/noxfile.py | 1 + monitoring/snippets/v3/cloud-client/noxfile.py | 1 + monitoring/snippets/v3/uptime-check-client/noxfile.py | 1 + 3 files changed, 3 insertions(+) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index 3bbef5d54f4..20cdfc62013 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -187,6 +187,7 @@ def _session_tests( ) -> None: # check for presence of tests test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + test_list.extend(glob.glob("tests")) if len(test_list) == 0: print("No tests found, skipping directory.") else: diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index 3bbef5d54f4..20cdfc62013 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -187,6 +187,7 @@ def _session_tests( ) -> None: # check for presence of tests test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + test_list.extend(glob.glob("tests")) if len(test_list) == 0: print("No tests found, skipping directory.") else: diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index 3bbef5d54f4..20cdfc62013 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -187,6 +187,7 @@ def _session_tests( ) -> None: # check for presence of tests test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + test_list.extend(glob.glob("tests")) if len(test_list) == 0: print("No tests found, skipping directory.") else: From 61d0015b92620ce2a427665272a72d3900d2bb43 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Sat, 26 Feb 2022 01:36:23 +0100 Subject: [PATCH 46/77] chore(deps): update dependency pytest to v7 (#275) --- monitoring/snippets/v3/alerts-client/requirements-test.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- .../snippets/v3/uptime-check-client/requirements-test.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements-test.txt b/monitoring/snippets/v3/alerts-client/requirements-test.txt index 27f0578cea7..846d03f1ed4 100644 --- a/monitoring/snippets/v3/alerts-client/requirements-test.txt +++ b/monitoring/snippets/v3/alerts-client/requirements-test.txt @@ -1,3 +1,3 @@ -pytest==6.2.5 +pytest==7.0.1 retrying==1.3.3 flaky==3.7.0 diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index c8884b24251..f56065a9c13 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ backoff==1.11.1 -pytest==6.2.5 +pytest==7.0.1 mock==4.0.3 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt index fbe6c1c5cfc..c531e813e29 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -1,2 +1,2 @@ backoff==1.11.1 -pytest==6.2.5 +pytest==7.0.1 From f1c617e7531f1a4bf8438ad35c9c8842377676cf Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 1 Mar 2022 12:19:48 +0100 Subject: [PATCH 47/77] chore(deps): update all dependencies (#279) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(deps): update all dependencies * 🦉 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 --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index b0c91d20913..768fbcfd29c 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.8.0 +google-cloud-monitoring==2.9.0 tabulate==0.8.9 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 1b5777875af..9f67a9017bd 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.8.0 +google-cloud-monitoring==2.9.0 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index b0c91d20913..768fbcfd29c 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.8.0 +google-cloud-monitoring==2.9.0 tabulate==0.8.9 From aead93ccf1be72de4d520b88ac5f3f603f3f4f69 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 4 Mar 2022 12:46:50 -0500 Subject: [PATCH 48/77] chore: Adding support for pytest-xdist and pytest-parallel (#287) Source-Link: https://github.com/googleapis/synthtool/commit/82f5cb283efffe96e1b6cd634738e0e7de2cd90a Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:5d8da01438ece4021d135433f2cf3227aa39ef0eaccc941d62aa35e6902832ae Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- .../snippets/v3/alerts-client/noxfile.py | 80 +++++++++++-------- .../snippets/v3/cloud-client/noxfile.py | 80 +++++++++++-------- .../v3/uptime-check-client/noxfile.py | 80 +++++++++++-------- 3 files changed, 138 insertions(+), 102 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index 20cdfc62013..4c808af73ea 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -188,42 +188,54 @@ def _session_tests( # check for presence of tests test_list = glob.glob("*_test.py") + glob.glob("test_*.py") test_list.extend(glob.glob("tests")) + if len(test_list) == 0: print("No tests found, skipping directory.") - else: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install( - "-r", "requirements-test.txt", "-c", "constraints-test.txt" - ) - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + return + + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + concurrent_args = [] + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + with open("requirements.txt") as rfile: + packages = rfile.read() + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + with open("requirements-test.txt") as rtfile: + packages += rtfile.read() + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + if "pytest-parallel" in packages: + concurrent_args.extend(['--workers', 'auto', '--tests-per-worker', 'auto']) + elif "pytest-xdist" in packages: + concurrent_args.extend(['-n', 'auto']) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs + concurrent_args), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index 20cdfc62013..4c808af73ea 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -188,42 +188,54 @@ def _session_tests( # check for presence of tests test_list = glob.glob("*_test.py") + glob.glob("test_*.py") test_list.extend(glob.glob("tests")) + if len(test_list) == 0: print("No tests found, skipping directory.") - else: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install( - "-r", "requirements-test.txt", "-c", "constraints-test.txt" - ) - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + return + + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + concurrent_args = [] + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + with open("requirements.txt") as rfile: + packages = rfile.read() + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + with open("requirements-test.txt") as rtfile: + packages += rtfile.read() + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + if "pytest-parallel" in packages: + concurrent_args.extend(['--workers', 'auto', '--tests-per-worker', 'auto']) + elif "pytest-xdist" in packages: + concurrent_args.extend(['-n', 'auto']) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs + concurrent_args), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index 20cdfc62013..4c808af73ea 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -188,42 +188,54 @@ def _session_tests( # check for presence of tests test_list = glob.glob("*_test.py") + glob.glob("test_*.py") test_list.extend(glob.glob("tests")) + if len(test_list) == 0: print("No tests found, skipping directory.") - else: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install( - "-r", "requirements-test.txt", "-c", "constraints-test.txt" - ) - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + return + + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + concurrent_args = [] + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + with open("requirements.txt") as rfile: + packages = rfile.read() + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + with open("requirements-test.txt") as rtfile: + packages += rtfile.read() + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + if "pytest-parallel" in packages: + concurrent_args.extend(['--workers', 'auto', '--tests-per-worker', 'auto']) + elif "pytest-xdist" in packages: + concurrent_args.extend(['-n', 'auto']) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs + concurrent_args), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) From c8f20edf376d777c2f4bcca6923f7daecd389031 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 8 Mar 2022 02:48:25 +0100 Subject: [PATCH 49/77] chore(deps): update dependency google-cloud-monitoring to v2.9.1 (#290) --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index 768fbcfd29c..1bd61207ccb 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.9.0 +google-cloud-monitoring==2.9.1 tabulate==0.8.9 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 9f67a9017bd..cae18eaa5fc 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.9.0 +google-cloud-monitoring==2.9.1 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index 768fbcfd29c..1bd61207ccb 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.9.0 +google-cloud-monitoring==2.9.1 tabulate==0.8.9 From 5697207b7acabc12c6fd04a49e7e308ad3dbf239 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Sun, 13 Mar 2022 23:38:52 +0100 Subject: [PATCH 50/77] chore(deps): update dependency pytest to v7.1.0 (#292) --- monitoring/snippets/v3/alerts-client/requirements-test.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- .../snippets/v3/uptime-check-client/requirements-test.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements-test.txt b/monitoring/snippets/v3/alerts-client/requirements-test.txt index 846d03f1ed4..15e01dac6b1 100644 --- a/monitoring/snippets/v3/alerts-client/requirements-test.txt +++ b/monitoring/snippets/v3/alerts-client/requirements-test.txt @@ -1,3 +1,3 @@ -pytest==7.0.1 +pytest==7.1.0 retrying==1.3.3 flaky==3.7.0 diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index f56065a9c13..6725122dbe2 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ backoff==1.11.1 -pytest==7.0.1 +pytest==7.1.0 mock==4.0.3 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt index c531e813e29..c265ab7091f 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -1,2 +1,2 @@ backoff==1.11.1 -pytest==7.0.1 +pytest==7.1.0 From 7a23543b037b4c81110928e05190ac6f8d47b899 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Sat, 19 Mar 2022 12:03:15 +0100 Subject: [PATCH 51/77] chore(deps): update dependency pytest to v7.1.1 (#293) --- monitoring/snippets/v3/alerts-client/requirements-test.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- .../snippets/v3/uptime-check-client/requirements-test.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements-test.txt b/monitoring/snippets/v3/alerts-client/requirements-test.txt index 15e01dac6b1..b442611dfc4 100644 --- a/monitoring/snippets/v3/alerts-client/requirements-test.txt +++ b/monitoring/snippets/v3/alerts-client/requirements-test.txt @@ -1,3 +1,3 @@ -pytest==7.1.0 +pytest==7.1.1 retrying==1.3.3 flaky==3.7.0 diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index 6725122dbe2..2f4eefb6d04 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ backoff==1.11.1 -pytest==7.1.0 +pytest==7.1.1 mock==4.0.3 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt index c265ab7091f..678dbc8efd1 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -1,2 +1,2 @@ backoff==1.11.1 -pytest==7.1.0 +pytest==7.1.1 From aaf9c0a6e3966accbdc04701c98ef99b192ad41e Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 28 Mar 2022 19:52:51 -0400 Subject: [PATCH 52/77] chore(python): use black==22.3.0 (#299) Source-Link: https://github.com/googleapis/synthtool/commit/6fab84af09f2cf89a031fd8671d1def6b2931b11 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:7cffbc10910c3ab1b852c05114a08d374c195a81cdec1d4a67a1d129331d0bfe Co-authored-by: Owl Bot --- monitoring/snippets/v3/alerts-client/noxfile.py | 2 +- monitoring/snippets/v3/cloud-client/noxfile.py | 2 +- monitoring/snippets/v3/uptime-check-client/noxfile.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index 4c808af73ea..949e0fde9ae 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -29,7 +29,7 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -BLACK_VERSION = "black==19.10b0" +BLACK_VERSION = "black==22.3.0" # Copy `noxfile_config.py` to your directory and modify it instead. diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index 4c808af73ea..949e0fde9ae 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -29,7 +29,7 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -BLACK_VERSION = "black==19.10b0" +BLACK_VERSION = "black==22.3.0" # Copy `noxfile_config.py` to your directory and modify it instead. diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index 4c808af73ea..949e0fde9ae 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -29,7 +29,7 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -BLACK_VERSION = "black==19.10b0" +BLACK_VERSION = "black==22.3.0" # Copy `noxfile_config.py` to your directory and modify it instead. From 77f07479051791e2ea96a06c5db33f31daa04827 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 20 Apr 2022 20:31:41 -0400 Subject: [PATCH 53/77] chore(python): add nox session to sort python imports (#311) Source-Link: https://github.com/googleapis/synthtool/commit/1b71c10e20de7ed3f97f692f99a0e3399b67049f Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:00c9d764fd1cd56265f12a5ef4b99a0c9e87cf261018099141e2ca5158890416 Co-authored-by: Owl Bot --- .../snippets/v3/alerts-client/noxfile.py | 21 +++++++++++++++++++ .../snippets/v3/cloud-client/noxfile.py | 21 +++++++++++++++++++ .../v3/uptime-check-client/noxfile.py | 21 +++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index 949e0fde9ae..38bb0a572b8 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -30,6 +30,7 @@ # WARNING - WARNING - WARNING - WARNING - WARNING BLACK_VERSION = "black==22.3.0" +ISORT_VERSION = "isort==5.10.1" # Copy `noxfile_config.py` to your directory and modify it instead. @@ -168,12 +169,32 @@ def lint(session: nox.sessions.Session) -> None: @nox.session def blacken(session: nox.sessions.Session) -> None: + """Run black. Format code to uniform standard.""" session.install(BLACK_VERSION) python_files = [path for path in os.listdir(".") if path.endswith(".py")] session.run("black", *python_files) +# +# format = isort + black +# + +@nox.session +def format(session: nox.sessions.Session) -> None: + """ + Run isort to sort imports. Then run black + to format code to uniform standard. + """ + session.install(BLACK_VERSION, ISORT_VERSION) + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + # Use the --fss option to sort imports using strict alphabetical order. + # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + session.run("isort", "--fss", *python_files) + session.run("black", *python_files) + + # # Sample Tests # diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index 949e0fde9ae..38bb0a572b8 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -30,6 +30,7 @@ # WARNING - WARNING - WARNING - WARNING - WARNING BLACK_VERSION = "black==22.3.0" +ISORT_VERSION = "isort==5.10.1" # Copy `noxfile_config.py` to your directory and modify it instead. @@ -168,12 +169,32 @@ def lint(session: nox.sessions.Session) -> None: @nox.session def blacken(session: nox.sessions.Session) -> None: + """Run black. Format code to uniform standard.""" session.install(BLACK_VERSION) python_files = [path for path in os.listdir(".") if path.endswith(".py")] session.run("black", *python_files) +# +# format = isort + black +# + +@nox.session +def format(session: nox.sessions.Session) -> None: + """ + Run isort to sort imports. Then run black + to format code to uniform standard. + """ + session.install(BLACK_VERSION, ISORT_VERSION) + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + # Use the --fss option to sort imports using strict alphabetical order. + # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + session.run("isort", "--fss", *python_files) + session.run("black", *python_files) + + # # Sample Tests # diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index 949e0fde9ae..38bb0a572b8 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -30,6 +30,7 @@ # WARNING - WARNING - WARNING - WARNING - WARNING BLACK_VERSION = "black==22.3.0" +ISORT_VERSION = "isort==5.10.1" # Copy `noxfile_config.py` to your directory and modify it instead. @@ -168,12 +169,32 @@ def lint(session: nox.sessions.Session) -> None: @nox.session def blacken(session: nox.sessions.Session) -> None: + """Run black. Format code to uniform standard.""" session.install(BLACK_VERSION) python_files = [path for path in os.listdir(".") if path.endswith(".py")] session.run("black", *python_files) +# +# format = isort + black +# + +@nox.session +def format(session: nox.sessions.Session) -> None: + """ + Run isort to sort imports. Then run black + to format code to uniform standard. + """ + session.install(BLACK_VERSION, ISORT_VERSION) + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + # Use the --fss option to sort imports using strict alphabetical order. + # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + session.run("isort", "--fss", *python_files) + session.run("black", *python_files) + + # # Sample Tests # From 1d9a44a437ff5f012ff45c152e27517b80c60ace Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 25 Apr 2022 17:06:04 +0200 Subject: [PATCH 54/77] chore(deps): update dependency pytest to v7.1.2 (#314) --- monitoring/snippets/v3/alerts-client/requirements-test.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- .../snippets/v3/uptime-check-client/requirements-test.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements-test.txt b/monitoring/snippets/v3/alerts-client/requirements-test.txt index b442611dfc4..6e5ec1ea09e 100644 --- a/monitoring/snippets/v3/alerts-client/requirements-test.txt +++ b/monitoring/snippets/v3/alerts-client/requirements-test.txt @@ -1,3 +1,3 @@ -pytest==7.1.1 +pytest==7.1.2 retrying==1.3.3 flaky==3.7.0 diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index 2f4eefb6d04..f4a6f912e27 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ backoff==1.11.1 -pytest==7.1.1 +pytest==7.1.2 mock==4.0.3 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt index 678dbc8efd1..e29e011b390 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -1,2 +1,2 @@ backoff==1.11.1 -pytest==7.1.1 +pytest==7.1.2 From 47d4d7cef6cb7ea37829cbc2a4becf30eceecbb2 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 26 Apr 2022 20:06:49 +0200 Subject: [PATCH 55/77] chore(deps): update dependency backoff to v2 (#315) --- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- .../snippets/v3/uptime-check-client/requirements-test.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index f4a6f912e27..9479922a296 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ -backoff==1.11.1 +backoff==2.0.0 pytest==7.1.2 mock==4.0.3 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt index e29e011b390..81c3a60c109 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -1,2 +1,2 @@ -backoff==1.11.1 +backoff==2.0.0 pytest==7.1.2 From e3fdebcc82de48cce0800f2900af1e91ee82a199 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Wed, 27 Apr 2022 18:10:50 +0200 Subject: [PATCH 56/77] chore(deps): update dependency backoff to v2.0.1 (#317) --- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- .../snippets/v3/uptime-check-client/requirements-test.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index 9479922a296..9f9812ba3e7 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ -backoff==2.0.0 +backoff==2.0.1 pytest==7.1.2 mock==4.0.3 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt index 81c3a60c109..4d92cc9aa9d 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -1,2 +1,2 @@ -backoff==2.0.0 +backoff==2.0.1 pytest==7.1.2 From b2761462f2c7635a29f255b8cc3c433d3a6a63bf Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 6 Jul 2022 13:33:38 -0400 Subject: [PATCH 57/77] fix: require python 3.7+ (#459) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(python): drop python 3.6 Source-Link: https://github.com/googleapis/synthtool/commit/4f89b13af10d086458f9b379e56a614f9d6dab7b Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:e7bb19d47c13839fe8c147e50e02e8b6cf5da8edd1af8b82208cd6f66cc2829c * add api_description to .repo-metadata.json * require python 3.7+ in setup.py * remove python 3.6 sample configs * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * trigger ci Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- monitoring/snippets/v3/alerts-client/noxfile.py | 2 +- monitoring/snippets/v3/cloud-client/noxfile.py | 2 +- monitoring/snippets/v3/uptime-check-client/noxfile.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index 38bb0a572b8..5fcb9d7461f 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -89,7 +89,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to test samples. -ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"] +ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index 38bb0a572b8..5fcb9d7461f 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -89,7 +89,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to test samples. -ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"] +ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index 38bb0a572b8..5fcb9d7461f 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -89,7 +89,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to test samples. -ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"] +ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] From b091ad6041f0dae78bd717ce1747803f2a69bbed Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 7 Jul 2022 16:09:39 +0200 Subject: [PATCH 58/77] chore(deps): update all dependencies (#445) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(deps): update all dependencies * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- .../snippets/v3/uptime-check-client/requirements-test.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index 9f9812ba3e7..1518b7cbf24 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ -backoff==2.0.1 +backoff==2.1.2 pytest==7.1.2 mock==4.0.3 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt index 4d92cc9aa9d..ce161d15f1a 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -1,2 +1,2 @@ -backoff==2.0.1 +backoff==2.1.2 pytest==7.1.2 From 8e830db00ea14874e17ee1bc1e10c38f861806e1 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 2 Aug 2022 14:46:24 +0200 Subject: [PATCH 59/77] chore(deps): update all dependencies (#467) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(deps): update all dependencies * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- monitoring/snippets/v3/alerts-client/requirements.txt | 4 ++-- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index 1bd61207ccb..d0d171a3265 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.9.1 -tabulate==0.8.9 +google-cloud-monitoring==2.10.1 +tabulate==0.8.10 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index cae18eaa5fc..e1da0e7253f 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.9.1 +google-cloud-monitoring==2.10.1 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index 1bd61207ccb..d0d171a3265 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.9.1 -tabulate==0.8.9 +google-cloud-monitoring==2.10.1 +tabulate==0.8.10 From 7b61ee10513110a13efc520780c6d0a1b3867121 Mon Sep 17 00:00:00 2001 From: Shabir Mohamed Abdul Samadh <7249208+Shabirmean@users.noreply.github.com> Date: Fri, 5 Aug 2022 21:59:29 -0400 Subject: [PATCH 60/77] docs(samples): add docstrings to explain the project ID format (#469) * improvement: add doc strings to explain the project ID format * fix: argument desc mismatch Co-authored-by: Anthonios Partheniou --- .../snippets/v3/alerts-client/snippets.py | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/monitoring/snippets/v3/alerts-client/snippets.py b/monitoring/snippets/v3/alerts-client/snippets.py index d34e039095a..aeaa45a1cab 100644 --- a/monitoring/snippets/v3/alerts-client/snippets.py +++ b/monitoring/snippets/v3/alerts-client/snippets.py @@ -27,6 +27,13 @@ # [START monitoring_alert_list_policies] def list_alert_policies(project_name): + """List alert policies in a project. + + Arguments: + project_name (str): The Google Cloud Project to use. The project name + must be in the format - 'projects/'. + """ + client = monitoring_v3.AlertPolicyServiceClient() policies = client.list_alert_policies(name=project_name) print( @@ -44,6 +51,13 @@ def list_alert_policies(project_name): # [START monitoring_alert_list_channels] def list_notification_channels(project_name): + """List alert notification channels in a project. + + Arguments: + project_name (str): The Google Cloud Project to use. The project name + must be in the format - 'projects/'. + """ + client = monitoring_v3.NotificationChannelServiceClient() channels = client.list_notification_channels(name=project_name) print( @@ -62,7 +76,8 @@ def enable_alert_policies(project_name, enable, filter_=None): """Enable or disable alert policies in a project. Arguments: - project_name (str) + project_name (str): The Google Cloud Project to use. The project name + must be in the format - 'projects/'. enable (bool): Enable or disable the policies. filter_ (str, optional): Only enable/disable alert policies that match this filter_. See @@ -95,6 +110,17 @@ def enable_alert_policies(project_name, enable, filter_=None): # [START monitoring_alert_replace_channels] def replace_notification_channels(project_name, alert_policy_id, channel_ids): + """Replace notification channel of an alert. + + Arguments: + project_name (str): The Google Cloud Project to use. The project name + must be in the format - 'projects/'. + alert_policy_id (str): The ID of the alert policy whose notification + channels are to be replaced. + channel_ids (str): ID of notification channel to be added as channel + for the given alert policy. + """ + _, project_id = project_name.split("/") alert_client = monitoring_v3.AlertPolicyServiceClient() channel_client = monitoring_v3.NotificationChannelServiceClient() @@ -119,6 +145,17 @@ def replace_notification_channels(project_name, alert_policy_id, channel_ids): # [START monitoring_alert_delete_channel] def delete_notification_channels(project_name, channel_ids, force=None): + """Delete alert notification channels. + + Arguments: + project_name (str): The Google Cloud Project to use. The project name + must be in the format - 'projects/'. + channel_ids list(str): List of IDs of notification channels to delete. + force (bool): If true, the notification channels are deleted regardless + of its in use by alert policies. If false, channels that are still + referenced by an existing alerting policy will fail to be deleted. + """ + channel_client = monitoring_v3.NotificationChannelServiceClient() for channel_id in channel_ids: channel_name = "{}/notificationChannels/{}".format(project_name, channel_id) @@ -136,6 +173,15 @@ def delete_notification_channels(project_name, channel_ids, force=None): # [START monitoring_alert_backup_policies] def backup(project_name, backup_filename): + """Backup alert policies from a project to a local file. + + Arguments: + project_name (str): The Google Cloud Project to use. The project name + must be in the format - 'projects/' + backup_filename (str): Name of the file (along with its path) to which + the alert policies will be written as backup. + """ + alert_client = monitoring_v3.AlertPolicyServiceClient() channel_client = monitoring_v3.NotificationChannelServiceClient() record = { From af9175e8dea2d8b33c55d9198c65b005ce6a6694 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 9 Aug 2022 02:55:09 +0200 Subject: [PATCH 61/77] chore(deps): update all dependencies (#473) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(deps): update all dependencies * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index d0d171a3265..12be7c0c219 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.10.1 +google-cloud-monitoring==2.11.0 tabulate==0.8.10 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index e1da0e7253f..55400380f83 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.10.1 +google-cloud-monitoring==2.11.0 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index d0d171a3265..12be7c0c219 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.10.1 +google-cloud-monitoring==2.11.0 tabulate==0.8.10 From e2c4cec9a8fe324a2960a313ff69f75fdc0c80e0 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 16 Aug 2022 18:39:44 +0200 Subject: [PATCH 62/77] chore(deps): update dependency google-cloud-monitoring to v2.11.1 (#479) --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index 12be7c0c219..f0b2ede75ce 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.11.0 +google-cloud-monitoring==2.11.1 tabulate==0.8.10 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 55400380f83..78083b0ff77 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.11.0 +google-cloud-monitoring==2.11.1 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index 12be7c0c219..f0b2ede75ce 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.11.0 +google-cloud-monitoring==2.11.1 tabulate==0.8.10 From c40b913d5413edbff08dfef574bb92d799ed4bec Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 6 Sep 2022 17:47:15 +0200 Subject: [PATCH 63/77] chore(deps): update dependency pytest to v7.1.3 (#489) --- monitoring/snippets/v3/alerts-client/requirements-test.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- .../snippets/v3/uptime-check-client/requirements-test.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements-test.txt b/monitoring/snippets/v3/alerts-client/requirements-test.txt index 6e5ec1ea09e..8a77da2aa57 100644 --- a/monitoring/snippets/v3/alerts-client/requirements-test.txt +++ b/monitoring/snippets/v3/alerts-client/requirements-test.txt @@ -1,3 +1,3 @@ -pytest==7.1.2 +pytest==7.1.3 retrying==1.3.3 flaky==3.7.0 diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index 1518b7cbf24..987cc10d37b 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ backoff==2.1.2 -pytest==7.1.2 +pytest==7.1.3 mock==4.0.3 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt index ce161d15f1a..6759e75e03a 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -1,2 +1,2 @@ backoff==2.1.2 -pytest==7.1.2 +pytest==7.1.3 From 84924707fa46e6370728475d4d269789e3ff9552 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 13 Sep 2022 16:18:34 +0000 Subject: [PATCH 64/77] chore: detect samples tests in nested directories (#494) Source-Link: https://github.com/googleapis/synthtool/commit/50db768f450a50d7c1fd62513c113c9bb96fd434 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:e09366bdf0fd9c8976592988390b24d53583dd9f002d476934da43725adbb978 --- monitoring/snippets/v3/alerts-client/noxfile.py | 4 ++-- monitoring/snippets/v3/cloud-client/noxfile.py | 4 ++-- monitoring/snippets/v3/uptime-check-client/noxfile.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py index 5fcb9d7461f..0398d72ff69 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ b/monitoring/snippets/v3/alerts-client/noxfile.py @@ -207,8 +207,8 @@ def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: # check for presence of tests - test_list = glob.glob("*_test.py") + glob.glob("test_*.py") - test_list.extend(glob.glob("tests")) + test_list = glob.glob("**/*_test.py", recursive=True) + glob.glob("**/test_*.py", recursive=True) + test_list.extend(glob.glob("**/tests", recursive=True)) if len(test_list) == 0: print("No tests found, skipping directory.") diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py index 5fcb9d7461f..0398d72ff69 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ b/monitoring/snippets/v3/cloud-client/noxfile.py @@ -207,8 +207,8 @@ def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: # check for presence of tests - test_list = glob.glob("*_test.py") + glob.glob("test_*.py") - test_list.extend(glob.glob("tests")) + test_list = glob.glob("**/*_test.py", recursive=True) + glob.glob("**/test_*.py", recursive=True) + test_list.extend(glob.glob("**/tests", recursive=True)) if len(test_list) == 0: print("No tests found, skipping directory.") diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py index 5fcb9d7461f..0398d72ff69 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile.py @@ -207,8 +207,8 @@ def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: # check for presence of tests - test_list = glob.glob("*_test.py") + glob.glob("test_*.py") - test_list.extend(glob.glob("tests")) + test_list = glob.glob("**/*_test.py", recursive=True) + glob.glob("**/test_*.py", recursive=True) + test_list.extend(glob.glob("**/tests", recursive=True)) if len(test_list) == 0: print("No tests found, skipping directory.") From 9e946268141fa57aa4398578e83352b37feedf74 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 4 Oct 2022 15:42:57 +0200 Subject: [PATCH 65/77] chore(deps): update dependency google-cloud-monitoring to v2.11.2 (#498) --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index f0b2ede75ce..db5d369c2d3 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.11.1 +google-cloud-monitoring==2.11.2 tabulate==0.8.10 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 78083b0ff77..7d155e14b06 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.11.1 +google-cloud-monitoring==2.11.2 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index f0b2ede75ce..db5d369c2d3 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.11.1 +google-cloud-monitoring==2.11.2 tabulate==0.8.10 From 73690ea97c36171c227b58e4aed8511429a5ba0f Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Thu, 6 Oct 2022 15:40:12 +0200 Subject: [PATCH 66/77] chore(deps): update dependency backoff to v2.2.1 (#499) --- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- .../snippets/v3/uptime-check-client/requirements-test.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index 987cc10d37b..46606d37d83 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ -backoff==2.1.2 +backoff==2.2.1 pytest==7.1.3 mock==4.0.3 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt index 6759e75e03a..3bc76cee52d 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -1,2 +1,2 @@ -backoff==2.1.2 +backoff==2.2.1 pytest==7.1.3 From 1e23252ead941a9f6c5e95cd45e6c99aa13a719b Mon Sep 17 00:00:00 2001 From: minherz Date: Mon, 10 Oct 2022 18:26:36 +0000 Subject: [PATCH 67/77] fix: add missing argument description (#504) add argument description for restore() method --- monitoring/snippets/v3/alerts-client/snippets.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/monitoring/snippets/v3/alerts-client/snippets.py b/monitoring/snippets/v3/alerts-client/snippets.py index aeaa45a1cab..6362ff37f15 100644 --- a/monitoring/snippets/v3/alerts-client/snippets.py +++ b/monitoring/snippets/v3/alerts-client/snippets.py @@ -216,6 +216,14 @@ def default(self, obj): # [START monitoring_alert_update_channel] # [START monitoring_alert_enable_channel] def restore(project_name, backup_filename): + """Restore alert policies in a project. + + Arguments: + project_name (str): The Google Cloud Project to use. The project name + must be in the format - 'projects/'. + backup_filename (str): Name of the file (along with its path) from + which the alert policies will be restored. + """ print( "Loading alert policies and notification channels from {}.".format( backup_filename From c73eb1783b4f3428441f2f1203bbb68f69ff9939 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 18 Oct 2022 15:33:29 +0200 Subject: [PATCH 68/77] chore(deps): update dependency tabulate to v0.9.0 (#501) Co-authored-by: Anthonios Partheniou --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index db5d369c2d3..e08503f1336 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ google-cloud-monitoring==2.11.2 -tabulate==0.8.10 +tabulate==0.9.0 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index db5d369c2d3..e08503f1336 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ google-cloud-monitoring==2.11.2 -tabulate==0.8.10 +tabulate==0.9.0 From 9d80149e4da590892e3072d33d1455883ea0bc5c Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 18 Oct 2022 17:33:24 +0200 Subject: [PATCH 69/77] chore(deps): update dependency google-cloud-monitoring to v2.11.3 (#506) --- monitoring/snippets/v3/alerts-client/requirements.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements.txt | 2 +- monitoring/snippets/v3/uptime-check-client/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements.txt b/monitoring/snippets/v3/alerts-client/requirements.txt index e08503f1336..1aa5e91c597 100644 --- a/monitoring/snippets/v3/alerts-client/requirements.txt +++ b/monitoring/snippets/v3/alerts-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.11.2 +google-cloud-monitoring==2.11.3 tabulate==0.9.0 diff --git a/monitoring/snippets/v3/cloud-client/requirements.txt b/monitoring/snippets/v3/cloud-client/requirements.txt index 7d155e14b06..6bd58bf6c5c 100644 --- a/monitoring/snippets/v3/cloud-client/requirements.txt +++ b/monitoring/snippets/v3/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-monitoring==2.11.2 +google-cloud-monitoring==2.11.3 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements.txt b/monitoring/snippets/v3/uptime-check-client/requirements.txt index e08503f1336..1aa5e91c597 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-monitoring==2.11.2 +google-cloud-monitoring==2.11.3 tabulate==0.9.0 From fb5cd4937c989aaf4942e7b98a165b6fc1d42cc0 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Wed, 26 Oct 2022 12:59:46 +0200 Subject: [PATCH 70/77] chore(deps): update dependency pytest to v7.2.0 (#507) --- monitoring/snippets/v3/alerts-client/requirements-test.txt | 2 +- monitoring/snippets/v3/cloud-client/requirements-test.txt | 2 +- .../snippets/v3/uptime-check-client/requirements-test.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/requirements-test.txt b/monitoring/snippets/v3/alerts-client/requirements-test.txt index 8a77da2aa57..608095bdfe9 100644 --- a/monitoring/snippets/v3/alerts-client/requirements-test.txt +++ b/monitoring/snippets/v3/alerts-client/requirements-test.txt @@ -1,3 +1,3 @@ -pytest==7.1.3 +pytest==7.2.0 retrying==1.3.3 flaky==3.7.0 diff --git a/monitoring/snippets/v3/cloud-client/requirements-test.txt b/monitoring/snippets/v3/cloud-client/requirements-test.txt index 46606d37d83..5051384f226 100644 --- a/monitoring/snippets/v3/cloud-client/requirements-test.txt +++ b/monitoring/snippets/v3/cloud-client/requirements-test.txt @@ -1,3 +1,3 @@ backoff==2.2.1 -pytest==7.1.3 +pytest==7.2.0 mock==4.0.3 diff --git a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt index 3bc76cee52d..b90fc387d01 100644 --- a/monitoring/snippets/v3/uptime-check-client/requirements-test.txt +++ b/monitoring/snippets/v3/uptime-check-client/requirements-test.txt @@ -1,2 +1,2 @@ backoff==2.2.1 -pytest==7.1.3 +pytest==7.2.0 From 0286f4632efed0cd199a8d32fbceba43806c3f49 Mon Sep 17 00:00:00 2001 From: minherz Date: Fri, 28 Oct 2022 19:50:38 +0000 Subject: [PATCH 71/77] fix: add metric label example to the snippet (#509) add code line to set metric label in addition to resource label. make the code sample align with similar samples in other languages. --- monitoring/snippets/v3/cloud-client/quickstart.py | 1 + 1 file changed, 1 insertion(+) diff --git a/monitoring/snippets/v3/cloud-client/quickstart.py b/monitoring/snippets/v3/cloud-client/quickstart.py index 78088dbad9b..244060c0982 100644 --- a/monitoring/snippets/v3/cloud-client/quickstart.py +++ b/monitoring/snippets/v3/cloud-client/quickstart.py @@ -25,6 +25,7 @@ def run_quickstart(project=""): series = monitoring_v3.TimeSeries() series.metric.type = "custom.googleapis.com/my_metric" + series.metric.labels["store_id"] = "Pittsburgh" series.resource.type = "gce_instance" series.resource.labels["instance_id"] = "1234567890123456789" series.resource.labels["zone"] = "us-central1-f" From 55060ffedab1c3c47a82d3c43d35b7156b509bcd Mon Sep 17 00:00:00 2001 From: Drew Brown Date: Tue, 8 Nov 2022 11:53:50 -0700 Subject: [PATCH 72/77] chore: Update company name in license header --- monitoring/snippets/v3/cloud-client/quickstart.py | 2 +- monitoring/snippets/v3/cloud-client/quickstart_test.py | 2 +- monitoring/snippets/v3/cloud-client/snippets.py | 2 +- monitoring/snippets/v3/cloud-client/snippets_test.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/monitoring/snippets/v3/cloud-client/quickstart.py b/monitoring/snippets/v3/cloud-client/quickstart.py index 244060c0982..4d526c91f19 100644 --- a/monitoring/snippets/v3/cloud-client/quickstart.py +++ b/monitoring/snippets/v3/cloud-client/quickstart.py @@ -1,4 +1,4 @@ -# Copyright 2017 Google Inc. +# Copyright 2017 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/monitoring/snippets/v3/cloud-client/quickstart_test.py b/monitoring/snippets/v3/cloud-client/quickstart_test.py index d7826e92ce5..c034e621904 100644 --- a/monitoring/snippets/v3/cloud-client/quickstart_test.py +++ b/monitoring/snippets/v3/cloud-client/quickstart_test.py @@ -1,4 +1,4 @@ -# Copyright 2017 Google Inc. +# Copyright 2017 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/monitoring/snippets/v3/cloud-client/snippets.py b/monitoring/snippets/v3/cloud-client/snippets.py index aa9eae62331..cbb7d88bc48 100644 --- a/monitoring/snippets/v3/cloud-client/snippets.py +++ b/monitoring/snippets/v3/cloud-client/snippets.py @@ -1,4 +1,4 @@ -# Copyright 2017 Google Inc. +# Copyright 2017 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/monitoring/snippets/v3/cloud-client/snippets_test.py b/monitoring/snippets/v3/cloud-client/snippets_test.py index d6c7d07adf4..9a2b44c633b 100644 --- a/monitoring/snippets/v3/cloud-client/snippets_test.py +++ b/monitoring/snippets/v3/cloud-client/snippets_test.py @@ -1,4 +1,4 @@ -# Copyright 2017 Google Inc. +# Copyright 2017 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From c1e4eaf44f1d3645633aa89bb583c0908434c815 Mon Sep 17 00:00:00 2001 From: Drew Brown Date: Tue, 8 Nov 2022 16:11:39 -0700 Subject: [PATCH 73/77] Remove 2.7 from ignored version (test not run) --- monitoring/snippets/v3/alerts-client/noxfile_config.py | 2 +- monitoring/snippets/v3/cloud-client/noxfile_config.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile_config.py b/monitoring/snippets/v3/alerts-client/noxfile_config.py index 664c58309d7..1c420fc8a2d 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile_config.py +++ b/monitoring/snippets/v3/alerts-client/noxfile_config.py @@ -22,7 +22,7 @@ TEST_CONFIG_OVERRIDE = { # You can opt out from the test for specific Python versions. - 'ignored_versions': ["2.7"], + 'ignored_versions': [], # Declare optional test sessions you want to opt-in. Currently we # have the following optional test sessions: diff --git a/monitoring/snippets/v3/cloud-client/noxfile_config.py b/monitoring/snippets/v3/cloud-client/noxfile_config.py index 664c58309d7..1c420fc8a2d 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile_config.py +++ b/monitoring/snippets/v3/cloud-client/noxfile_config.py @@ -22,7 +22,7 @@ TEST_CONFIG_OVERRIDE = { # You can opt out from the test for specific Python versions. - 'ignored_versions': ["2.7"], + 'ignored_versions': [], # Declare optional test sessions you want to opt-in. Currently we # have the following optional test sessions: From 060bfb0ac8b4d5d5cd7b877db87d17845e7741ae Mon Sep 17 00:00:00 2001 From: Drew Brown Date: Tue, 8 Nov 2022 16:42:46 -0700 Subject: [PATCH 74/77] Wrangle noxfile into submission Remove noxfile Add noxfile_config.py skipping 2.7 --- .../snippets/v3/alerts-client/noxfile.py | 312 ------------------ .../v3/alerts-client/noxfile_config.py | 2 +- .../snippets/v3/cloud-client/noxfile.py | 312 ------------------ .../v3/cloud-client/noxfile_config.py | 2 +- .../v3/uptime-check-client/noxfile.py | 312 ------------------ .../v3/uptime-check-client/noxfile_config.py | 42 +++ 6 files changed, 44 insertions(+), 938 deletions(-) delete mode 100644 monitoring/snippets/v3/alerts-client/noxfile.py delete mode 100644 monitoring/snippets/v3/cloud-client/noxfile.py delete mode 100644 monitoring/snippets/v3/uptime-check-client/noxfile.py create mode 100644 monitoring/snippets/v3/uptime-check-client/noxfile_config.py diff --git a/monitoring/snippets/v3/alerts-client/noxfile.py b/monitoring/snippets/v3/alerts-client/noxfile.py deleted file mode 100644 index 0398d72ff69..00000000000 --- a/monitoring/snippets/v3/alerts-client/noxfile.py +++ /dev/null @@ -1,312 +0,0 @@ -# Copyright 2019 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. - -from __future__ import print_function - -import glob -import os -from pathlib import Path -import sys -from typing import Callable, Dict, List, Optional - -import nox - - -# WARNING - WARNING - WARNING - WARNING - WARNING -# WARNING - WARNING - WARNING - WARNING - WARNING -# DO NOT EDIT THIS FILE EVER! -# WARNING - WARNING - WARNING - WARNING - WARNING -# WARNING - WARNING - WARNING - WARNING - WARNING - -BLACK_VERSION = "black==22.3.0" -ISORT_VERSION = "isort==5.10.1" - -# Copy `noxfile_config.py` to your directory and modify it instead. - -# `TEST_CONFIG` dict is a configuration hook that allows users to -# modify the test configurations. The values here should be in sync -# with `noxfile_config.py`. Users will copy `noxfile_config.py` into -# their directory and modify it. - -TEST_CONFIG = { - # You can opt out from the test for specific Python versions. - "ignored_versions": [], - # Old samples are opted out of enforcing Python type hints - # All new samples should feature them - "enforce_type_hints": False, - # An envvar key for determining the project id to use. Change it - # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a - # build specific Cloud project. You can also use your own string - # to use your own Cloud project. - "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", - # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - # If you need to use a specific version of pip, - # change pip_version_override to the string representation - # of the version number, for example, "20.2.4" - "pip_version_override": None, - # A dictionary you want to inject into your test. Don't put any - # secrets here. These values will override predefined values. - "envs": {}, -} - - -try: - # Ensure we can import noxfile_config in the project's directory. - sys.path.append(".") - from noxfile_config import TEST_CONFIG_OVERRIDE -except ImportError as e: - print("No user noxfile_config found: detail: {}".format(e)) - TEST_CONFIG_OVERRIDE = {} - -# Update the TEST_CONFIG with the user supplied values. -TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) - - -def get_pytest_env_vars() -> Dict[str, str]: - """Returns a dict for pytest invocation.""" - ret = {} - - # Override the GCLOUD_PROJECT and the alias. - env_key = TEST_CONFIG["gcloud_project_env"] - # This should error out if not set. - ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] - - # Apply user supplied envs. - ret.update(TEST_CONFIG["envs"]) - return ret - - -# DO NOT EDIT - automatically generated. -# All versions used to test samples. -ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10"] - -# Any default versions that should be ignored. -IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] - -TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) - -INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ( - "True", - "true", -) - -# Error if a python version is missing -nox.options.error_on_missing_interpreters = True - -# -# Style Checks -# - - -def _determine_local_import_names(start_dir: str) -> List[str]: - """Determines all import names that should be considered "local". - - This is used when running the linter to insure that import order is - properly checked. - """ - file_ext_pairs = [os.path.splitext(path) for path in os.listdir(start_dir)] - return [ - basename - for basename, extension in file_ext_pairs - if extension == ".py" - or os.path.isdir(os.path.join(start_dir, basename)) - and basename not in ("__pycache__") - ] - - -# Linting with flake8. -# -# We ignore the following rules: -# E203: whitespace before ‘:’ -# E266: too many leading ‘#’ for block comment -# E501: line too long -# I202: Additional newline in a section of imports -# -# We also need to specify the rules which are ignored by default: -# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121'] -FLAKE8_COMMON_ARGS = [ - "--show-source", - "--builtin=gettext", - "--max-complexity=20", - "--import-order-style=google", - "--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py", - "--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202", - "--max-line-length=88", -] - - -@nox.session -def lint(session: nox.sessions.Session) -> None: - if not TEST_CONFIG["enforce_type_hints"]: - session.install("flake8", "flake8-import-order") - else: - session.install("flake8", "flake8-import-order", "flake8-annotations") - - local_names = _determine_local_import_names(".") - args = FLAKE8_COMMON_ARGS + [ - "--application-import-names", - ",".join(local_names), - ".", - ] - session.run("flake8", *args) - - -# -# Black -# - - -@nox.session -def blacken(session: nox.sessions.Session) -> None: - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - python_files = [path for path in os.listdir(".") if path.endswith(".py")] - - session.run("black", *python_files) - - -# -# format = isort + black -# - -@nox.session -def format(session: nox.sessions.Session) -> None: - """ - Run isort to sort imports. Then run black - to format code to uniform standard. - """ - session.install(BLACK_VERSION, ISORT_VERSION) - python_files = [path for path in os.listdir(".") if path.endswith(".py")] - - # Use the --fss option to sort imports using strict alphabetical order. - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections - session.run("isort", "--fss", *python_files) - session.run("black", *python_files) - - -# -# Sample Tests -# - - -PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] - - -def _session_tests( - session: nox.sessions.Session, post_install: Callable = None -) -> None: - # check for presence of tests - test_list = glob.glob("**/*_test.py", recursive=True) + glob.glob("**/test_*.py", recursive=True) - test_list.extend(glob.glob("**/tests", recursive=True)) - - if len(test_list) == 0: - print("No tests found, skipping directory.") - return - - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - concurrent_args = [] - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - with open("requirements.txt") as rfile: - packages = rfile.read() - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install( - "-r", "requirements-test.txt", "-c", "constraints-test.txt" - ) - else: - session.install("-r", "requirements-test.txt") - with open("requirements-test.txt") as rtfile: - packages += rtfile.read() - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - if "pytest-parallel" in packages: - concurrent_args.extend(['--workers', 'auto', '--tests-per-worker', 'auto']) - elif "pytest-xdist" in packages: - concurrent_args.extend(['-n', 'auto']) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs + concurrent_args), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) - - -@nox.session(python=ALL_VERSIONS) -def py(session: nox.sessions.Session) -> None: - """Runs py.test for a sample using the specified version of Python.""" - if session.python in TESTED_VERSIONS: - _session_tests(session) - else: - session.skip( - "SKIPPED: {} tests are disabled for this sample.".format(session.python) - ) - - -# -# Readmegen -# - - -def _get_repo_root() -> Optional[str]: - """ Returns the root folder of the project. """ - # Get root of this repository. Assume we don't have directories nested deeper than 10 items. - p = Path(os.getcwd()) - for i in range(10): - if p is None: - break - if Path(p / ".git").exists(): - return str(p) - # .git is not available in repos cloned via Cloud Build - # setup.py is always in the library's root, so use that instead - # https://github.com/googleapis/synthtool/issues/792 - if Path(p / "setup.py").exists(): - return str(p) - p = p.parent - raise Exception("Unable to detect repository root.") - - -GENERATED_READMES = sorted([x for x in Path(".").rglob("*.rst.in")]) - - -@nox.session -@nox.parametrize("path", GENERATED_READMES) -def readmegen(session: nox.sessions.Session, path: str) -> None: - """(Re-)generates the readme for a sample.""" - session.install("jinja2", "pyyaml") - dir_ = os.path.dirname(path) - - if os.path.exists(os.path.join(dir_, "requirements.txt")): - session.install("-r", os.path.join(dir_, "requirements.txt")) - - in_file = os.path.join(dir_, "README.rst.in") - session.run( - "python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file - ) diff --git a/monitoring/snippets/v3/alerts-client/noxfile_config.py b/monitoring/snippets/v3/alerts-client/noxfile_config.py index 1c420fc8a2d..664c58309d7 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile_config.py +++ b/monitoring/snippets/v3/alerts-client/noxfile_config.py @@ -22,7 +22,7 @@ TEST_CONFIG_OVERRIDE = { # You can opt out from the test for specific Python versions. - 'ignored_versions': [], + 'ignored_versions': ["2.7"], # Declare optional test sessions you want to opt-in. Currently we # have the following optional test sessions: diff --git a/monitoring/snippets/v3/cloud-client/noxfile.py b/monitoring/snippets/v3/cloud-client/noxfile.py deleted file mode 100644 index 0398d72ff69..00000000000 --- a/monitoring/snippets/v3/cloud-client/noxfile.py +++ /dev/null @@ -1,312 +0,0 @@ -# Copyright 2019 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. - -from __future__ import print_function - -import glob -import os -from pathlib import Path -import sys -from typing import Callable, Dict, List, Optional - -import nox - - -# WARNING - WARNING - WARNING - WARNING - WARNING -# WARNING - WARNING - WARNING - WARNING - WARNING -# DO NOT EDIT THIS FILE EVER! -# WARNING - WARNING - WARNING - WARNING - WARNING -# WARNING - WARNING - WARNING - WARNING - WARNING - -BLACK_VERSION = "black==22.3.0" -ISORT_VERSION = "isort==5.10.1" - -# Copy `noxfile_config.py` to your directory and modify it instead. - -# `TEST_CONFIG` dict is a configuration hook that allows users to -# modify the test configurations. The values here should be in sync -# with `noxfile_config.py`. Users will copy `noxfile_config.py` into -# their directory and modify it. - -TEST_CONFIG = { - # You can opt out from the test for specific Python versions. - "ignored_versions": [], - # Old samples are opted out of enforcing Python type hints - # All new samples should feature them - "enforce_type_hints": False, - # An envvar key for determining the project id to use. Change it - # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a - # build specific Cloud project. You can also use your own string - # to use your own Cloud project. - "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", - # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - # If you need to use a specific version of pip, - # change pip_version_override to the string representation - # of the version number, for example, "20.2.4" - "pip_version_override": None, - # A dictionary you want to inject into your test. Don't put any - # secrets here. These values will override predefined values. - "envs": {}, -} - - -try: - # Ensure we can import noxfile_config in the project's directory. - sys.path.append(".") - from noxfile_config import TEST_CONFIG_OVERRIDE -except ImportError as e: - print("No user noxfile_config found: detail: {}".format(e)) - TEST_CONFIG_OVERRIDE = {} - -# Update the TEST_CONFIG with the user supplied values. -TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) - - -def get_pytest_env_vars() -> Dict[str, str]: - """Returns a dict for pytest invocation.""" - ret = {} - - # Override the GCLOUD_PROJECT and the alias. - env_key = TEST_CONFIG["gcloud_project_env"] - # This should error out if not set. - ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] - - # Apply user supplied envs. - ret.update(TEST_CONFIG["envs"]) - return ret - - -# DO NOT EDIT - automatically generated. -# All versions used to test samples. -ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10"] - -# Any default versions that should be ignored. -IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] - -TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) - -INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ( - "True", - "true", -) - -# Error if a python version is missing -nox.options.error_on_missing_interpreters = True - -# -# Style Checks -# - - -def _determine_local_import_names(start_dir: str) -> List[str]: - """Determines all import names that should be considered "local". - - This is used when running the linter to insure that import order is - properly checked. - """ - file_ext_pairs = [os.path.splitext(path) for path in os.listdir(start_dir)] - return [ - basename - for basename, extension in file_ext_pairs - if extension == ".py" - or os.path.isdir(os.path.join(start_dir, basename)) - and basename not in ("__pycache__") - ] - - -# Linting with flake8. -# -# We ignore the following rules: -# E203: whitespace before ‘:’ -# E266: too many leading ‘#’ for block comment -# E501: line too long -# I202: Additional newline in a section of imports -# -# We also need to specify the rules which are ignored by default: -# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121'] -FLAKE8_COMMON_ARGS = [ - "--show-source", - "--builtin=gettext", - "--max-complexity=20", - "--import-order-style=google", - "--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py", - "--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202", - "--max-line-length=88", -] - - -@nox.session -def lint(session: nox.sessions.Session) -> None: - if not TEST_CONFIG["enforce_type_hints"]: - session.install("flake8", "flake8-import-order") - else: - session.install("flake8", "flake8-import-order", "flake8-annotations") - - local_names = _determine_local_import_names(".") - args = FLAKE8_COMMON_ARGS + [ - "--application-import-names", - ",".join(local_names), - ".", - ] - session.run("flake8", *args) - - -# -# Black -# - - -@nox.session -def blacken(session: nox.sessions.Session) -> None: - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - python_files = [path for path in os.listdir(".") if path.endswith(".py")] - - session.run("black", *python_files) - - -# -# format = isort + black -# - -@nox.session -def format(session: nox.sessions.Session) -> None: - """ - Run isort to sort imports. Then run black - to format code to uniform standard. - """ - session.install(BLACK_VERSION, ISORT_VERSION) - python_files = [path for path in os.listdir(".") if path.endswith(".py")] - - # Use the --fss option to sort imports using strict alphabetical order. - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections - session.run("isort", "--fss", *python_files) - session.run("black", *python_files) - - -# -# Sample Tests -# - - -PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] - - -def _session_tests( - session: nox.sessions.Session, post_install: Callable = None -) -> None: - # check for presence of tests - test_list = glob.glob("**/*_test.py", recursive=True) + glob.glob("**/test_*.py", recursive=True) - test_list.extend(glob.glob("**/tests", recursive=True)) - - if len(test_list) == 0: - print("No tests found, skipping directory.") - return - - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - concurrent_args = [] - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - with open("requirements.txt") as rfile: - packages = rfile.read() - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install( - "-r", "requirements-test.txt", "-c", "constraints-test.txt" - ) - else: - session.install("-r", "requirements-test.txt") - with open("requirements-test.txt") as rtfile: - packages += rtfile.read() - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - if "pytest-parallel" in packages: - concurrent_args.extend(['--workers', 'auto', '--tests-per-worker', 'auto']) - elif "pytest-xdist" in packages: - concurrent_args.extend(['-n', 'auto']) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs + concurrent_args), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) - - -@nox.session(python=ALL_VERSIONS) -def py(session: nox.sessions.Session) -> None: - """Runs py.test for a sample using the specified version of Python.""" - if session.python in TESTED_VERSIONS: - _session_tests(session) - else: - session.skip( - "SKIPPED: {} tests are disabled for this sample.".format(session.python) - ) - - -# -# Readmegen -# - - -def _get_repo_root() -> Optional[str]: - """ Returns the root folder of the project. """ - # Get root of this repository. Assume we don't have directories nested deeper than 10 items. - p = Path(os.getcwd()) - for i in range(10): - if p is None: - break - if Path(p / ".git").exists(): - return str(p) - # .git is not available in repos cloned via Cloud Build - # setup.py is always in the library's root, so use that instead - # https://github.com/googleapis/synthtool/issues/792 - if Path(p / "setup.py").exists(): - return str(p) - p = p.parent - raise Exception("Unable to detect repository root.") - - -GENERATED_READMES = sorted([x for x in Path(".").rglob("*.rst.in")]) - - -@nox.session -@nox.parametrize("path", GENERATED_READMES) -def readmegen(session: nox.sessions.Session, path: str) -> None: - """(Re-)generates the readme for a sample.""" - session.install("jinja2", "pyyaml") - dir_ = os.path.dirname(path) - - if os.path.exists(os.path.join(dir_, "requirements.txt")): - session.install("-r", os.path.join(dir_, "requirements.txt")) - - in_file = os.path.join(dir_, "README.rst.in") - session.run( - "python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file - ) diff --git a/monitoring/snippets/v3/cloud-client/noxfile_config.py b/monitoring/snippets/v3/cloud-client/noxfile_config.py index 1c420fc8a2d..664c58309d7 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile_config.py +++ b/monitoring/snippets/v3/cloud-client/noxfile_config.py @@ -22,7 +22,7 @@ TEST_CONFIG_OVERRIDE = { # You can opt out from the test for specific Python versions. - 'ignored_versions': [], + 'ignored_versions': ["2.7"], # Declare optional test sessions you want to opt-in. Currently we # have the following optional test sessions: diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile.py b/monitoring/snippets/v3/uptime-check-client/noxfile.py deleted file mode 100644 index 0398d72ff69..00000000000 --- a/monitoring/snippets/v3/uptime-check-client/noxfile.py +++ /dev/null @@ -1,312 +0,0 @@ -# Copyright 2019 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. - -from __future__ import print_function - -import glob -import os -from pathlib import Path -import sys -from typing import Callable, Dict, List, Optional - -import nox - - -# WARNING - WARNING - WARNING - WARNING - WARNING -# WARNING - WARNING - WARNING - WARNING - WARNING -# DO NOT EDIT THIS FILE EVER! -# WARNING - WARNING - WARNING - WARNING - WARNING -# WARNING - WARNING - WARNING - WARNING - WARNING - -BLACK_VERSION = "black==22.3.0" -ISORT_VERSION = "isort==5.10.1" - -# Copy `noxfile_config.py` to your directory and modify it instead. - -# `TEST_CONFIG` dict is a configuration hook that allows users to -# modify the test configurations. The values here should be in sync -# with `noxfile_config.py`. Users will copy `noxfile_config.py` into -# their directory and modify it. - -TEST_CONFIG = { - # You can opt out from the test for specific Python versions. - "ignored_versions": [], - # Old samples are opted out of enforcing Python type hints - # All new samples should feature them - "enforce_type_hints": False, - # An envvar key for determining the project id to use. Change it - # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a - # build specific Cloud project. You can also use your own string - # to use your own Cloud project. - "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", - # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - # If you need to use a specific version of pip, - # change pip_version_override to the string representation - # of the version number, for example, "20.2.4" - "pip_version_override": None, - # A dictionary you want to inject into your test. Don't put any - # secrets here. These values will override predefined values. - "envs": {}, -} - - -try: - # Ensure we can import noxfile_config in the project's directory. - sys.path.append(".") - from noxfile_config import TEST_CONFIG_OVERRIDE -except ImportError as e: - print("No user noxfile_config found: detail: {}".format(e)) - TEST_CONFIG_OVERRIDE = {} - -# Update the TEST_CONFIG with the user supplied values. -TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) - - -def get_pytest_env_vars() -> Dict[str, str]: - """Returns a dict for pytest invocation.""" - ret = {} - - # Override the GCLOUD_PROJECT and the alias. - env_key = TEST_CONFIG["gcloud_project_env"] - # This should error out if not set. - ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] - - # Apply user supplied envs. - ret.update(TEST_CONFIG["envs"]) - return ret - - -# DO NOT EDIT - automatically generated. -# All versions used to test samples. -ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10"] - -# Any default versions that should be ignored. -IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] - -TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) - -INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ( - "True", - "true", -) - -# Error if a python version is missing -nox.options.error_on_missing_interpreters = True - -# -# Style Checks -# - - -def _determine_local_import_names(start_dir: str) -> List[str]: - """Determines all import names that should be considered "local". - - This is used when running the linter to insure that import order is - properly checked. - """ - file_ext_pairs = [os.path.splitext(path) for path in os.listdir(start_dir)] - return [ - basename - for basename, extension in file_ext_pairs - if extension == ".py" - or os.path.isdir(os.path.join(start_dir, basename)) - and basename not in ("__pycache__") - ] - - -# Linting with flake8. -# -# We ignore the following rules: -# E203: whitespace before ‘:’ -# E266: too many leading ‘#’ for block comment -# E501: line too long -# I202: Additional newline in a section of imports -# -# We also need to specify the rules which are ignored by default: -# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121'] -FLAKE8_COMMON_ARGS = [ - "--show-source", - "--builtin=gettext", - "--max-complexity=20", - "--import-order-style=google", - "--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py", - "--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202", - "--max-line-length=88", -] - - -@nox.session -def lint(session: nox.sessions.Session) -> None: - if not TEST_CONFIG["enforce_type_hints"]: - session.install("flake8", "flake8-import-order") - else: - session.install("flake8", "flake8-import-order", "flake8-annotations") - - local_names = _determine_local_import_names(".") - args = FLAKE8_COMMON_ARGS + [ - "--application-import-names", - ",".join(local_names), - ".", - ] - session.run("flake8", *args) - - -# -# Black -# - - -@nox.session -def blacken(session: nox.sessions.Session) -> None: - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - python_files = [path for path in os.listdir(".") if path.endswith(".py")] - - session.run("black", *python_files) - - -# -# format = isort + black -# - -@nox.session -def format(session: nox.sessions.Session) -> None: - """ - Run isort to sort imports. Then run black - to format code to uniform standard. - """ - session.install(BLACK_VERSION, ISORT_VERSION) - python_files = [path for path in os.listdir(".") if path.endswith(".py")] - - # Use the --fss option to sort imports using strict alphabetical order. - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections - session.run("isort", "--fss", *python_files) - session.run("black", *python_files) - - -# -# Sample Tests -# - - -PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] - - -def _session_tests( - session: nox.sessions.Session, post_install: Callable = None -) -> None: - # check for presence of tests - test_list = glob.glob("**/*_test.py", recursive=True) + glob.glob("**/test_*.py", recursive=True) - test_list.extend(glob.glob("**/tests", recursive=True)) - - if len(test_list) == 0: - print("No tests found, skipping directory.") - return - - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - concurrent_args = [] - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - with open("requirements.txt") as rfile: - packages = rfile.read() - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install( - "-r", "requirements-test.txt", "-c", "constraints-test.txt" - ) - else: - session.install("-r", "requirements-test.txt") - with open("requirements-test.txt") as rtfile: - packages += rtfile.read() - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - if "pytest-parallel" in packages: - concurrent_args.extend(['--workers', 'auto', '--tests-per-worker', 'auto']) - elif "pytest-xdist" in packages: - concurrent_args.extend(['-n', 'auto']) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs + concurrent_args), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) - - -@nox.session(python=ALL_VERSIONS) -def py(session: nox.sessions.Session) -> None: - """Runs py.test for a sample using the specified version of Python.""" - if session.python in TESTED_VERSIONS: - _session_tests(session) - else: - session.skip( - "SKIPPED: {} tests are disabled for this sample.".format(session.python) - ) - - -# -# Readmegen -# - - -def _get_repo_root() -> Optional[str]: - """ Returns the root folder of the project. """ - # Get root of this repository. Assume we don't have directories nested deeper than 10 items. - p = Path(os.getcwd()) - for i in range(10): - if p is None: - break - if Path(p / ".git").exists(): - return str(p) - # .git is not available in repos cloned via Cloud Build - # setup.py is always in the library's root, so use that instead - # https://github.com/googleapis/synthtool/issues/792 - if Path(p / "setup.py").exists(): - return str(p) - p = p.parent - raise Exception("Unable to detect repository root.") - - -GENERATED_READMES = sorted([x for x in Path(".").rglob("*.rst.in")]) - - -@nox.session -@nox.parametrize("path", GENERATED_READMES) -def readmegen(session: nox.sessions.Session, path: str) -> None: - """(Re-)generates the readme for a sample.""" - session.install("jinja2", "pyyaml") - dir_ = os.path.dirname(path) - - if os.path.exists(os.path.join(dir_, "requirements.txt")): - session.install("-r", os.path.join(dir_, "requirements.txt")) - - in_file = os.path.join(dir_, "README.rst.in") - session.run( - "python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file - ) diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile_config.py b/monitoring/snippets/v3/uptime-check-client/noxfile_config.py new file mode 100644 index 00000000000..664c58309d7 --- /dev/null +++ b/monitoring/snippets/v3/uptime-check-client/noxfile_config.py @@ -0,0 +1,42 @@ +# Copyright 2020 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. + +# Default TEST_CONFIG_OVERRIDE for python repos. + +# You can copy this file into your directory, then it will be inported from +# the noxfile.py. + +# The source of truth: +# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py + +TEST_CONFIG_OVERRIDE = { + # You can opt out from the test for specific Python versions. + 'ignored_versions': ["2.7"], + + # Declare optional test sessions you want to opt-in. Currently we + # have the following optional test sessions: + # 'cloud_run' # Test session for Cloud Run application. + 'opt_in_sessions': [], + + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + # 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + 'envs': {}, +} From d5444efde37b7742dbd6bc784969b86820744595 Mon Sep 17 00:00:00 2001 From: Drew Brown Date: Tue, 8 Nov 2022 16:45:42 -0700 Subject: [PATCH 75/77] Minor format change --- monitoring/snippets/v3/alerts-client/noxfile_config.py | 2 +- monitoring/snippets/v3/cloud-client/noxfile_config.py | 2 +- monitoring/snippets/v3/uptime-check-client/noxfile_config.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monitoring/snippets/v3/alerts-client/noxfile_config.py b/monitoring/snippets/v3/alerts-client/noxfile_config.py index 664c58309d7..6df11b83bd8 100644 --- a/monitoring/snippets/v3/alerts-client/noxfile_config.py +++ b/monitoring/snippets/v3/alerts-client/noxfile_config.py @@ -22,7 +22,7 @@ TEST_CONFIG_OVERRIDE = { # You can opt out from the test for specific Python versions. - 'ignored_versions': ["2.7"], + 'ignored_versions': ['2.7'], # Declare optional test sessions you want to opt-in. Currently we # have the following optional test sessions: diff --git a/monitoring/snippets/v3/cloud-client/noxfile_config.py b/monitoring/snippets/v3/cloud-client/noxfile_config.py index 664c58309d7..6df11b83bd8 100644 --- a/monitoring/snippets/v3/cloud-client/noxfile_config.py +++ b/monitoring/snippets/v3/cloud-client/noxfile_config.py @@ -22,7 +22,7 @@ TEST_CONFIG_OVERRIDE = { # You can opt out from the test for specific Python versions. - 'ignored_versions': ["2.7"], + 'ignored_versions': ['2.7'], # Declare optional test sessions you want to opt-in. Currently we # have the following optional test sessions: diff --git a/monitoring/snippets/v3/uptime-check-client/noxfile_config.py b/monitoring/snippets/v3/uptime-check-client/noxfile_config.py index 664c58309d7..6df11b83bd8 100644 --- a/monitoring/snippets/v3/uptime-check-client/noxfile_config.py +++ b/monitoring/snippets/v3/uptime-check-client/noxfile_config.py @@ -22,7 +22,7 @@ TEST_CONFIG_OVERRIDE = { # You can opt out from the test for specific Python versions. - 'ignored_versions': ["2.7"], + 'ignored_versions': ['2.7'], # Declare optional test sessions you want to opt-in. Currently we # have the following optional test sessions: From 92e4a39d17d430ad6192178604169898be1a1230 Mon Sep 17 00:00:00 2001 From: Drew Brown Date: Tue, 8 Nov 2022 17:30:41 -0700 Subject: [PATCH 76/77] Update blunderbuss and CODEOWNERS --- .github/CODEOWNERS | 2 +- .github/blunderbuss.yml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6d84c22da6a..f3d39865ea4 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -49,7 +49,7 @@ /media_cdn/**/* @justin-mp @msampathkumar @GoogleCloudPlatform/python-samples-reviewers /memorystore/**/* @GoogleCloudPlatform/python-samples-reviewers /ml_engine/**/* @ivanmkc @GoogleCloudPlatform/python-samples-reviewers -/monitoring/**/* @GoogleCloudPlatform/python-samples-reviewers +/monitoring/**/* @GoogleCloudPlatform/dee-observability @GoogleCloudPlatform/python-samples-reviewers /monitoring/opencensus @yuriatgoogle @GoogleCloudPlatform/python-samples-reviewers /monitoring/prometheus @yuriatgoogle @GoogleCloudPlatform/python-samples-reviewers /notebooks/**/* @alixhami @GoogleCloudPlatform/python-samples-reviewers diff --git a/.github/blunderbuss.yml b/.github/blunderbuss.yml index bc1059f6faa..747802efb56 100644 --- a/.github/blunderbuss.yml +++ b/.github/blunderbuss.yml @@ -108,6 +108,9 @@ assign_issues_by: - 'api: translate' to: - nicain +- labels: + - 'api: monitoring' + to: GoogleCloudPlatform/dee-observability assign_prs_by: - labels: From 19361b29081472921d40506e9902a9a9e93fa3e7 Mon Sep 17 00:00:00 2001 From: Drew Brown Date: Tue, 8 Nov 2022 17:33:19 -0700 Subject: [PATCH 77/77] Fix blunderbuss config --- .github/blunderbuss.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/blunderbuss.yml b/.github/blunderbuss.yml index 747802efb56..9d14b64ca9a 100644 --- a/.github/blunderbuss.yml +++ b/.github/blunderbuss.yml @@ -110,7 +110,8 @@ assign_issues_by: - nicain - labels: - 'api: monitoring' - to: GoogleCloudPlatform/dee-observability + to: + - GoogleCloudPlatform/dee-observability assign_prs_by: - labels: