Skip to content

Commit 5169bd4

Browse files
arithmetic1728Bill PrinJon Wayne Parrottdpebotwaprin
authored
chore: move samples from python-docs-sample (#18)
* Add Error Reporting Code * Updating doc links [(#324)](#324) * Commenting noxfile, renaming a test file. Change-Id: Ice25caa7c035c24a585a66575dda69e170862df8 * Update requirements. [(#436)](#436) * Fix import order lint errors Change-Id: Ieaf7237fc6f925daec46a07d2e81a452b841198a * bump Change-Id: I02e7767d13ba267ee9fc72c5b68a57013bb8b8d3 * Auto-update dependencies. [(#537)](#537) * Update samples to support latest Google Cloud Python [(#656)](#656) * Switch Error Reporting to Google Cloud Python [(#663)](#663) * Switch Error Reporting to Google Cloud Python * Switch Error Reporting to Google Cloud Python * Auto-update dependencies. [(#715)](#715) * Auto-update dependencies. [(#914)](#914) * Auto-update dependencies. * xfail the error reporting test * Fix lint * Re-generate all readmes * Auto-update dependencies. [(#922)](#922) * Auto-update dependencies. * Fix pubsub iam samples * Fix README rst links [(#962)](#962) * Fix README rst links * Update all READMEs * Auto-update dependencies. [(#1004)](#1004) * Auto-update dependencies. * Fix natural language samples * Fix pubsub iam samples * Fix language samples * Fix bigquery samples * Auto-update dependencies. [(#1011)](#1011) * Auto-update dependencies. [(#1055)](#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 * Auto-update dependencies. [(#1093)](#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 * Update all generated readme auth instructions [(#1121)](#1121) Change-Id: I03b5eaef8b17ac3dc3c0339fd2c7447bd3e11bd2 * Added Link to Python Setup Guide [(#1158)](#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)](#1186) * Add error reporting sample for manual reporting * Readd fluentd samples * rename dir * Auto-update dependencies. [(#1205)](#1205) * Auto-update dependencies. [(#1215)](#1215) * Auto-update dependencies. [(#1245)](#1245) * Auto-update dependencies. [(#1248)](#1248) * Added "Open in Cloud Shell" buttons to README files [(#1254)](#1254) * Auto-update dependencies. [(#1276)](#1276) * Auto-update dependencies. [(#1282)](#1282) * Auto-update dependencies. * Fix storage acl sample Change-Id: I413bea899fdde4c4859e4070a9da25845b81f7cf * Auto-update dependencies. [(#1317)](#1317) * Auto-update dependencies. [(#1320)](#1320) * Auto-update dependencies. [(#1359)](#1359) * Auto-update dependencies. [(#1377)](#1377) * Auto-update dependencies. * Update requirements.txt * Regenerate the README files and fix the Open in Cloud Shell link for some samples [(#1441)](#1441) * Update READMEs to fix numbering and add git clone [(#1464)](#1464) * Auto-update dependencies. [(#1658)](#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. * Put in new region code error_reporting_quickstart [(#1842)](#1842) * New region tags [(#1843)](#1843) * Auto-update dependencies. [(#1980)](#1980) * Auto-update dependencies. * Update requirements.txt * Update requirements.txt * Adds updates including compute [(#2436)](#2436) * Adds updates including compute * Python 2 compat pytest * Fixing weird \r\n issue from GH merge * Put asset tests back in * Re-add pod operator test * Hack parameter for k8s pod operator * Auto-update dependencies. [(#2005)](#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 <dmahugh@gmail.com> * chore(deps): update dependency fluent-logger to v0.9.5 [(#3004)](#3004) * chore(deps): update dependency fluent-logger to v0.9.6 [(#3080)](#3080) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [fluent-logger](https://togithub.com/fluent/fluent-logger-python) | patch | `==0.9.5` -> `==0.9.6` | --- ### Release Notes <details> <summary>fluent/fluent-logger-python</summary> ### [`v0.9.6`](https://togithub.com/fluent/fluent-logger-python/compare/v0.9.5...v0.9.6) [Compare Source](https://togithub.com/fluent/fluent-logger-python/compare/v0.9.5...v0.9.6) </details> --- ### 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**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->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). * Simplify noxfile setup. [(#2806)](#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 <bot@renovateapp.com> * chore(deps): update dependency google-cloud-error-reporting to v0.34.0 [(#3782)](#3782) * chore(deps): update dependency pytest to v5.4.3 [(#4279)](#4279) * chore(deps): update dependency pytest to v5.4.3 * specify pytest for python 2 in appengine Co-authored-by: Leah Cole <coleleah@google.com> * chore(deps): update dependency mock to v4 [(#4287)](#4287) * chore(deps): update dependency mock to v4 * specify mock version for appengine python 2 Co-authored-by: Leah Cole <coleleah@google.com> * Update dependency pytest to v6 [(#4390)](#4390) * chore: update templates Co-authored-by: Bill Prin <waprin@google.com> Co-authored-by: Jon Wayne Parrott <jonwayne@google.com> Co-authored-by: DPE bot <dpebot@google.com> Co-authored-by: Bill Prin <waprin@gmail.com> Co-authored-by: michaelawyu <chenyumic@google.com> Co-authored-by: Andrew Gorcester <gorcester@google.com> Co-authored-by: Andrew Gorcester <andrew.gorcester@gmail.com> Co-authored-by: Frank Natividad <frankyn@users.noreply.github.com> Co-authored-by: Charles Engelke <github@engelke.com> Co-authored-by: Gus Class <gguuss@gmail.com> Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com> Co-authored-by: Doug Mahugh <dmahugh@gmail.com> Co-authored-by: WhiteSource Renovate <bot@renovateapp.com> Co-authored-by: Leah Cole <coleleah@google.com>
0 parents  commit 5169bd4

File tree

7 files changed

+362
-0
lines changed

7 files changed

+362
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Google Error Reorting Samples Samples
2+
3+
[![Open in Cloud Shell][shell_img]][shell_link]
4+
5+
[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png
6+
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=error_reporting/fluent_on_compute/README.md
7+
8+
This section contains samples for [Google Cloud Error Reporting](https://cloud.google.com/error-reporting).
9+
10+
A startup script has been provided to demonstrated how to properly provision a GCE
11+
instance with fluentd configured. Note the intallation of fluentd, the addition of the config file,
12+
and the restarting of the fluetnd service. You can start an instance using
13+
it like this:
14+
15+
gcloud compute instances create example-instance --metadata-from-file startup-script=startup_script.sh
16+
17+
or simply use it as reference when creating your own instance.
18+
19+
After fluentd is configured, main.py could be used to simulate an error:
20+
21+
gcloud compute copy-files main.py example-instance:~/main.py
22+
23+
Then,
24+
25+
gcloud compute ssh example-instance
26+
python ~/main.py
27+
28+
And you will see the message in the Errors Console.
29+
30+
<!-- auto-doc-link -->
31+
These samples are used on the following documentation page:
32+
33+
> https://cloud.google.com/error-reporting/docs/setting-up-on-compute-engine
34+
35+
<!-- end-auto-doc-link -->
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START error_reporting]
16+
import traceback
17+
18+
import fluent.event
19+
import fluent.sender
20+
21+
22+
def simulate_error():
23+
fluent.sender.setup('myapp', host='localhost', port=24224)
24+
25+
def report(ex):
26+
data = {}
27+
data['message'] = '{0}'.format(ex)
28+
data['serviceContext'] = {'service': 'myapp'}
29+
# ... add more metadata
30+
fluent.event.Event('errors', data)
31+
32+
# report exception data using:
33+
try:
34+
# simulate calling a method that's not defined
35+
raise NameError
36+
except Exception:
37+
report(traceback.format_exc())
38+
# [END error_reporting]
39+
40+
41+
if __name__ == '__main__':
42+
simulate_error()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import mock
16+
17+
import main
18+
19+
20+
@mock.patch("fluent.event")
21+
def test_error_sends(event_mock):
22+
main.simulate_error()
23+
event_mock.Event.assert_called_once_with(mock.ANY, mock.ANY)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import print_function
16+
17+
import os
18+
from pathlib import Path
19+
import sys
20+
21+
import nox
22+
23+
24+
# WARNING - WARNING - WARNING - WARNING - WARNING
25+
# WARNING - WARNING - WARNING - WARNING - WARNING
26+
# DO NOT EDIT THIS FILE EVER!
27+
# WARNING - WARNING - WARNING - WARNING - WARNING
28+
# WARNING - WARNING - WARNING - WARNING - WARNING
29+
30+
# Copy `noxfile_config.py` to your directory and modify it instead.
31+
32+
33+
# `TEST_CONFIG` dict is a configuration hook that allows users to
34+
# modify the test configurations. The values here should be in sync
35+
# with `noxfile_config.py`. Users will copy `noxfile_config.py` into
36+
# their directory and modify it.
37+
38+
TEST_CONFIG = {
39+
# You can opt out from the test for specific Python versions.
40+
'ignored_versions': ["2.7"],
41+
42+
# An envvar key for determining the project id to use. Change it
43+
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
44+
# build specific Cloud project. You can also use your own string
45+
# to use your own Cloud project.
46+
'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT',
47+
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
48+
49+
# A dictionary you want to inject into your test. Don't put any
50+
# secrets here. These values will override predefined values.
51+
'envs': {},
52+
}
53+
54+
55+
try:
56+
# Ensure we can import noxfile_config in the project's directory.
57+
sys.path.append('.')
58+
from noxfile_config import TEST_CONFIG_OVERRIDE
59+
except ImportError as e:
60+
print("No user noxfile_config found: detail: {}".format(e))
61+
TEST_CONFIG_OVERRIDE = {}
62+
63+
# Update the TEST_CONFIG with the user supplied values.
64+
TEST_CONFIG.update(TEST_CONFIG_OVERRIDE)
65+
66+
67+
def get_pytest_env_vars():
68+
"""Returns a dict for pytest invocation."""
69+
ret = {}
70+
71+
# Override the GCLOUD_PROJECT and the alias.
72+
env_key = TEST_CONFIG['gcloud_project_env']
73+
# This should error out if not set.
74+
ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key]
75+
76+
# Apply user supplied envs.
77+
ret.update(TEST_CONFIG['envs'])
78+
return ret
79+
80+
81+
# DO NOT EDIT - automatically generated.
82+
# All versions used to tested samples.
83+
ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"]
84+
85+
# Any default versions that should be ignored.
86+
IGNORED_VERSIONS = TEST_CONFIG['ignored_versions']
87+
88+
TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS])
89+
90+
INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False))
91+
#
92+
# Style Checks
93+
#
94+
95+
96+
def _determine_local_import_names(start_dir):
97+
"""Determines all import names that should be considered "local".
98+
99+
This is used when running the linter to insure that import order is
100+
properly checked.
101+
"""
102+
file_ext_pairs = [os.path.splitext(path) for path in os.listdir(start_dir)]
103+
return [
104+
basename
105+
for basename, extension in file_ext_pairs
106+
if extension == ".py"
107+
or os.path.isdir(os.path.join(start_dir, basename))
108+
and basename not in ("__pycache__")
109+
]
110+
111+
112+
# Linting with flake8.
113+
#
114+
# We ignore the following rules:
115+
# E203: whitespace before ‘:’
116+
# E266: too many leading ‘#’ for block comment
117+
# E501: line too long
118+
# I202: Additional newline in a section of imports
119+
#
120+
# We also need to specify the rules which are ignored by default:
121+
# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121']
122+
FLAKE8_COMMON_ARGS = [
123+
"--show-source",
124+
"--builtin=gettext",
125+
"--max-complexity=20",
126+
"--import-order-style=google",
127+
"--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py",
128+
"--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202",
129+
"--max-line-length=88",
130+
]
131+
132+
133+
@nox.session
134+
def lint(session):
135+
session.install("flake8", "flake8-import-order")
136+
137+
local_names = _determine_local_import_names(".")
138+
args = FLAKE8_COMMON_ARGS + [
139+
"--application-import-names",
140+
",".join(local_names),
141+
"."
142+
]
143+
session.run("flake8", *args)
144+
145+
146+
#
147+
# Sample Tests
148+
#
149+
150+
151+
PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"]
152+
153+
154+
def _session_tests(session, post_install=None):
155+
"""Runs py.test for a particular project."""
156+
if os.path.exists("requirements.txt"):
157+
session.install("-r", "requirements.txt")
158+
159+
if os.path.exists("requirements-test.txt"):
160+
session.install("-r", "requirements-test.txt")
161+
162+
if INSTALL_LIBRARY_FROM_SOURCE:
163+
session.install("-e", _get_repo_root())
164+
165+
if post_install:
166+
post_install(session)
167+
168+
session.run(
169+
"pytest",
170+
*(PYTEST_COMMON_ARGS + session.posargs),
171+
# Pytest will return 5 when no tests are collected. This can happen
172+
# on travis where slow and flaky tests are excluded.
173+
# See http://doc.pytest.org/en/latest/_modules/_pytest/main.html
174+
success_codes=[0, 5],
175+
env=get_pytest_env_vars()
176+
)
177+
178+
179+
@nox.session(python=ALL_VERSIONS)
180+
def py(session):
181+
"""Runs py.test for a sample using the specified version of Python."""
182+
if session.python in TESTED_VERSIONS:
183+
_session_tests(session)
184+
else:
185+
session.skip("SKIPPED: {} tests are disabled for this sample.".format(
186+
session.python
187+
))
188+
189+
190+
#
191+
# Readmegen
192+
#
193+
194+
195+
def _get_repo_root():
196+
""" Returns the root folder of the project. """
197+
# Get root of this repository. Assume we don't have directories nested deeper than 10 items.
198+
p = Path(os.getcwd())
199+
for i in range(10):
200+
if p is None:
201+
break
202+
if Path(p / ".git").exists():
203+
return str(p)
204+
p = p.parent
205+
raise Exception("Unable to detect repository root.")
206+
207+
208+
GENERATED_READMES = sorted([x for x in Path(".").rglob("*.rst.in")])
209+
210+
211+
@nox.session
212+
@nox.parametrize("path", GENERATED_READMES)
213+
def readmegen(session, path):
214+
"""(Re-)generates the readme for a sample."""
215+
session.install("jinja2", "pyyaml")
216+
dir_ = os.path.dirname(path)
217+
218+
if os.path.exists(os.path.join(dir_, "requirements.txt")):
219+
session.install("-r", os.path.join(dir_, "requirements.txt"))
220+
221+
in_file = os.path.join(dir_, "README.rst.in")
222+
session.run(
223+
"python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file
224+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pytest==6.0.1
2+
mock==4.0.2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fluent-logger==0.9.6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2016 Google Inc. All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -v
17+
18+
curl -sSO "https://dl.google.com/cloudagents/install-logging-agent.sh"
19+
chmod +x install-logging-agent.sh
20+
./install-logging-agent.sh
21+
mkdir -p /etc/google-fluentd/config.d/
22+
cat <<EOF > /etc/google-fluentd/config.d/forward.conf
23+
<source>
24+
type forward
25+
port 24224
26+
</source>
27+
EOF
28+
service google-fluentd restart
29+
30+
apt-get update
31+
apt-get install -yq \
32+
git build-essential supervisor python python-dev python-pip libffi-dev \
33+
libssl-dev
34+
pip install fluent-logger
35+

0 commit comments

Comments
 (0)