Skip to content

Add ability to filter out services from being bound to server factories #213

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

therepanic
Copy link
Contributor

@therepanic therepanic commented Jun 30, 2025

With this change, we will give users the ability to configure their filters for the server-side factory.

I created an interface similar to the ones we already have, and in DefaultGrpcServerFactory we use it to add/not add a service. Overall, nothing special, but I will leave a couple of comments on the points that bother me in some way.

Closes: #207

Comment on lines 78 to 87
public DefaultGrpcServerFactory(String address, List<ServerBuilderCustomizer<T>> serverBuilderCustomizers,
KeyManagerFactory keyManager, TrustManagerFactory trustManager, ClientAuth clientAuth) {
KeyManagerFactory keyManager, TrustManagerFactory trustManager, ClientAuth clientAuth,
ServerServiceDefinitionFilter serviceFilter) {
this(address, serverBuilderCustomizers);
this.keyManager = keyManager;
this.trustManager = trustManager;
this.clientAuth = clientAuth;
this.serviceFilter = serviceFilter;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we maintain backward compatibility by adding another constructor? This question arose because of this comment: #203 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

I don't like the way that some of the new constructors use Optional and this one doesn't (not optional but @Nullable seems better in a mostly internal API). I'm neutral on whether to add another constructor (but mostly against).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeh, we typically rarely use Optional for things besides returns types. For consistency I would say lets go w/ null and @Nullable as well.

@@ -61,7 +63,7 @@ static class ShadedNettyServerFactoryConfiguration {
@Bean
ShadedNettyGrpcServerFactory shadedNettyGrpcServerFactory(GrpcServerProperties properties,
GrpcServiceDiscoverer grpcServicesDiscoverer, ServerBuilderCustomizers serverBuilderCustomizers,
SslBundles bundles) {
SslBundles bundles, Optional<ServerServiceDefinitionFilter> serviceFilter) {
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 think that's okay? I haven't seen any other simpler options.

* @param serverFactory the server factory in use.
* @return {@code true} if the service should be included; {@code false} otherwise.
*/
boolean filter(ServerServiceDefinition serviceDefinition, GrpcServerFactory serverFactory);
Copy link
Member

Choose a reason for hiding this comment

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

This seems wrong - there are no methods on GrpcServerFactory that we would expect to be useful to implementations of this interface, so it's confusing to pass it in. I don't know if removing it will cause more trouble than it is worth but I'd like to at least see that option.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, since there is a single filter bean allowed to be configured, the server factory can be used to check if the service should be added to the particular factory (e.g. in process does not want health checks).

@therepanic therepanic force-pushed the gh-207 branch 3 times, most recently from 66ec313 to 7c9e2f3 Compare July 1, 2025 13:11
@therepanic
Copy link
Contributor Author

Thanks for the review. I removed the second argument from ServerServiceDefinitionFilter and also added the @Nullable annotation to its class constructor. Instead of using Option in autoconfigure, I also use the @Nullable annotation.

@therepanic therepanic force-pushed the gh-207 branch 2 times, most recently from edbdf5d to 4136c04 Compare July 1, 2025 13:19
…es (spring-projects#207)

Signed-off-by: Andrey Litvitski <andrey1010102008@gmail.com>
Signed-off-by: Andrey Litvitski <andrey1010102008@gmail.com>
Copy link
Contributor

@onobc onobc left a comment

Choose a reason for hiding this comment

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

Thanks @therepanic - looking good. A couple of comments to address and then we will be good to go.

…pcServerFactory`

Signed-off-by: Andrey Litvitski <andrey1010102008@gmail.com>
Copy link
Contributor

@onobc onobc left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @therepanic ! Looks great. The only outstanding item is the passing of the server factory into the filter. I think it needs to be there but lets wait for @dsyer reply. I will take it from here though and update accordingly based on what we agree upon. Great work! It should be merged w/in the next 24hrs.

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.

Add ability to filter out services from being bound to server factories
3 participants