-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added basic readiness check for registry API #2997
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just some minor error handling changes are required.
path("ready") { | ||
DB readOnly { session => | ||
recordPersistence.getReadiness(Some(logger))(session) | ||
} match { | ||
case Some(true) => complete("OK") | ||
case Some(false) | None => | ||
complete(StatusCodes.InternalServerError, "Database not ready") | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested in the cluster and it seems most exceptions are not captured.
e.g.
java.util.NoSuchElementException: key not found: to_regclass
OR org.postgresql.util.PSQLException: Connection to registry-db:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
OR org.postgresql.util.PSQLException: FATAL: role "client" does not exist
I think you probably need to capture any failure from the DB.readonly method as the execution is happening there.
you might want to try scala's util.Try
instead of try/catch
--- it's more common in scala as it's more flexible / offer more streamlined exception processing
https://www.scala-lang.org/api/2.9.3/scala/util/Try.html
You can do something like this:
import scala.util.{Try, Failure, Success}
Try{
DB readOnly { session =>
recordPersistence.getReadiness(Some(logger))(session)
}
} match {
case Success(Some(true)) => complete("OK")
case Success(Some(false)) | Success(None) =>
complete(StatusCodes.InternalServerError, "Database not ready")
case Failure(exception) => complete(StatusCodes.InternalServerError, "Database not ready Other")
}
The recordPersistence.getReadiness
doesn't seem to need to capture any exceptions (so you don't have to capture at multiple place) nor has a chance to produce a NONE. I guess a Boolean could simpler
I'm sorry @t83714 I've run out of time for this one, are you able to do the error handling changes you have in mind, then get this in? 🙏 I think it would still be extremely useful for the registry API to have this check! |
@soyarsauce |
|
What this PR does
Fixes #2992
Checklist