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

[postgres] Allow 'host' config value be UNIX socket path #2734

Merged
merged 2 commits into from
Oct 27, 2016

Conversation

DylanFrese
Copy link
Contributor

The PostgreSQL check has been changed to try to connect to the PostgreSQL database via a UNIX socket if the hostname provided in the configuration begins with a forward-slash ('/').

This behaviour is similar to the 'psql' command-line utility. From psql(1):

  --host=hostname
      Specifies the host name of the machine on which the server is
      running. If the value begins with a slash, it is used as the
      directory for the Unix-domain socket.

With the difference being that we interpret it as an exact path, whereas psql interprets it as a directory to look for a socket with a particularly formatted name.

This addresses issue #2361. Arguably, a new configuration parameter, unix_sock or similar, should be added. I chose to do it this way as it touches less code, and is, as mentioned above, similar to how psql does things.

The documentation at Datadog/documentation/content/integrations/postgresql.md should also be updated with the new content of postgres.yaml.example.

The PostgreSQL check has been changed to try to connect to the
PostgreSQL database via a UNIX socket if the hostname provided in the
configuration begins with a forward-slash ('/').

This behaviour is similar to the 'psql' command-line utility. From
psql(1):

  --host=hostname
      Specifies the host name of the machine on which the server is
      running. If the value begins with a slash, it is used as the
      directory for the Unix-domain socket.

With the difference being that we interpret it as an exact path, whereas
psql interprets it as a directory to look for a socket with a
particularly formatted name.
postgres.yaml.example now mentions how one might connect to PostgreSQL
using a UNIX socket.
@truthbk truthbk self-assigned this Aug 8, 2016
@truthbk
Copy link
Member

truthbk commented Aug 8, 2016

Thanks for this @DylanFrese code looks good, we'll talk over whether introducing a new unix_sock parameter makes sense, or if if this is - as it seems - more than enough. Thanks a bunch!

@truthbk truthbk added this to the 5.10.0 milestone Aug 12, 2016
@antifuchs
Copy link
Contributor

I just ran into the problem that this fixes - any chance this could be pulled in sometime? (:

@olivielpeau olivielpeau assigned olivielpeau and unassigned truthbk Oct 26, 2016
@olivielpeau
Copy link
Member

Thanks @DylanFrese, just gave your changes a test run and everything works nicely! Keeping host makes sense to me too, thanks for the thorough explanation.

Merging, this will be part of the next minor release, 5.10.0

Travis is failing but I think the current master fixes the failures. I'll keep an eye on the CI once this is merged

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.

None yet

4 participants