Skip to content

Commit

Permalink
Updates supporting release 23.3.0 (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
claws authored Mar 14, 2023
1 parent 66c04c8 commit 4786678
Show file tree
Hide file tree
Showing 46 changed files with 348 additions and 1,675 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -39,17 +39,10 @@ jobs:
- name: Check code style
run: |
make check-style
- name: Install package on Python 3.6
# Quart is not supported on Python 3.6
if: ${{ matrix.python-version == '3.6' }}
run: |
echo "Python version is: ${{ matrix.python-version }}"
pip install .[aiohttp,binary,starlette]
- name: Install package
if: ${{ matrix.python-version != '3.6' }}
run: |
echo "Python version is: ${{ matrix.python-version }}"
pip install .[aiohttp,binary,starlette,quart]
pip install .[aiohttp,starlette,quart]
- name: Run unit tests
run: |
make test
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
matrix:
python-version: ["3.9"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ suggestion-mode=yes

disable=invalid-name,
broad-except,
broad-exception-raised,
duplicate-code,
logging-fstring-interpolation,
missing-class-docstring,
missing-module-docstring,
missing-function-docstring,
no-self-use,
too-many-instance-attributes,
too-many-arguments,
too-few-public-methods,
Expand Down
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@

## XX.Y.Z

## 23.3.0

- Added support for Histogram metric in timer decorator
- Update docs to demonstrate how to use basic authentication with Pusher.
- Developer updates
- Removed isort optional extra 'deprecated_imports_finder' as it isn't supported anymore.
- Minor type annotations updates to keep mypy happy
- Updated '.pylintrc' to fix warnings about options that are no longer supported.
- Updated Sphinx config to specify language to avoid warning being reported.
- Minor updates to address pylint warnings
- Silence orjson no-members warnings (See: https://github.com/ijl/orjson/issues/248)
- Added httpx as developmental dependency so that the Starlette test client can be used.
- Update ASGI middleware to obtain starlette app reference from 'http' ASGI scope when run from Starlette test client.
- Updated Pusher unit test to check basic authentication.
- Added aiohttp_basicauth to dev dependencies.
- Fix CI
- Removed support for Python3.6 as it isn't supported by Github actions anymore.
- Updated repo to indicate minimum supported Python is 3.8+
- Removed dependency on asynctest package which is no longer maintained and causes errors in Python3.11.
- Using 'unittest.IsolatedAsyncioTestCase' instead, but this is only supported for 3.8+.
- Updated CI workflow 'uses' items to use later versions
- Prometheus 2.0 removed support for the binary protocol. Removed support for Prometheus binary protocol (fixes #57).
- Updated unit tests
- Updated CI
- Updated docs
- Updated examples

## 22.5.0

- Fix CI package install issue related to pip (#78)
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This makefile has been created to help developers perform common actions.
# It assumes it is operating in an environment, such as a virtual env,
# where the python command links to the Python3.7 executable.
# where the python command links to the Python3.11 executable.


# Do not remove this block. It is used by the 'help' rule when
Expand All @@ -9,7 +9,7 @@
# help: aioprometheus Makefile help
# help:

PYTHON_VERSION := python3.9
PYTHON_VERSION := python3.11
VENV_DIR := venv

# help: help - display this makefile's help information
Expand All @@ -22,9 +22,9 @@ help:
.PHONY: venv
venv:
@rm -Rf "$(VENV_DIR)"
@$(PYTHON_VERSION) -m venv "$(VENV_DIR)"
@$(PYTHON_VERSION) -m venv "$(VENV_DIR)" --prompt aioprom
@/bin/bash -c "source $(VENV_DIR)/bin/activate && pip install pip --upgrade && pip install -r requirements.dev.txt"
@/bin/bash -c "source $(VENV_DIR)/bin/activate && pip install -e .[aiohttp,binary,starlette,quart]"
@/bin/bash -c "source $(VENV_DIR)/bin/activate && pip install -e .[aiohttp,starlette,quart]"
@echo "Enter virtual environment using:\n\n\t$ source $(VENV_DIR)/bin/activate\n"


Expand Down
28 changes: 9 additions & 19 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ aioprometheus
`aioprometheus` is a Prometheus Python client library for asyncio-based
applications. It provides metrics collection and serving capabilities for
use with Prometheus and compatible monitoring systems. It supports exporting
metrics into text and binary formats and pushing metrics to a gateway.
metrics into text and pushing metrics to a gateway.

The ASGI middleware in `aioprometheus` can be used in FastAPI/Starlette and
Quart applications. `aioprometheus` can also be used in other kinds of asyncio
Expand Down Expand Up @@ -50,20 +50,11 @@ dependencies are not installed by default. You can install them alongside
$ pip install aioprometheus[aiohttp]
Prometheus 2.0 removed support for the binary protocol, so in version 20.0.0 the
dependency on `prometheus-metrics-proto`, which provides binary support, is now
optional. If you need binary response support, for use with an older Prometheus,
you will need to specify the 'binary' optional extra:

.. code-block:: console
$ pip install aioprometheus[binary]
Multiple optional dependencies can be listed at once, such as:

.. code-block:: console
$ pip install aioprometheus[aiohttp,binary,starlette,quart]
$ pip install aioprometheus[aiohttp,starlette,quart]
Usage
Expand Down Expand Up @@ -159,9 +150,15 @@ The next example shows how to use the Service HTTP endpoint to provide a
dedicated metrics endpoint for other applications such as long running
distributed system processes.

The Service object requires optional extras to be installed so make sure you
install aioprometheus with the 'aiohttp' extras.

.. code-block:: console
$ pip install aioprometheus[aiohttp]
.. code-block:: python
#!/usr/bin/env python
"""
This example demonstrates how the ``aioprometheus.Service`` can be used to
expose metrics on a HTTP endpoint.
Expand Down Expand Up @@ -226,13 +223,6 @@ the Service uses the default collector registry, which is
``aioprometheus.REGISTRY``. The Service can be configured to use a different
registry by passing one in as an argument to the Service constructor.

The Service object requires optional extras to be installed so make sure you
install aioprometheus with the 'aiohttp' extras.

.. code-block:: console
$ pip install aioprometheus[aiohttp]

License
-------
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = "en"

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
Expand Down
7 changes: 4 additions & 3 deletions docs/dev/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ If you have found a bug or have an idea for an enhancement that would
improve the library, use the
`bug tracker <https://github.com/claws/aioprometheus/issues>`_.

To develop `aioprometheus` you'll need Python 3.6+, some dependencies and
To develop `aioprometheus` you'll need Python 3.8+, some dependencies and
the source code.


Expand Down Expand Up @@ -41,6 +41,7 @@ commands are pointing at the correct tools.
$ source venv/bin/activate
(aioprom) $
(aioprom) $ pip install pip --upgrade
(aioprom) $ pip install wheel
.. note::

Expand All @@ -56,13 +57,13 @@ Rules in the convenience Makefile depend on the development dependencies
being installed. The development dependencies also include various web
application frameworks to assist verifying integration methods. Install the
developmental dependencies using ``pip``. Then install the `aioprometheus`
package (and its optional dependencies). in a way that allows you to edit the
package (and its optional dependencies) in a way that allows you to edit the
code after it is installed so that any changes take effect immediately.

.. code-block:: console
(aioprom) $ pip install -r requirements.dev.txt
(aioprom) $ pip install -e .[aiohttp,binary]
(aioprom) $ pip install -e .[aiohttp,starlette,quart]
Code Style
Expand Down
10 changes: 5 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ aioprometheus
`aioprometheus` is a Prometheus Python client library for asyncio-based
applications. It provides metrics collection and serving capabilities for
use with `Prometheus <https://prometheus.io/>`_ and compatible monitoring
systems. It supports exporting metrics into text and binary formats and
pushing metrics to a gateway.
systems. It supports exporting metrics into text format and pushing metrics
to a gateway.

`aioprometheus` can be used in applications built with FastAPI/Starlette,
Quart, aiohttp as well as networking apps built upon asyncio.
Expand All @@ -41,9 +41,9 @@ Origins
package. Many thanks to `slok <https://github.com/slok>`_ for developing
`prometheus-python`.

The original work has been modified and updated it to meet the needs of asyncio
applications by adding the histogram metric, binary format support, docs,
decorators, ASGI middleware, etc.
The original work has been modified and updated to support the needs of
asyncio applications by adding the histogram metric, docs, decorators, ASGI
middleware, etc.


.. |ci status| image:: https://github.com/claws/aioprometheus/workflows/CI%20Pipeline/badge.svg?branch=master
Expand Down
46 changes: 31 additions & 15 deletions docs/user/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,11 @@ dependencies are not installed by default. You can install them alongside
$ pip install aioprometheus[aiohttp]
Prometheus 2.0 removed support for the binary protocol, so in version 20.0.0 the
dependency on `prometheus-metrics-proto`, which provides binary support, is now
optional. If you need binary response support, for use with an older Prometheus,
you will need to specify the 'binary' optional extra:

.. code-block:: console
$ pip install aioprometheus[binary]
Multiple optional dependencies can be listed at once, such as:

.. code-block:: console
$ pip install aioprometheus[aiohttp,binary,starlette,quart]
$ pip install aioprometheus[aiohttp,starlette,quart]
.. _usage-label:
Expand Down Expand Up @@ -484,13 +475,38 @@ install aioprometheus with the 'aiohttp' extras.
from aioprometheus.pusher import Pusher
PUSH_GATEWAY_ADDR = "http://127.0.0.1:61423"
pusher = Pusher("my-job", PUSH_GATEWAY_ADDR, grouping_key={"instance": "127.0.0.1:1234"})
c = Counter("total_requests", "Total requests.", {})
c.inc({'url': "/p/user"})
async def main():
pusher = Pusher("my-job", PUSH_GATEWAY_ADDR, grouping_key={"instance": "127.0.0.1:1234"})
c = Counter("total_requests", "Total requests.", {})
c.inc({'url': "/p/user"})
resp = await pusher.replace(REGISTRY)
if __name__ == "__main__":
asyncio.run(main())
The Pusher API supports passing 'kwargs' on to the underlying client session
used to push updates to the Gateway. This feature provides the ability to
supply configuration information such as authentication parameters. The example
code below shows how you can use basic authentication with the Pusher.

.. code-block:: python
import aiohttp
from aioprometheus import REGISTRY, Counter
from aioprometheus.pusher import Pusher
PUSH_GATEWAY_ADDR = "http://127.0.0.1:61423"
AUTH = aiohttp.BasicAuth("Joe", password="4321")
async def main():
pusher = Pusher("my-job", PUSH_GATEWAY_ADDR)
c = Counter("total_requests", "Total requests.", {})
c.inc({'url': "/p/user"})
resp = await pusher.replace(REGISTRY, auth=AUTH)
# Push to the push gateway
resp = await pusher.replace(REGISTRY)
if __name__ == "__main__":
asyncio.run(main())
Using Prometheus To Check Examples
Expand Down
5 changes: 3 additions & 2 deletions examples/decorators/decorator_count_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
"""
Usage:
.. code-block:: python
$ python decorator_count_exceptions.py
Expand Down Expand Up @@ -30,6 +31,7 @@
)
REQUESTS = Counter("request_total", "Total number of requests")


# Decorate function with metric.
@count_exceptions(REQUEST_EXCEPTIONS, {"route": "/"})
async def handle_request(duration):
Expand All @@ -52,7 +54,6 @@ async def handle_requests():


if __name__ == "__main__":

loop = asyncio.get_event_loop()

svr = Service()
Expand Down
5 changes: 3 additions & 2 deletions examples/decorators/decorator_inprogress.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
"""
Usage:
.. code-block:: python
$ python decorator_inprogress.py
Expand All @@ -26,6 +27,7 @@
REQUESTS_IN_PROGRESS = Gauge("request_in_progress", "Number of requests in progress")
REQUESTS = Counter("request_total", "Total number of requests")


# Decorate function with metric.
@inprogress(REQUESTS_IN_PROGRESS, {"route": "/"})
async def handle_request(duration):
Expand All @@ -43,7 +45,6 @@ async def handle_requests():


if __name__ == "__main__":

loop = asyncio.get_event_loop()

svr = Service()
Expand Down
3 changes: 1 addition & 2 deletions examples/decorators/decorator_timer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
"""
Usage:
Expand Down Expand Up @@ -31,6 +30,7 @@
REQUEST_TIME = Summary("request_processing_seconds", "Time spent processing request")
REQUESTS = Counter("request_total", "Total number of requests")


# Decorate function with metric.
@timer(REQUEST_TIME)
async def handle_request(duration):
Expand All @@ -48,7 +48,6 @@ async def handle_requests():


if __name__ == "__main__":

loop = asyncio.get_event_loop()

svr = Service()
Expand Down
1 change: 0 additions & 1 deletion examples/frameworks/aiohttp-example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
"""
Sometimes you may not want to expose Prometheus metrics from a dedicated
Prometheus metrics server but instead want to use an existing web framework.
Expand Down
Loading

0 comments on commit 4786678

Please sign in to comment.