mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-04-07 09:41:52 +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"
|
||||
"math"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@ -996,7 +997,12 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
|
||||
|
||||
db, err := getDB(e.dsn)
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user