Skip to content

Commit

Permalink
fix sqlstats sometimes taking wrong DB name
Browse files Browse the repository at this point in the history
  • Loading branch information
majewsky committed Dec 12, 2024
1 parent 8f3ed77 commit 9f39897
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/db/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ func Init() (*sql.DB, error) {
extraConnectionOptions["idle_in_transaction_session_timeout"] = "10000" // 10000 ms = 10 seconds
}

dbName := osext.GetenvOrDefault("LIMES_DB_NAME", "limes")
dbURL, err := easypg.URLFrom(easypg.URLParts{
HostName: osext.GetenvOrDefault("LIMES_DB_HOSTNAME", "localhost"),
Port: osext.GetenvOrDefault("LIMES_DB_PORT", "5432"),
UserName: osext.GetenvOrDefault("LIMES_DB_USERNAME", "postgres"),
Password: os.Getenv("LIMES_DB_PASSWORD"),
ConnectionOptions: os.Getenv("LIMES_DB_CONNECTION_OPTIONS"),
DatabaseName: osext.GetenvOrDefault("LIMES_DB_NAME", "limes"),
DatabaseName: dbName,
})
if err != nil {
return nil, err
Expand All @@ -63,7 +64,7 @@ func Init() (*sql.DB, error) {
if err != nil {
return nil, err
}
prometheus.MustRegister(sqlstats.NewStatsCollector("limes", dbConn))
prometheus.MustRegister(sqlstats.NewStatsCollector(dbName, dbConn))
return dbConn, nil
}

Expand Down

0 comments on commit 9f39897

Please sign in to comment.