-
Notifications
You must be signed in to change notification settings - Fork 64
#1: Autoconfigure metric registry support #41
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...java/org/springframework/grpc/autoconfigure/server/GrpcServerMetricAutoConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package org.springframework.grpc.autoconfigure.server; | ||
|
|
||
| import io.grpc.ServerBuilder; | ||
| import io.grpc.ServerInterceptor; | ||
| import io.micrometer.core.instrument.binder.grpc.ObservationGrpcServerInterceptor; | ||
| import io.micrometer.observation.ObservationRegistry; | ||
| import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.grpc.server.ServerBuilderCustomizer; | ||
|
|
||
| @AutoConfiguration | ||
| @ConditionalOnClass(ObservationGrpcServerInterceptor.class) | ||
| @ConditionalOnBean(ObservationRegistry.class) | ||
| public class GrpcServerMetricAutoConfiguration { | ||
hmtang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Bean | ||
| public ServerInterceptor observationGrpcServerInterceptor(ObservationRegistry observationRegistry) { | ||
| return new ObservationGrpcServerInterceptor(observationRegistry); | ||
| } | ||
|
|
||
| @Bean | ||
| <T extends ServerBuilder<T>> ServerBuilderCustomizer<T> metricsInterceptor( | ||
hmtang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ServerInterceptor observationGrpcServerInterceptor) { | ||
| return (serverBuilder) -> serverBuilder.intercept(observationGrpcServerInterceptor); | ||
dsyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| } | ||
39 changes: 39 additions & 0 deletions
39
...org/springframework/grpc/autoconfigure/server/GrpcServerMetricAutoConfigurationTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package org.springframework.grpc.autoconfigure.server; | ||
|
|
||
| import io.grpc.ServerBuilder; | ||
| import io.grpc.ServerInterceptor; | ||
| import io.micrometer.core.instrument.binder.grpc.ObservationGrpcServerInterceptor; | ||
| import io.micrometer.observation.ObservationRegistry; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
| import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
| import org.springframework.grpc.server.ServerBuilderCustomizer; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| class GrpcServerMetricAutoConfigurationTests { | ||
|
|
||
| private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() | ||
| .withConfiguration(AutoConfigurations.of(GrpcServerMetricAutoConfiguration.class)); | ||
|
|
||
| @Test | ||
| void whenObservationRegistryNotProvided_thenMetricsInterceptorNotConfigured() { | ||
hmtang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.contextRunner.run(context -> { | ||
| assertThat(context).doesNotHaveBean(ServerBuilderCustomizer.class); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| void whenMetricsInterceptorConfigured_thenServerBuilderCustomizerConfigured() { | ||
| this.contextRunner.withBean(ObservationRegistry.class, ObservationRegistry::create).run(context -> { | ||
| assertThat(context).hasSingleBean(ServerBuilderCustomizer.class); | ||
| assertThat(context).hasSingleBean(ServerInterceptor.class); | ||
| ServerInterceptor interceptor = context.getBean(ServerInterceptor.class); | ||
| ServerBuilderCustomizer customizer = context.getBean(ServerBuilderCustomizer.class); | ||
| ServerBuilder<?> builder = org.mockito.Mockito.mock(ServerBuilder.class); | ||
| customizer.customize(builder); | ||
| org.mockito.Mockito.verify(builder, org.mockito.Mockito.times(1)).intercept(interceptor); | ||
| }); | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.