Skip to content
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

Disable in-process transport by default and add @AutoConfigureInProcessTransport annotation #88

Conversation

panic08
Copy link
Contributor

@panic08 panic08 commented Jan 1, 2025

Here I have added the AutoConfigureInProcessTransport annotation which should be set over the test where we want in-process transport to be enabled. I also added the class InProcessTransportEnvironmentPostProcessor which implements EnvironmentPostProcessor and where I use AnnotationUtils.findAnnotation to check if the startup class is marked with an annotation or not. If yes, then we need to enable in-process transport and we set spring.grpc.inprocess.enabled=true. I also set matchIfMissing to false in InProcessGrpcServerFactoryAutoConfiguration (ignored as it is by default) so that in-process will default to false.

Closes #77

import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;

public class InProcessTransportEnvironmentPostProcessor implements EnvironmentPostProcessor {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this is going to work. Don't we need something that is aware of the test environment? Look at the existing @AutoConfigure* annotations to see how they are implemented.

Copy link
Contributor Author

@panic08 panic08 Jan 2, 2025

Choose a reason for hiding this comment

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

Thanks so much for the tip. I've looked into it more, tested it, and I'd like to say. Could we create an InProcessFactory that will implement ContextCustomizerFactory? That is, make a class like ObservabilityContextCustomizerFactory

@panic08 panic08 force-pushed the make-in-process-transport-inclusion-customizable branch from af78ee1 to 8714edc Compare January 6, 2025 14:21
@panic08
Copy link
Contributor Author

panic08 commented Jan 6, 2025

I listened to what you said. For an idea for looking at @AutoConfigure* annotation implementations, I decided to go with AutoConfigureObservability as advised by @onobc .

I created an InProcessTransportContextCustomizerFactory that will check for the presence of the @AutoConfigureInProcessTransport annotation I created. If this annotation is not present, I've added the ability for properties to specify spring.grpc.inprocess.auto-configure to enable auto-configuration (I think this will be good for us?). If auto-configure is enabled, for now we only do one thing, in the test properties set spring.grpc.inprocess.enabled=true

@panic08 panic08 requested a review from dsyer January 6, 2025 14:28
@dsyer
Copy link
Collaborator

dsyer commented Jan 6, 2025

I took a version of your PR from yesterday and added some extra code to detect if we are running in a test. I think this works now. Merged in e0a744b. Thank you.

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.

Test apps should not use in-process transport
2 participants