-
Notifications
You must be signed in to change notification settings - Fork 32
Adding metadata to shardcake's internal calls. #155
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
Adding metadata to shardcake's internal calls. #155
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
@@ -17,10 +20,11 @@ case class GrpcConfig( | |||
maxInboundMessageSize: Int, | |||
executor: Option[Executor], | |||
shutdownTimeout: Duration, | |||
interceptors: Seq[ZClientInterceptor] | |||
interceptors: Seq[ZClientInterceptor], | |||
serviceTransform: GTransform[RequestContext, StatusException, RequestContext, StatusException] |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the code to add the serverInterceptors
. I will work on adding some tests next.
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.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
}
)
.bindAll
but 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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.
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.