Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate code from googleapis/python-error-reporting #8524

Merged
merged 35 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5169bd4
chore: move samples from python-docs-sample (#18)
arithmetic1728 Aug 13, 2020
268b015
chore: update templates (#38)
yoshi-automation Nov 18, 2020
b2be570
chore: add config / docs for 'pre-commit' support (#50)
yoshi-automation Dec 28, 2020
4d9a754
chore: Adding header-checker-lint and updating environment (#73)
yoshi-automation Jan 29, 2021
5141d61
chore(deps): update dependency fluent-logger to v0.10.0 (#88)
renovate-bot Mar 11, 2021
b96fbae
chore: Re-generated to pick up changes from synthtool. (#113)
yoshi-automation May 6, 2021
961126d
chore(deps): update dependency mock to v4.0.3 (#116)
renovate-bot May 6, 2021
904a3b6
chore(deps): update dependency pytest to v6.2.4 (#117)
renovate-bot May 6, 2021
6fa42cf
chore: new owl bot post processor docker image (#129)
gcf-owl-bot[bot] May 22, 2021
dce4386
feat: add Samples section to CONTRIBUTING.rst (#151)
gcf-owl-bot[bot] Jul 22, 2021
9ea9c86
chore: fix INSTALL_LIBRARY_FROM_SOURCE in noxfile.py (#161)
gcf-owl-bot[bot] Aug 11, 2021
1a41da8
chore: drop mention of Python 2.7 from templates (#163)
gcf-owl-bot[bot] Aug 13, 2021
7e5450f
chore(deps): update dependency pytest to v6.2.5 (#168)
renovate-bot Aug 31, 2021
1536ece
chore: blacken samples noxfile template (#173)
gcf-owl-bot[bot] Sep 17, 2021
caf8099
chore: fail samples nox session if python version is missing (#183)
gcf-owl-bot[bot] Sep 30, 2021
2db210a
chore(python): Add kokoro configs for python 3.10 samples testing (#189)
gcf-owl-bot[bot] Oct 8, 2021
3835e01
chore(samples): Add check for tests in directory (#213)
gcf-owl-bot[bot] Jan 11, 2022
c6de740
chore(python): Noxfile recognizes that tests can live in a folder (#217)
gcf-owl-bot[bot] Jan 19, 2022
e62f226
chore(deps): update all dependencies (#224)
renovate-bot Feb 7, 2022
77b7c0c
chore(deps): update dependency pytest to v7.0.1 (#229)
renovate-bot Feb 14, 2022
fe1fd6f
chore: Adding support for pytest-xdist and pytest-parallel (#242)
gcf-owl-bot[bot] Mar 4, 2022
1724cff
chore(deps): update dependency pytest to v7.1.0 (#247)
renovate-bot Mar 13, 2022
1d68cc1
chore(deps): update dependency pytest to v7.1.1 (#249)
renovate-bot Mar 17, 2022
7ef111a
chore(python): use black==22.3.0 (#253)
gcf-owl-bot[bot] Mar 29, 2022
c80e9fb
chore(python): add nox session to sort python imports (#267)
gcf-owl-bot[bot] Apr 21, 2022
1a12e4c
chore(deps): update dependency pytest to v7.1.2 (#270)
renovate-bot Apr 25, 2022
8064ea0
fix: require python 3.7+ (#358)
gcf-owl-bot[bot] Jul 10, 2022
e360bb2
chore(deps): update dependency pytest to v7.1.3 (#381)
renovate-bot Sep 6, 2022
4ee1eb4
chore: detect samples tests in nested directories (#385)
gcf-owl-bot[bot] Sep 13, 2022
b231ce6
chore(deps): update dependency pytest to v7.2.0 (#395)
renovate-bot Oct 26, 2022
ce81888
Merge remote-tracking branch 'migration/main' into python-error-repor…
msampathkumar Nov 16, 2022
e91b1d3
Update copyright headers for main.py main_test.py and startup_script.sh
msampathkumar Nov 16, 2022
c865c5e
remove noxfile.py
msampathkumar Nov 16, 2022
324e096
Update copyright details.
msampathkumar Nov 16, 2022
0cd6de3
Merge branch 'main' into python-error-reporting-migration
dandhlee Nov 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions error_reporting/fluent_on_compute/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Google Error Reorting Samples Samples

[![Open in Cloud Shell][shell_img]][shell_link]

[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png
[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

This section contains samples for [Google Cloud Error Reporting](https://cloud.google.com/error-reporting).

A startup script has been provided to demonstrated how to properly provision a GCE
instance with fluentd configured. Note the intallation of fluentd, the addition of the config file,
and the restarting of the fluetnd service. You can start an instance using
it like this:

gcloud compute instances create example-instance --metadata-from-file startup-script=startup_script.sh

or simply use it as reference when creating your own instance.

After fluentd is configured, main.py could be used to simulate an error:

gcloud compute copy-files main.py example-instance:~/main.py

Then,

gcloud compute ssh example-instance
python ~/main.py

And you will see the message in the Errors Console.

<!-- auto-doc-link -->
These samples are used on the following documentation page:

> https://cloud.google.com/error-reporting/docs/setting-up-on-compute-engine

<!-- end-auto-doc-link -->
45 changes: 45 additions & 0 deletions error_reporting/fluent_on_compute/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python
# Copyright 2016 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.
#
# All rights reserved.

# [START error_reporting_fluent_on_compute]
import traceback

import fluent.event
import fluent.sender


def simulate_error():
fluent.sender.setup('myapp', host='localhost', port=24224)

def report(ex):
data = {}
data['message'] = '{0}'.format(ex)
data['serviceContext'] = {'service': 'myapp'}
# ... add more metadata
fluent.event.Event('errors', data)

# report exception data using:
try:
# simulate calling a method that's not defined
raise NameError
except Exception:
report(traceback.format_exc())
# [END error_reporting_fluent_on_compute]


if __name__ == '__main__':
simulate_error()
26 changes: 26 additions & 0 deletions error_reporting/fluent_on_compute/main_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
# Copyright 2016 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.
#
# All rights reserved.

import mock

import main


@mock.patch("fluent.event")
def test_error_sends(event_mock):
main.simulate_error()
event_mock.Event.assert_called_once_with(mock.ANY, mock.ANY)
2 changes: 2 additions & 0 deletions error_reporting/fluent_on_compute/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest==7.2.0
mock==4.0.3
1 change: 1 addition & 0 deletions error_reporting/fluent_on_compute/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fluent-logger==0.10.0
37 changes: 37 additions & 0 deletions error_reporting/fluent_on_compute/startup_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Copyright 2016 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.
#
# All rights reserved.

set -v

curl -sSO "https://dl.google.com/cloudagents/install-logging-agent.sh"
chmod +x install-logging-agent.sh
./install-logging-agent.sh
mkdir -p /etc/google-fluentd/config.d/
cat <<EOF > /etc/google-fluentd/config.d/forward.conf
<source>
type forward
port 24224
</source>
EOF
service google-fluentd restart

apt-get update
apt-get install -yq \
git build-essential supervisor python python-dev python-pip libffi-dev \
libssl-dev
pip install fluent-logger