Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Patch for issue #48 Enable logging of SQL statements #173

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 6 additions & 4 deletions docs/deployment/@relengapi/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ This is effective for development, but certainly not for production.
The database for the relengapi core is named ``relengapi``.
Other blueprints may require additional URIs.

If you ever need to see what SQLAlchemy is doing with the connection pool, it is useful to enable the logging. To do that make sure you have the ``SQLALCHEMY_DB_LOG`` is flag to set to True.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can see, sqlalchemy always logs at the INFO level. So I think this is more flexibility than the user needs, and your earlier use of a boolean flag is probably the best solution.

.. _Deployment-Authentication:

Authentication
Expand Down Expand Up @@ -130,19 +132,19 @@ The configuration looks like this::

# Base LDAP URI
'uri': "ldaps://your.ldap.server/",

# This needs to be a user that has sufficient rights to read users and groups
'login_dn': "<dn for bind user>",
'login_password': "<password for bind user>",

# The search bases for users and groups, respectively
'user_base': 'o=users,dc=example,dc=com',
'group_base': 'o=groups,dc=example,dc=com',

# set this to True for extra logging
'debug': False,
}

Permissions are cumulative: a person has a permission if they are a member of any group configured with that permission.
In the example above, a user in both ``team_relops`` and ``team_releng`` would have permission to create tasks and to issue and view tokens.
The group name ``<everyone>`` is treated specially: it grants permission to all authenticated users, regardless of authentication mechanism.
Expand Down
7 changes: 7 additions & 0 deletions relengapi/lib/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
from sqlalchemy.orm import scoping
from sqlalchemy.pool import Pool


# db logging
logger = logging.getLogger(__name__)
logging.basicConfig()


class _QueryProperty(object):
Expand Down Expand Up @@ -75,6 +78,10 @@ def _get_db_config(self, dbname):

@synchronized(threading.Lock())
def engine(self, dbname):
# Get the log level for db logs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid multiple logger for sql engine, I thought it would better to create it when the db is getting created.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think this makes sense.

if self.app.config.get('SQLALCHEMY_DB_LOG'):
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)

if dbname not in self._engines:
uri = self._get_db_config(dbname)
self._engines[dbname] = sa.create_engine(uri)
Expand Down
6 changes: 6 additions & 0 deletions settings_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
# configuration is present, is to use '*.db' files in the directory containing
# the RelengAPI source code.

# set the flag True for logging SQLAlchemy engine activities
# default it is set to True
SQLALCHEMY_DB_LOG = True

# ===== Authentication and Authorization =====

RELENGAPI_AUTHENTICATION = {
Expand All @@ -36,3 +40,5 @@
# ===== Celery =====
# Any Celery configuration option can be included here; see
# http://docs.celeryproject.org/en/master/configuration.html#configuration