Skip to content

Commit ace3066

Browse files
committed
Merge pull request #50799 from xfocus3
* gh-50791-grpc-health-overall: Polish "Honor gRPC overall health setting" Honor gRPC overall health setting Closes gh-50799
2 parents d107f34 + e2b4c93 commit ace3066

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

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

Lines changed: 3 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,8 @@ 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()) ? new AutoConfiguredHealthCheckedGrpcComponent(
72+
HealthContributorMembership.always(), statusAggregator, statusMapper) : null;
7373
this.services = createServices(properties.getService(), beanFactory, statusAggregator, statusMapper);
7474
}
7575

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,17 @@ void createsGrpcServerHealth() {
302302
});
303303
}
304304

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

0 commit comments

Comments
 (0)