mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-04-01 22:48:15 +00:00
Merge pull request #787 from mothership/fix/mothershipper/support-alt-scheme
Supports alternate postgres:// prefix in URLs
This commit is contained in:
commit
fb316ad4ae
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user