Skip to content

Commit da318b2

Browse files
Ahmed El amraouiyinesnicoll
authored andcommitted
Honor gRPC overall health setting
See gh-50799 Signed-off-by: Ahmed El amraouiyine <amraouiyine@gmail.com>
1 parent d107f34 commit da318b2

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

module/spring-boot-grpc-server/src/main/java/org/springframework/boot/grpc/server/autoconfigure/health/AutoConfiguredHealthCheckedGrpcComponents.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
*/
5252
class AutoConfiguredHealthCheckedGrpcComponents implements HealthCheckedGrpcComponents {
5353

54-
private final HealthCheckedGrpcComponent server;
54+
private final @Nullable HealthCheckedGrpcComponent server;
5555

5656
private final Map<String, HealthCheckedGrpcComponent> services;
5757

@@ -68,8 +68,10 @@ class AutoConfiguredHealthCheckedGrpcComponents implements HealthCheckedGrpcComp
6868
() -> StatusAggregator.of(properties.getStatus().getOrder()));
6969
StatusMapper statusMapper = getNonQualifiedBean(beanFactory, StatusMapper.class,
7070
() -> StatusMapper.of(properties.getStatus().getMapping()));
71-
this.server = new AutoConfiguredHealthCheckedGrpcComponent(HealthContributorMembership.always(),
72-
statusAggregator, statusMapper);
71+
this.server = (properties.isIncludeOverallHealth())
72+
? new AutoConfiguredHealthCheckedGrpcComponent(HealthContributorMembership.always(), statusAggregator,
73+
statusMapper)
74+
: null;
7375
this.services = createServices(properties.getService(), beanFactory, statusAggregator, statusMapper);
7476
}
7577

module/spring-boot-grpc-server/src/test/java/org/springframework/boot/grpc/server/autoconfigure/health/AutoConfiguredHealthCheckedGrpcComponentsTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ void getServerMatchesAllMembers() {
5959
});
6060
}
6161

62+
@Test
63+
void getServerWhenIncludeOverallHealthIsFalseReturnsNull() {
64+
this.contextRunner.withPropertyValues("spring.grpc.server.health.include-overall-health=false")
65+
.run((context) -> {
66+
HealthCheckedGrpcComponents components = context.getBean(HealthCheckedGrpcComponents.class);
67+
assertThat(components.getServer()).isNull();
68+
});
69+
}
70+
6271
@Test
6372
void getServiceNamesReturnsServiceNames() {
6473
this.contextRunner

module/spring-boot-grpc-server/src/test/java/org/springframework/boot/grpc/server/autoconfigure/health/GrpcServerHealthAutoConfigurationTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,16 @@ void createsGrpcServerHealth() {
302302
});
303303
}
304304

305+
@Test
306+
void whenIncludeOverallHealthIsFalseDoesNotReportOverallHealth() {
307+
this.contextRunner.withPropertyValues("spring.grpc.server.health.include-overall-health=false").run((context) -> {
308+
GrpcServerHealth serverHealth = context.getBean(GrpcServerHealth.class);
309+
Map<String, ServingStatus> result = new LinkedHashMap<>();
310+
serverHealth.update(result::put);
311+
assertThat(result).isEmpty();
312+
});
313+
}
314+
305315
@Test
306316
void whenHasGrpcServerHealthBeanDoesNotCreateAdditional() {
307317
this.contextRunner.withUserConfiguration(GrpcServerHealthConfiguration.class).run((context) -> {

0 commit comments

Comments
 (0)