Adding metadata to shardcake's internal calls.#155
Adding metadata to shardcake's internal calls.#155ghostdogpr merged 10 commits intodevsisters:series/2.xfrom
Conversation
manager/src/main/scala/com/devsisters/shardcake/ManagerConfig.scala
Outdated
Show resolved
Hide resolved
protocol-grpc/src/main/scala/com/devsisters/shardcake/GrpcConfig.scala
Outdated
Show resolved
Hide resolved
| shutdownTimeout: Duration, | ||
| interceptors: Seq[ZClientInterceptor] | ||
| interceptors: Seq[ZClientInterceptor], | ||
| serviceTransform: GTransform[RequestContext, StatusException, RequestContext, StatusException] |
There was a problem hiding this comment.
Looks ok, how about renaming interceptors to clientInterceptors and serviceTransform to serverInterceptors?
Even though identity (and similarly the empty aspect) does nothing, a list might be a little better? So that we don't call anything additional when we don't need it.
There was a problem hiding this comment.
I have renamed the var names but I have not updated how the GrpcShardingService adds the serviceTransform to the service. I will work on this tomorrow.
There was a problem hiding this comment.
I have updated the code to add the serverInterceptors. I will work on adding some tests next.
There was a problem hiding this comment.
@ghostdogpr I have added some tests for adding metadata to shardcake's internal calls. I put them in the example subproject because it had access to all of the code that I needed but I am not sure if that is the right place for them.
Can you review these changes again? Also, is there any documentation that I need to update for this change?
| services <- | ||
| ServiceList | ||
| .add( | ||
| grpcConfig.serverInterceptors |
There was a problem hiding this comment.
Originally, I tried the following to add the interceptors:
services <- ServiceList
.add(
grpcConfig.serverInterceptors.foldLeft(new GrpcShardingService(sharding, config.sendTimeout) {}.asGeneric) { case (service, interceptor) =>
service.transform(interceptor)
}
)
.bindAllbut it did not like that I changed the type of the service from GShardingService[Any, StatusException] to GShardingService[RequestContext, StatusException]. So combining all of the server interceptors into one interceptor was the simplest solution.
| grpcConfig.serverInterceptors | ||
| .reduceOption(_.andThen(_)) | ||
| .map(t => grpcShardingService.transform(t)) | ||
| .getOrElse(grpcShardingService.asGeneric) |
There was a problem hiding this comment.
The GrpcShardingService depends on the implicit conversion ShardingService.genericBindable to be able to add it to the list. By default the compiler does not know that it needs to use the implicit conversion in the getOrElse call so I needed to call asGeneric
ghostdogpr
left a comment
There was a problem hiding this comment.
Looks great, thanks!
This PR provides an example of how we could implement adding metadata to shardcake's internal calls (see issue here). I am looking for some feedback on this approach before I add tests and documentation.