Skip to content

Adding metadata to shardcake's internal calls.#155

Merged
ghostdogpr merged 10 commits intodevsisters:series/2.xfrom
douglasthomsen:add-request-metadata
Apr 12, 2025
Merged

Adding metadata to shardcake's internal calls.#155
ghostdogpr merged 10 commits intodevsisters:series/2.xfrom
douglasthomsen:add-request-metadata

Conversation

@douglasthomsen
Copy link
Contributor

@douglasthomsen douglasthomsen commented Mar 31, 2025

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.

shutdownTimeout: Duration,
interceptors: Seq[ZClientInterceptor]
interceptors: Seq[ZClientInterceptor],
serviceTransform: GTransform[RequestContext, StatusException, RequestContext, StatusException]
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
Copy link
Contributor Author

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)
Copy link
Contributor Author

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

Copy link
Collaborator

@ghostdogpr ghostdogpr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@ghostdogpr ghostdogpr merged commit 72591f8 into devsisters:series/2.x Apr 12, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants