diff --git a/cmd/perfApp/perfApp.go b/cmd/perfApp/perfApp.go index bd8ebeb..e8c65b9 100644 --- a/cmd/perfApp/perfApp.go +++ b/cmd/perfApp/perfApp.go @@ -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 { diff --git a/internal/perf/db.go b/internal/perf/db.go index f8153bf..db0a8dc 100644 --- a/internal/perf/db.go +++ b/internal/perf/db.go @@ -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)