Skip to content

Commit aea6fae

Browse files
Recover when connection cannot be established straight at startup (prometheus-community#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 <[email protected]>
1 parent f188bde commit aea6fae

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

cmd/postgres_exporter/postgres_exporter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1624,12 +1624,12 @@ func (e *Exporter) discoverDatabaseDSNs() []string {
16241624
continue
16251625
}
16261626

1627-
dsns[dsn] = struct{}{}
16281627
server, err := e.servers.GetServer(dsn)
16291628
if err != nil {
16301629
log.Errorf("Error opening connection to database (%s): %v", loggableDSN(dsn), err)
16311630
continue
16321631
}
1632+
dsns[dsn] = struct{}{}
16331633

16341634
// If autoDiscoverDatabases is true, set first dsn as master database (Default: false)
16351635
server.master = true

0 commit comments

Comments
 (0)