Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into majorgreys/instru…
Browse files Browse the repository at this point in the history
…mentor-celery
  • Loading branch information
majorgreys committed Jun 17, 2020
2 parents fcc65a7 + 17558b8 commit 4464220
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 65 deletions.
6 changes: 3 additions & 3 deletions docs/examples/cloud_monitoring/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ To use this exporter you first need to:
* Run example

.. code-block:: sh
python basic_metrics.py
.. literalinclude:: basic_metrics.py
:language: python
:lines: 1-

Viewing Output
--------------------------
Expand Down
47 changes: 38 additions & 9 deletions docs/examples/cloud_trace_exporter/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ Basic Example
-------------

To use this exporter you first need to:
* A Google Cloud project. You can `create one here. <https://console.cloud.google.com/projectcreate>`_
* Enable Cloud Trace API (aka Stackdriver Trace API) in the project `here. <https://console.cloud.google.com/apis/library?q=cloud_trace>`_
* Enable `Default Application Credentials. <https://developers.google.com/identity/protocols/application-default-credentials>`_
* A Google Cloud project. You can `create one here <https://console.cloud.google.com/projectcreate>`_.
* Enable Cloud Trace API (listed in the Cloud Console as Stackdriver Trace API) in the project `here <https://console.cloud.google.com/apis/library?q=cloud%20trace&filter=visibility:public>`_.
* If the page says "API Enabled" then you're done! No need to do anything.
* Enable Default Application Credentials by creating setting `GOOGLE_APPLICATION_CREDENTIALS <https://cloud.google.com/docs/authentication/getting-started>`_ or by `installing gcloud sdk <https://cloud.google.com/sdk/install>`_ and calling ``gcloud auth application-default login``.

* Installation

Expand All @@ -20,12 +21,11 @@ To use this exporter you first need to:
pip install opentelemetry-sdk
pip install opentelemetry-exporter-cloud-trace
* Run example locally
* Run an example locally

.. code-block:: sh
cd opentelemetry-python/docs/examples/cloud_trace_exporter
python basic_trace.py
.. literalinclude:: basic_trace.py
:language: python
:lines: 1-

Checking Output
--------------------------
Expand All @@ -47,4 +47,33 @@ Running basic_trace.py hangs:

Getting error ``google.api_core.exceptions.ResourceExhausted: 429 Resource has been exhausted``:
################################################################################################
* Check that you've enabled the `Cloud Trace (Stackdriver Trace) API <https://console.cloud.google.com/apis/library?q=cloud_trace>`_
* Check that you've enabled the `Cloud Trace (Stackdriver Trace) API <https://console.cloud.google.com/apis/library?q=cloud%20trace&filter=visibility:public>`_

bash: pip: command not found:
#############################
* `Install pip <https://cloud.google.com/python/setup#installing_python>`_
* If your machine uses python2 by default, pip will also be the python2 version. Try using ``pip3`` instead of ``pip``.

pip install is hanging
######################
Try upgrading pip

.. code-block:: sh
pip install --upgrade pip
``pip install grcpio`` has been known to hang when you aren't using an upgraded version.

ImportError: No module named opentelemetry
##########################################
Make sure you are using python3. If

.. code-block:: sh
python --version
returns ``Python 2.X.X`` try calling

.. code-block:: sh
python3 basic_trace.py
124 changes: 124 additions & 0 deletions scripts/eachdist.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/usr/bin/env python3

import argparse
import os
import re
import shlex
import shutil
import subprocess
import sys
from collections import namedtuple
from configparser import ConfigParser
from datetime import datetime
from inspect import cleandoc
from itertools import chain
from pathlib import Path, PurePath
Expand Down Expand Up @@ -236,6 +239,15 @@ def setup_instparser(instparser):
"pytestargs", nargs=argparse.REMAINDER, help=extraargs_help("pytest")
)

releaseparser = subparsers.add_parser(
"release", help="Prepares release, used by maintainers and CI",
)
releaseparser.set_defaults(func=release_args)
releaseparser.add_argument("--version", required=True)
releaseparser.add_argument(
"releaseargs", nargs=argparse.REMAINDER, help=extraargs_help("pytest")
)

return parser.parse_args(args)


Expand Down Expand Up @@ -503,6 +515,118 @@ def lint_args(args):
)


def update_changelog(path, version, new_entry):
unreleased_changes = False
try:
with open(path) as changelog:
text = changelog.read()
if "## Version {}".format(version) in text:
raise AttributeError(
"{} already contans version {}".format(path, version)
)
with open(path) as changelog:
for line in changelog:
if line.startswith("## Unreleased"):
unreleased_changes = False
elif line.startswith("## "):
break
elif len(line.strip()) > 0:
unreleased_changes = True

except FileNotFoundError:
print("file missing: {}".format(path))
return

if unreleased_changes:
print("updating: {}".format(path))
text = re.sub("## Unreleased", new_entry, text)
with open(path, "w") as changelog:
changelog.write(text)


def update_changelogs(targets, version):
print("updating CHANGELOG")
today = datetime.now().strftime("%Y-%m-%d")
new_entry = "## Unreleased\n\n## Version {}\n\nReleased {}".format(
version, today
)
errors = False
for target in targets:
try:
update_changelog(
"{}/CHANGELOG.md".format(target), version, new_entry
)
except Exception as err: # pylint: disable=broad-except
print(str(err))
errors = True

if errors:
sys.exit(1)


def find(name, path):
for root, _, files in os.walk(path):
if name in files:
return os.path.join(root, name)
return None


def update_version_files(targets, version):
print("updating version.py files")
update_files(
targets,
version,
"version.py",
"__version__ .*",
'__version__ = "{}"'.format(version),
)


def update_dependencies(targets, version):
print("updating dependencies")
update_files(
targets,
version,
"setup.cfg",
r"(opentelemetry-.*)= (.*)",
r"\1= " + version,
)


def update_files(targets, version, filename, search, replace):
errors = False
for target in targets:
curr_file = find(filename, target)
if curr_file is None:
print("file missing: {}/{}".format(target, filename))
continue

with open(curr_file) as _file:
text = _file.read()

if version in text:
print("{} already contans version {}".format(curr_file, version))
errors = True
continue

with open(curr_file, "w") as _file:
_file.write(re.sub(search, replace, text))

if errors:
sys.exit(1)


def release_args(args):
print("preparing release")

rootpath = find_projectroot()
targets = list(find_targets_unordered(rootpath))
version = args.version
update_dependencies(targets, version)
update_version_files(targets, version)
update_changelogs(targets, version)


def test_args(args):
clean_remainder_args(args.pytestargs)
execute_args(
Expand Down
62 changes: 9 additions & 53 deletions scripts/prepare_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,57 +21,6 @@ if [[ ! "${VERSION}" =~ ^([0-9])(\.*[0-9]{1,5}[a-b]*){1,3}$ ]]; then
exit 1
fi

function update_version_file() {
errors=0
for f in `find . -name version.py`; do
# check if version is already in version.py
grep -q ${VERSION} $f;
rc=$?
if [ $rc == 0 ]; then
errors=1
echo "${f} already contains ${VERSION}"
continue
fi
# update version.py
perl -i -pe "s/__version__.*/__version__ = \"${VERSION}\"/g" ${f};
git add ${f};
echo "Updating ${f}"
done
if [ ${errors} != 0 ]; then
echo "::set-output name=version_updated::0"
exit 0
fi
}

function update_changelog() {
errors=0
RELEASE_DATE=`date +%F`
for f in `find . -name CHANGELOG.md`; do
# check if version is already in CHANGELOG
grep -q ${VERSION} $f;
rc=$?
if [ $rc == 0 ]; then
errors=1
echo "${f} already contains ${VERSION}"
continue
fi
# check if changelog contains any new details
changes=`sed -n '/## Unreleased/,/^##/p' ${f} | grep -v '^##' | wc -w | awk '{$1=$1;print}'`
if [ ${changes} != "0" ]; then
# update CHANGELOG.md
perl -i -pe 's/## Unreleased.*/## Unreleased\n\n## '${VERSION}'\n\nReleased '${RELEASE_DATE}'/' ${f};
git add ${f};
echo "Updating ${f}"
else
echo "Skipping ${f}, no changes detected"
fi
done
if [ ${errors} != 0 ]; then
echo "::set-output name=version_updated::0"
exit 0
fi
}

# create the release branch
git fetch origin master
git checkout master
Expand All @@ -81,8 +30,15 @@ git push origin release/${VERSION}

# create a temporary branch to create a PR for updated version and changelogs
git checkout -b release/${VERSION}-auto
update_version_file
update_changelog
./scripts/eachdist.py release --version ${VERSION}
rc=$?
if [ $rc != 0 ]; then
echo "::set-output name=version_updated::0"
exit 0
fi

git add **/version.py **/setup.cfg **/CHANGELOG.md

git commit -m "updating changelogs and version to ${VERSION}"

echo "Time to create a release, here's a sample title:"
Expand Down

0 comments on commit 4464220

Please sign in to comment.