Skip to content

Commit

Permalink
fix: Handle dialect config structure in akka-persistence-r2dbc, #46 (#48
Browse files Browse the repository at this point in the history
)
  • Loading branch information
patriknw authored Aug 17, 2023
1 parent 4439a1a commit 4553f17
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions akka-diagnostics/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ akka.diagnostics.checker {
"akka.persistence.r2dbc.state.change-handler",
"akka.persistence.testkit.snapshotstore.pluginid",
"akka.persistence.testkit.journal",
"akka.projection.dummy-for-docs",
"akka.projection.r2dbc.default-h2-schema"
]
}
#//#config-checker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package akka.diagnostics

import java.net.InetAddress
import java.util
import java.util.Locale
import java.util.concurrent.TimeUnit.MILLISECONDS

Expand Down Expand Up @@ -309,6 +310,8 @@ class ConfigChecker(system: ExtendedActorSystem, config: Config, reference: Conf
pathList.size > 4 && pathList.asScala.startsWith(Seq("akka", "actor", "deployment"))
def inGrpcClientSection: Boolean =
pathList.size > 4 && pathList.asScala.startsWith(Seq("akka", "grpc", "client"))
def inR2dbcConnectionFactorySection: Boolean =
pathList.contains("connection-factory")

def checkConfigObject(obj: ConfigObject): Unit = {
val iter = obj.entrySet().iterator()
Expand Down Expand Up @@ -336,6 +339,8 @@ class ConfigChecker(system: ExtendedActorSystem, config: Config, reference: Conf
// For checking typos inside a `akka.grpc.client."FooService"` section remove those 4 path elements
// and compare with the fallback deployment config.
!grpcClientReference.hasPathOrNull(ConfigUtil.joinPath(pathList.subList(4, pathList.size)))
else if (isR2dbcConfigAvailable && inR2dbcConnectionFactorySection)
checkTypoInR2dbcConnectionFactorySection(pathList)
else
!reference.hasPathOrNull(p)
if (isTypo) {
Expand Down Expand Up @@ -380,6 +385,30 @@ class ConfigChecker(system: ExtendedActorSystem, config: Config, reference: Conf
}
}

private lazy val isR2dbcConfigAvailable: Boolean = {
// check existence of a property from reference.conf that will unlikely be defined elsewhere
reference.hasPath("akka.persistence.r2dbc.journal")
}

private def checkTypoInR2dbcConnectionFactorySection(pathList: util.LinkedList[String]): Boolean = {
val i = pathList.indexOf("connection-factory")
val dialectPath = ConfigUtil.joinPath(pathList.subList(0, i + 1)) + ".dialect"
if (pathList.contains("additional-options"))
false
else if (config.hasPath(dialectPath)) {
val dialect = config.getString(dialectPath)
val dialectReferencePath = s"akka.persistence.r2dbc.$dialect"
if (reference.hasPath(dialectReferencePath)) {
// For checking typos inside a `connection-factory"` section remove preceding path elements
// and compare with the default dialect config.
val dialectReference = reference.getConfig(dialectReferencePath)
!dialectReference.hasPathOrNull(ConfigUtil.joinPath(pathList.subList(i + 1, pathList.size)))
} else // wrong dialect, but that is not a typo, check as ordinary property
!reference.hasPathOrNull(ConfigUtil.joinPath(pathList))
} else // no dialect, check as ordinary property
!reference.hasPathOrNull(ConfigUtil.joinPath(pathList))
}

/**
* INTERNAL API
*/
Expand Down

0 comments on commit 4553f17

Please sign in to comment.