Navigation Menu

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

Pg Check #6

Closed
wants to merge 5 commits into from
Closed

Pg Check #6

wants to merge 5 commits into from

Conversation

Dan-Ailenei
Copy link

Created a separate check, postgres specific to solve a bug where the postgres server would start but the database itself woudln't.

Copy link
Owner

@ionelmc ionelmc left a comment

Choose a reason for hiding this comment

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

Added some comments.

@@ -237,6 +270,12 @@ def parse_value(value, proto):
raise argparse.ArgumentTypeError('Invalid service spec %r. Port must be a number.' % value)
port = int(port)
return TcpCheck(host, port)
elif proto == 'postgresql':
Copy link
Owner

Choose a reason for hiding this comment

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

For convenience a "pg" protocol should also be allowed.

Copy link
Owner

Choose a reason for hiding this comment

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

Also "postgres" (cause they allow it), and we normalize to "postgresql" internally.

@@ -237,6 +270,12 @@ def parse_value(value, proto):
raise argparse.ArgumentTypeError('Invalid service spec %r. Port must be a number.' % value)
port = int(port)
return TcpCheck(host, port)
elif proto == 'postgresql':
user, password, host, port, dbname = value.strip('/').split(':', 4)
Copy link
Owner

Choose a reason for hiding this comment

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

I think we should have a different syntax. For tcp protocol it's very clear and simple to parse (host:port) but for postgres we have to many things. postgres://user:password:host:port:dbname is not really intuitive.

Fortunately psycopg2 supports DSNs (https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING) so we can just use those and not do any parsing at all.

Parse with psycopg2.extensions.make_dsn and just pass its result to psycopg2.connect.

def is_fatal_error(self, error):
representation = repr(error)
if 'password authentication failed' in representation or\
'database "{0}" does not exist'.format(self.database) in representation:
Copy link
Owner

Choose a reason for hiding this comment

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

Considering that db not existing is analogous to dns failing to resolve a hostname, and auth failures is analogous to permission denied errors when checking file/uds (the file/unix checks) then it would be inconsistent to have this distinction on failures.

It also makes code more complicated, lets revert it.

revert additional error checks
This reverts commit 3eb65ef.
@codecov-io
Copy link

codecov-io commented May 21, 2019

Codecov Report

Merging #6 into master will decrease coverage by 2.75%.
The diff coverage is 42.3%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #6      +/-   ##
==========================================
- Coverage   89.68%   86.93%   -2.76%     
==========================================
  Files           4        4              
  Lines         349      375      +26     
  Branches       60       62       +2     
==========================================
+ Hits          313      326      +13     
- Misses         22       34      +12     
- Partials       14       15       +1
Impacted Files Coverage Δ
src/holdup/cli.py 83.19% <42.3%> (-5.02%) ⬇️
tests/test_holdup.py 96.21% <0%> (+1.51%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f2d95f...ebd680f. Read the comment docs.

uri = 'postgresql://{}'.format(value)
try:
connection_uri = make_dsn(uri)
except ProgrammingError:
Copy link
Owner

@ionelmc ionelmc May 22, 2019

Choose a reason for hiding this comment

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

Should capture all exceptions (except Exception as exc:) and raise argparse.ArgumentTypeError("Failed to parse %s: %s. Expected format is blabla" % (value, exc)) or similar.

@ionelmc
Copy link
Owner

ionelmc commented May 22, 2019

Rebased in master (as d1f5f23 - 6fe7704).

@ionelmc ionelmc closed this May 22, 2019
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.

None yet

3 participants