@@ -3,15 +3,14 @@ package misk.vitess
33import com.zaxxer.hikari.SQLExceptionOverride
44import io.prometheus.client.CollectorRegistry
55import io.prometheus.client.Counter
6- import java.lang.ref.WeakReference
76import java.sql.SQLException
8- import java.util.Collections
9- import java.util.WeakHashMap
107import java.util.concurrent.ConcurrentHashMap
8+ import wisp.logging.getLogger
119
1210internal class VitessExceptionHandler (
1311 registry : CollectorRegistry ? = null ,
1412) : SQLExceptionOverride {
13+ private val logger = getLogger<VitessExceptionHandler >()
1514
1615 private val errorCounter = registry?.let { registry ->
1716 Counter
@@ -56,6 +55,15 @@ internal class VitessExceptionHandler(
5655
5756 override fun adjudicate (sqlException : SQLException ): SQLExceptionOverride .Override {
5857 return adjudicateInternal(sqlException).also { result ->
58+ logger.error(
59+ " Hikari exception adjudicate: " +
60+ " errorCode=${sqlException.errorCode} , " +
61+ // the logic around sqlState kotlin this is null safe, but the Java shows it being set
62+ // as null. Let's be explicit at the behavir.
63+ " state=${sqlException?.sqlState ? : " null" } , " +
64+ " message=${sqlException.message} , " +
65+ " adjudicate=$result "
66+ )
5967 errorCounter?.labels(
6068 sqlException.errorCode.toString(),
6169 sqlException.sqlState,
@@ -67,15 +75,17 @@ internal class VitessExceptionHandler(
6775
6876 companion object {
6977 /* *
70- * This uses a similar that Hikari does internally. We can't register the same counter twice.
71- * instead we use some global memory to find the existing reference and return it instead.
78+ * This uses a similar check that Hikari does internally. We can't register the same counter twice.
79+ * Instead we use some global memory to find the existing reference and return it instead.
7280 */
7381 private val registrationStatuses: ConcurrentHashMap <CollectorRegistry , Counter > =
7482 ConcurrentHashMap ()
7583 private fun Counter.registerOrReplace (registry : CollectorRegistry ): Counter {
7684 val existingCounter = registrationStatuses.putIfAbsent(registry, this )
7785 return if (existingCounter == null ) {
7886 registry.register(this )
87+ // make sure we have some baseline labels
88+ this .labels(" " , " " , " " , " CONTINUE_EVICT" )
7989 this
8090 } else {
8191 existingCounter
0 commit comments