func (a *API) ping(w http.ResponseWriter, req *http.Request, _ httprouter.Params) { logger := a.logger().New("fn", "ping") logger.Info("checking status", "host", serviceHost) if status, err := sirenia.NewClient(serviceHost + ":3306").Status(); err == nil && status.Database != nil && status.Database.ReadWrite { logger.Info("database is up, skipping scale check") } else { scaled, err := scale.CheckScale(app, controllerKey, "mongodb", a.logger()) if err != nil { httphelper.Error(w, err) return } // Cluster has yet to be scaled, return healthy if !scaled { w.WriteHeader(200) return } } session, err := mgo.DialWithInfo(&mgo.DialInfo{ Addrs: []string{net.JoinHostPort(serviceHost, "27017")}, Username: "******", Password: os.Getenv("MONGO_PWD"), Database: "admin", }) if err != nil { httphelper.Error(w, err) return } defer session.Close() w.WriteHeader(200) }
func (a *API) ping(ctx context.Context, w http.ResponseWriter, req *http.Request) { logger := a.logger().New("fn", "ping") logger.Info("checking status", "host", serviceHost) if status, err := sirenia.NewClient(serviceHost + ":3306").Status(); err == nil && status.Database != nil && status.Database.ReadWrite { logger.Info("database is up, skipping scale check") } else { scaled, err := scale.CheckScale(app, controllerKey, "mariadb", a.logger()) if err != nil { httphelper.Error(w, err) return } // Cluster has yet to be scaled, return healthy if !scaled { w.WriteHeader(200) return } } db, err := a.connect() if err != nil { httphelper.Error(w, err) return } defer db.Close() if _, err := db.Exec("SELECT 1"); err != nil { httphelper.Error(w, err) return } w.WriteHeader(200) }