Skip to content

Commit

Permalink
Default to port 5432 and add http handlers when PosgreSQL connection …
Browse files Browse the repository at this point in the history
…is established

Signed-off-by: Raul Sevilla <[email protected]>
  • Loading branch information
rsevilla87 committed Nov 30, 2022
1 parent dc45859 commit 68b309f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
30 changes: 16 additions & 14 deletions cmd/perfApp/perfApp.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,25 @@ func main() {
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGINT)
go handleInterrupt(c)
go func() {
if os.Getenv("POSTGRESQL_RETRY_INTERVAL") != "" {
retryInt, err := strconv.Atoi(os.Getenv("POSTGRESQL_RETRY_INTERVAL"))
if err != nil {
if os.Getenv("POSTGRESQL_HOSTNAME") != "" {
go func() {
if os.Getenv("POSTGRESQL_RETRY_INTERVAL") != "" {
retryInt, err := strconv.Atoi(os.Getenv("POSTGRESQL_RETRY_INTERVAL"))
if err != nil {
utils.ErrorHandler(err)
}
perf.DB.RetryInt = retryInt
}
perf.Connect2Db()
tables = append(tables, euler.Tables, ready.Tables)
if err := perf.CreateTables(tables); err != nil {
utils.ErrorHandler(err)
}
perf.DB.RetryInt = retryInt
}
perf.Connect2Db()
tables = append(tables, euler.Tables, ready.Tables)
if err := perf.CreateTables(tables); err != nil {
utils.ErrorHandler(err)
}
}()
}()
http.HandleFunc("/euler", euler.Handler)
http.HandleFunc("/ready", ready.Handler)
}
http.Handle("/metrics", promhttp.Handler())
http.HandleFunc("/euler", euler.Handler)
http.HandleFunc("/ready", ready.Handler)
http.HandleFunc("/health", health.Handler)
log.Printf("Listening at 8080")
if err := http.ListenAndServe(":8080", nil); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/perf/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const dbTImeout = 10

// Connect2Db Connects to a Postgres database using DBInfo
func Connect2Db() {
if DB.DBPort == "" {
DB.DBPort = "5432"
}
connStr := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=disable connect_timeout=%d", DB.DBUser, DB.DBPassword, DB.DBHost, DB.DBPort, DB.DBName, dbTImeout)
for {
log.Infof("Connecting with database %s:%s", DB.DBHost, DB.DBPort)
Expand Down

0 comments on commit 68b309f

Please sign in to comment.