Skip to content

Supports alternate postgres:// prefix in URLs #787

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/postgres_exporter/datasource.go
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ func (e *Exporter) discoverDatabaseDSNs() []string {
var dsnURI *url.URL
var dsnConnstring string

if strings.HasPrefix(dsn, "postgresql://") {
if strings.HasPrefix(dsn, "postgresql://") || strings.HasPrefix(dsn, "postgres://") {
var err error
dsnURI, err = url.Parse(dsn)
if err != nil {
2 changes: 1 addition & 1 deletion config/dsn.go
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ func (d DSN) GetConnectionString() string {
// dsnFromString parses a connection string into a dsn. It will attempt to parse the string as
// a URL and as a set of key=value pairs. If both attempts fail, dsnFromString will return an error.
func dsnFromString(in string) (DSN, error) {
if strings.HasPrefix(in, "postgresql://") {
if strings.HasPrefix(in, "postgresql://") || strings.HasPrefix(in, "postgres://") {
return dsnFromURL(in)
}

13 changes: 13 additions & 0 deletions config/dsn_test.go
Original file line number Diff line number Diff line change
@@ -186,6 +186,19 @@ func Test_dsnFromString(t *testing.T) {
},
wantErr: false,
},
{
name: "Alternative URL prefix",
input: "postgres://user:s3cret@host.example.com:5432/tsdb?user=postgres",
want: DSN{
scheme: "postgres",
host: "host.example.com:5432",
path: "/tsdb",
query: url.Values{},
username: "user",
password: "s3cret",
},
wantErr: false,
},
{
name: "URL with user and password in query string",
input: "postgresql://host.example.com:5432/tsdb?user=postgres&password=s3cr3t",