Skip to content

inject application name into engine connection args#322

Open
MoralCode wants to merge 1 commit into
mainfrom
qol/postgres_name
Open

inject application name into engine connection args#322
MoralCode wants to merge 1 commit into
mainfrom
qol/postgres_name

Conversation

@MoralCode
Copy link
Copy Markdown
Contributor

based on https://stackoverflow.com/questions/15685861/setting-application-name-on-postgres-sqlalchemy

When diagnosing #248, 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 collectoss 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, collectoss, dbeaver or other user-preferred database tools, researchers) can be accessing the collectoss database at a time. This may also lightly help debug our "connection leaks" issue (#148 etc)

This PR adds the string collectoss to 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 collectoss 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 metadata file this version is in is not an actual module that is accessible

Notes for Reviewers
Was tested previously

Signed commits

  • Yes, I signed my commits.


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"collectoss temporary/testing"})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[pylint] reported by reviewdog 🐶
W0621: Redefining name 'temporary_database_engine' from outer scope (line 42) (redefined-outer-name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant