Skip to content

Commit

Permalink
Trying to get override config for external services working, no success
Browse files Browse the repository at this point in the history
  • Loading branch information
johanandren committed Jan 24, 2025
1 parent c16feb6 commit ef2bf2b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
9 changes: 9 additions & 0 deletions akka-javasdk/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ akka.javasdk {
pass-along-env-allow = []
}

grpc.client {
# Specify entries for the full service DNS names to apply
# customizations for interacting with external gRPC services
# Fixme specify what settings are possible right here
# "com.example" {
# use-tls = true
# }
}

telemetry {
tracing {
collector-endpoint = ""
Expand Down
16 changes: 8 additions & 8 deletions akka-javasdk/src/main/scala/akka/javasdk/impl/SdkRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -341,21 +341,21 @@ private final class Sdk(
remoteIdentification.map(ri => RawHeader(ri.headerName, ri.headerValue)),
sdkSettings)

private lazy val grpcClientProvider = new GrpcClientProviderImpl(
system,
sdkSettings,
applicationConfig,
remoteIdentification.map(ri => GrpcClientProviderImpl.AuthHeaders(ri.headerName, ri.headerValue)))

private lazy val userServiceConfig = {
// hiding these paths from the config provided to user
val sensitivePaths = List("akka", "kalix.meta", "kalix.proxy", "kalix.runtime", "system")
val sdkConfig = applicationConfig.getConfig("akka.javasdk")
val sdkConfig = applicationConfig.getObject("akka.javasdk")
sensitivePaths
.foldLeft(applicationConfig) { (conf, toHide) => conf.withoutPath(toHide) }
.withFallback(sdkConfig)
.withValue("akka.javasdk", sdkConfig)
}

private lazy val grpcClientProvider = new GrpcClientProviderImpl(
system,
sdkSettings,
userServiceConfig,
remoteIdentification.map(ri => GrpcClientProviderImpl.AuthHeaders(ri.headerName, ri.headerValue)))

// validate service classes before instantiating
private val validation = componentClasses.foldLeft(Valid: Validation) { case (validations, cls) =>
validations ++ Validations.validate(cls)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import akka.javasdk.grpc.GrpcClientProvider
import akka.javasdk.impl.Settings
import akka.javasdk.impl.grpc.GrpcClientProviderImpl.AuthHeaders
import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory
import org.slf4j.LoggerFactory

import java.util.concurrent.ConcurrentHashMap
Expand Down Expand Up @@ -66,7 +67,7 @@ private[akka] object GrpcClientProviderImpl {
private[akka] final class GrpcClientProviderImpl(
system: ActorSystem[_],
settings: Settings,
applicationConfig: Config,
userServiceConfig: Config,
remoteIdentificationHeader: Option[AuthHeaders])
extends GrpcClientProvider {
import GrpcClientProviderImpl._
Expand All @@ -92,7 +93,8 @@ private[akka] final class GrpcClientProviderImpl(
// getGrpcClient(serviceClass, service, port, Some("impersonate-kalix-service" -> impersonate))

private def createNewClientFor(clientKey: ClientKey): AkkaGrpcClient = {
val clientSettings =
val clientSettings = {
// FIXME the old impl would look in config first and always choose that if present
if (isAkkaService(clientKey.serviceName)) {
val akkaServiceClientSettings = if (settings.devModeSettings.isDefined) {
// local service discovery when running locally
Expand Down Expand Up @@ -139,8 +141,14 @@ private[akka] final class GrpcClientProviderImpl(

// FIXME we should probably not allow any grpc client setting but a subset?
// external service, details defined in user config
GrpcClientSettings.fromConfig(clientKey.serviceName, applicationConfig)(system)
GrpcClientSettings.fromConfig(
clientKey.serviceName,
userServiceConfig
.getConfig("akka.javasdk.grpc.client")
// this config overload requires there to be an entry for the name, but then falls back to defaults
.withFallback(ConfigFactory.parseString(s""""${clientKey.serviceName}" = {}""")))(system)
}
}

// Java API - static create
val create =
Expand Down
7 changes: 7 additions & 0 deletions samples/doc-snippets/src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
my-app {
some-feature-flag = true
environment = "test"
}

akka.javasdk.grpc.client."hellogrpc.example.com" {
# configure external call, to call back to self
host = "localhost"
port = 9000
use-tls = false
}

0 comments on commit ef2bf2b

Please sign in to comment.