mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-04-21 06:25:32 +00:00
Mask the password field of the connection URL.
This solves the issue where failed connections can leak the database connection string to logs.
This commit is contained in:
parent
030e90f03e
commit
12b95c44d4
@ -8,6 +8,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -996,7 +997,12 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
|
|||||||
|
|
||||||
db, err := getDB(e.dsn)
|
db, err := getDB(e.dsn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Infof("Error opening connection to database (%s): %s", e.dsn, err)
|
loggableDsn := "could not parse DATA_SOURCE_NAME"
|
||||||
|
if pDsn, pErr := url.Parse(e.dsn); pErr != nil {
|
||||||
|
pDsn.User = url.UserPassword(pDsn.User.Username(), "xxx")
|
||||||
|
loggableDsn = pDsn.String()
|
||||||
|
}
|
||||||
|
log.Infof("Error opening connection to database (%s): %s", loggableDsn, err)
|
||||||
e.error.Set(1)
|
e.error.Set(1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user