Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

[-] fix connection string parsing for postgres-continuous-discovery, closes #584 #585

Merged
merged 1 commit into from
Mar 6, 2023
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
21 changes: 20 additions & 1 deletion pgwatch2/pgwatch2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4526,9 +4526,28 @@ func ResolveDatabasesFromConfigEntry(ce MonitoredDatabase) ([]MonitoredDatabase,
if err != nil {
return md, err
}

for _, d := range data {
mainConnString := ce.LibPQConnStr
var parsedConnString string
if len(mainConnString) > 0 {
if strings.Contains(mainConnString, "postgres://") || strings.Contains(mainConnString, "postgresql://") {
parsedConnString, err = pq.ParseURL(mainConnString)
if err != nil {
return nil, err
}
} else {
parsedConnString = mainConnString
}
if strings.Contains(parsedConnString, "dbname=") {
dbRegex := regexp.MustCompile(`dbname=\'?\w+\'?`)
parsedConnString = dbRegex.ReplaceAllString(parsedConnString, fmt.Sprintf("dbname='%s'", d["datname"].(string)))
} else {
parsedConnString += fmt.Sprintf(" dbname='%s'", d["datname"].(string))
}
}

md = append(md, MonitoredDatabase{
LibPQConnStr: parsedConnString,
DBUniqueName: ce.DBUniqueName + "_" + d["datname_escaped"].(string),
DBUniqueNameOrig: ce.DBUniqueName,
DBName: d["datname"].(string),
Expand Down