inject augur and version into engine connection args#3771
inject augur and version into engine connection args#3771
Conversation
based on https://stackoverflow.com/questions/15685861/setting-application-name-on-postgres-sqlalchemy Signed-off-by: Adrian Edwards <[email protected]>
Signed-off-by: Adrian Edwards <[email protected]>
Signed-off-by: Adrian Edwards <[email protected]>
|
|
||
| url = get_database_string() | ||
| temporary_database_engine = create_database_engine(url=url, poolclass=StaticPool) | ||
| temporary_database_engine = create_database_engine(url=url, poolclass=StaticPool, connect_args={"application_name": f"augur v{__version__} temporary"}) |
There was a problem hiding this comment.
[pylint] reported by reviewdog 🐶
W0621: Redefining name 'temporary_database_engine' from outer scope (line 44) (redefined-outer-name)
Signed-off-by: Adrian Edwards <[email protected]>
|
|
||
| url = get_database_string() | ||
| temporary_database_engine = create_database_engine(url=url, poolclass=StaticPool) | ||
| temporary_database_engine = create_database_engine(url=url, poolclass=StaticPool, connect_args={"application_name": f"augur v{__version__} temporary"}) |
There was a problem hiding this comment.
[pylint] reported by reviewdog 🐶
W0621: Redefining name 'temporary_database_engine' from outer scope (line 42) (redefined-outer-name)
|
|
||
| url = get_database_string() | ||
| temporary_database_engine = create_database_engine(url=url, poolclass=StaticPool) | ||
| temporary_database_engine = create_database_engine(url=url, poolclass=StaticPool, connect_args={"application_name": f"augur v{__version__} temporary"}) |
There was a problem hiding this comment.
[pylint] reported by reviewdog 🐶
E0602: Undefined variable 'version' (undefined-variable)
|
|
||
| url = get_database_string() | ||
| temporary_database_engine = create_database_engine(url=url, poolclass=StaticPool) | ||
| temporary_database_engine = create_database_engine(url=url, poolclass=StaticPool, connect_args={"application_name": f"augur v{__version__} temporary"}) |
There was a problem hiding this comment.
Is __version__ defined or imported anywhere in this file? I don't see it. Wouldn't this raise a NameError at runtime?
There was a problem hiding this comment.
Oh that should probably be removed if it hasn't already. I gave up importing the version except where already available because its in the metadata.py, outside the module structure and therefore hard to properly import
There was a problem hiding this comment.
Yeah! Probably should remove this

When diagnosing #3770, i investigated the seemingly high number of idle postgres tasks. while confirming whether these were a problem, i used dbeaver to view the open sessions on the database. This view in dbeaver has a column for application name (a couple of which were populated with dbeavers own name, for its own db connections).
I think setting augur to identify its own connections this way ( which can be done using https://stackoverflow.com/questions/15685861/setting-application-name-on-postgres-sqlalchemy) is a small change that can would help debugging efforts, especially when multiple things (grafana stack, augur, dbeaver or other user-preferred database tools, researchers) can be accessing an augur database at a time. This may also lightly help debug our "connection leaks" issue (#3452 etc)
This PR adds the string
augurto this field by passing it as a connection argument when we create a database engine.This string may also be followed by some other text indicating which part of augur the database connections are coming from (such as api, cli, etc). While I initially tried to include the version number, This turned out to not be possible as testing revealed that the
metadatafile this version is in is not an actual module that is accessibleNotes for Reviewers
Currently testing this in my local dev instance
Signed commits