1
0
mirror of https://github.com/prometheus-community/postgres_exporter.git synced 2025-08-09 15:42:47 +03:00

Recover when connection cannot be established straight at startup (#415)

When the connection to the PostgreSQL instance cannot be established straight
at startup, a race condition can happen when autoDiscoverDatabases is true. If
discoverDatabaseDSNs fails, no dsn is set as the master database, and, if
scrapeDSN succeeds, checkMapVersions will have omitted the default metrics in
the server metric map. The metric map won't be updated unless the version
returned by the PostgreSQL instance changes. With this patch, scrapeDSN won't
be run unless discoverDatabaseDSNs succeeded and thus the race condition is
eliminated.

Signed-off-by: Yann Soubeyrand <yann.soubeyrand@camptocamp.com>
This commit is contained in:
Yann Soubeyrand
2020-12-24 16:41:05 +01:00
committed by GitHub
parent f188bdef53
commit aea6fae7d6

View File

@@ -1624,12 +1624,12 @@ func (e *Exporter) discoverDatabaseDSNs() []string {
continue
}
dsns[dsn] = struct{}{}
server, err := e.servers.GetServer(dsn)
if err != nil {
log.Errorf("Error opening connection to database (%s): %v", loggableDSN(dsn), err)
continue
}
dsns[dsn] = struct{}{}
// If autoDiscoverDatabases is true, set first dsn as master database (Default: false)
server.master = true