Skip to content

Commit

Permalink
Add OpenTelemetry support
Browse files Browse the repository at this point in the history
JIRA: RHELWF-10556
  • Loading branch information
hluk committed Feb 2, 2024
1 parent 44c38b2 commit 1fc69a1
Show file tree
Hide file tree
Showing 11 changed files with 1,117 additions and 243 deletions.
132 changes: 72 additions & 60 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
product-listings-manager
========================

.. image:: https://copr.fedorainfracloud.org/coprs/ktdreyer/product-listings-manager/package/product-listings-manager/status_image/last_build.png
:target: https://copr.fedorainfracloud.org/coprs/ktdreyer/product-listings-manager/package/product-listings-manager/

.. image:: https://quay.io/repository/redhat/product-listings-manager/status
:target: https://quay.io/repository/redhat/product-listings-manager
.. image:: https://quay.io/repository/factory2/product-listings-manager/status
:target: https://quay.io/repository/factory2/product-listings-manager

.. image:: https://coveralls.io/repos/github/release-engineering/product-listings-manager/badge.svg?branch=master
:target: https://coveralls.io/github/release-engineering/product-listings-manager?branch=master
Expand Down Expand Up @@ -53,89 +50,104 @@ Architecture diagram
:height: 364px
:alt: product-listings-manager architecture diagram

Installation and setup
----------------------

1. Install the prerequisite system packages::

$ sudo dnf -y install postgresql-devel krb5-devel rpm-devel gcc python-devel python3-virtualenvwrapper

2. Set up a virtualenv::

$ mkvirtualenv -p python3 plm

... Run ``source /usr/bin/virtualenvwrapper.sh`` if ``mkvirtualenv`` command not available

3. Install the prerequisite packages::
Running the tests
-----------------

$ workon plm
$ pip install -r requirements.txt
You can invoke the tests with ``tox``::

4. Create ``config.py`` with the database settings::
$ tox

$ echo "SQLALCHEMY_DATABASE_URI = 'postgresql://myusername:mypass@dbhost/dbname'" > config.py
$ vi config.py
Using the ``--live`` argument if you want to run against the live composedb instance::

5. Set the ``PLM_CONFIG_FILE`` environment variable to the full filesystem path of
this new file::
$ tox -e py3 -- --cov=product_listings_manager --live tests

$ export PLM_CONFIG_FILE=$(pwd)/config.py
Running the linters
-------------------

6. Install brewkoji package. This creates ``/etc/koji.conf.d/brewkoji.conf``,
so ``products.py`` can contact the Brew hub::
To run viable linters to check syntax of various files before commit, install
`pre-commit <https://pre-commit.ci/>`__ and run::

$ sudo dnf -y install brewkoji
$ pre-commit install

7. Trust Brew's SSL certificate::
To run linters on all files (not just the ones changed in the last commit),
run::

$ export REQUESTS_CA_BUNDLE=/etc/pki/ca-trust/source/anchors/RH-IT-Root-CA.crt
$ pre-commit run -a

... Or if you've installed this globally on your system, tell requests to use
your global CA store::
Setting up local environment
----------------------------

$ export REQUESTS_CA_BUNDLE=/etc/pki/tls/certs/ca-bundle.crt
You can use ``docker-compose`` or ``podman-compose`` to start:

8. Run the server::
- product-listings-manager - the web service running at ``http://localhost:8080``
- postgres - database for product-listings-manager, initialized with all
``*.sql`` files in ``docker/docker-entrypoint-initdb.d`` directory
- jaeger - collector and query service for OpenTelemetry traces collected from
the local instance of product-listings-manager and the database, running at
``http://localhost:16686``

$ FLASK_APP=product_listings_manager.app flask run
Rebuild product-listings-manager image::

The Flask web server will run on TCP 5000.
$ podman-compose build

You can access the http://localhost:5000/ at that point.
Image rebuild is needed only if dependencies change. The container running in
the compose environment uses the current source code directory.

Running the tests
-----------------
Start the services::

Install required packages for test::
$ podman-compose up

$ pip install -r test-requirements.txt
Show logs::

You can invoke the tests with ``tox``::
$ podman-compose logs plm
$ podman-compose logs plm-db
$ podman-compose logs jaeger

$ tox
Restart product-listings-manager::

Alternatively, you can run pytest directly::
$ podman-compose restart plm

$ pytest --cov=product_listings_manager tests
Stop the services::

Using the ``--live`` argument if you want to run against the live composedb instance::
$ podman-compose up

$ pytest --cov=product_listings_manager --live tests
Configuration
-------------

Running the linters
-------------------
The service is conteinerized application and uses environment variables for
configuration:

To run viable linters to check syntax of various files before commit, install
[pre-commit](https://pre-commit.ci/) and run::
- ``SQLALCHEMY_DATABASE_URI`` - full database URI for SQLAlchemy, for example:
``postgresql://username:password@plm-db.example.com:5433/plm``
- ``OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`` - traces endpoint for OpenTelemetry
tracing, for example: ``https://otel.example.com/v1/traces``
- ``OTEL_EXPORTER_SERVICE_NAME`` - service name for OpenTelemetry tracing
- ``PLM_KOJI_CONFIG_PROFILE`` - Koji profile to use (in ``/etc/koji.conf.d/``
directory), default is ``brew``
- ``PLM_LDAP_HOST`` - LDAP host, for example ``ldaps://ldap.example.com``
- ``PLM_LDAP_SEARCHES`` - JSON formatted array with LDAP search base and search
template, for example:

$ pre-commit install
.. code-block:: json
To run linters on all files (not just the ones changed in the last commit),
run::
["BASE": "ou=Groups,dc=example,dc=com", "SEARCH_STRING": "(memberUid={user})"]
$ pre-commit run -a
- ``PLM_PERMISSIONS`` - JSON formatted array with permissions, for example:

Configuring a local database
----------------------------
.. code-block:: json
See ``database.rst`` for instructions to configure a local postgres instance.
[
{
"name": "admins",
"description": "product-listings-manager admins",
"contact": "plm-admins@example.com",
"queries": ["*"],
"groups": ["plm-admins"],
"users": ["alice", "bob"]
},
{
"name": "viewers",
"queries": ["SELECT *"],
"groups": ["plm-users"]
}
]
181 changes: 0 additions & 181 deletions database.rst

This file was deleted.

0 comments on commit 1fc69a1

Please sign in to comment.