Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch metrics for multiple databases #88

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

ydkn
Copy link

@ydkn ydkn commented Apr 30, 2019

Pull Request Checklist

General

  • [ x] Update Changelog following the conventions laid out here

  • [ x] Update README with any necessary configuration snippets

  • [ x] Binstubs are created if needed

  • [x ] RuboCop passes

  • [ x] Existing tests pass

Purpose

Allow to specify multiple databases separated by a semicolon instead of only one database to gather metrics from.

Known Compatibility Issues

If the database CLI argument (-p, --db) was not set now metrics for all databases are returned.
Suggestions how to be more backward compatible are welcome!

locks_per_type[lock_name] = row['count']
databases = pgdatabases
con = PG.connect(host: config[:hostname],
dbname: databases.first,
Copy link
Member

Choose a reason for hiding this comment

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

why only the first database?

Copy link
Author

Choose a reason for hiding this comment

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

The first database from the list is simply used to make a valid connection and the locks statistics are then queried through SQL statements for all databases. It is simply not necessary to make individual connections for each database. Please see line 99-103 for the queries run for each database.

Copy link
Member

Choose a reason for hiding this comment

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

ah gotcha, that makes sense, would not hurt to add a comment about that. I will review this in greater detail when I have more time. Is there any way we can provide backwards compatibility?

Copy link
Author

Choose a reason for hiding this comment

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

I currently see two possible options:

Option 1:
Require the user to set the --db option to * if all databases should be checked. If it is not set to * the current behaviour is retained.
But in lib/sensu-plugins-postgres/pgpass.rb there is a check for * to switch to fallbacks and to be consistent the switch to fallbacks should no longer be done which will also introduce a breaking change (with less users affected).

Option 2:
Add a new option e.g. --all-databases which will override the --db option. This means the user has to specify the --all-databases option if he really would like to get metrics for all databases or use the existing --db option to list database names explicitly.

Also Option 1 has the advantage over Option 2 that it is easier to parameterize the check through tokens if there is no option to invalidate/override another.

Let me know what you think or if you have another idea.

Copy link
Member

Choose a reason for hiding this comment

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

I think its a trade off between backwards compatibility and code readability I tend to prefer to not break users regardless of how small the numbers are unless there is a compelling reason.

@phumpal
Copy link
Contributor

phumpal commented Jun 23, 2019

Seems like the conversation is paused. Any update @majormoses @ydkn ?

option :database,
description: 'Database name',
option :databases,
description: 'Database names, separated by ";"',
Copy link
Member

Choose a reason for hiding this comment

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

I am thinking it might be safer to pass it with a comma separated list? Is it because we are passing this as raw SQL?

Copy link
Author

Choose a reason for hiding this comment

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

You're right, using "," as separator is better than ";".
Also it was not escaped when used in a query.

I've updated the PR with patches for both.

@ydkn
Copy link
Author

ydkn commented Jan 14, 2020

PR updated to be compatible with current master (fbc7833)

Copy link
Member

@majormoses majormoses left a comment

Choose a reason for hiding this comment

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

Looks good, a couple more updates and we should be able to get this over the line.

con = PG.connect(host: config[:hostname],
dbname: config[:database],
dbname: databases.first,
Copy link
Member

Choose a reason for hiding this comment

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

I think this still needs to be updated right?

Copy link
Author

Choose a reason for hiding this comment

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

Updated in which way? It connects to the first DB and then queries the information for all databases. There is no need to connect to each DB individually.

con = PG.connect(host: config[:hostname],
dbname: config[:database],
dbname: databases.first,
Copy link
Member

Choose a reason for hiding this comment

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

I think this still needs to be updated right?

Copy link
Author

Choose a reason for hiding this comment

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

Updated in which way? It connects to the first DB and then queries the information for all databases. There is no need to connect to each DB individually.

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
ydkn and others added 2 commits January 15, 2020 11:07
Co-Authored-By: Ben Abrams <[email protected]>
Co-Authored-By: Ben Abrams <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants