Skip to content

Commit 65e8a1b

Browse files
committed
add nested config object for health service
1 parent cced054 commit 65e8a1b

File tree

8 files changed

+55
-11
lines changed

8 files changed

+55
-11
lines changed

docs/en/actuator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ This integration enables the server to respond to gRPC health checks based on th
190190
To enable this integration, add the following properties to your application configuration:
191191
192192
````properties
193-
grpc.server.health-service-type=ACTUATOR
193+
grpc.server.health-service.type=ACTUATOR
194194
````
195195
196196
The integration allows you to check the health status for the whole service or specific health indicators, where the `service` is the key of the [`HealthIndicator`](https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints.health.auto-configured-health-indicators).

grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceAutoConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,23 @@ public class GrpcHealthServiceAutoConfiguration {
5050
*/
5151
@Bean
5252
@ConditionalOnMissingBean
53-
@ConditionalOnProperty(prefix = "grpc.server", name = "health-service-type", havingValue = "GRPC",
53+
@ConditionalOnProperty(prefix = "grpc.server", name = "health-service.type", havingValue = "GRPC",
5454
matchIfMissing = true)
5555
HealthStatusManager healthStatusManager() {
5656
return new HealthStatusManager();
5757
}
5858

5959
@Bean
6060
@GrpcService
61-
@ConditionalOnProperty(prefix = "grpc.server", name = "health-service-type", havingValue = "GRPC",
61+
@ConditionalOnProperty(prefix = "grpc.server", name = "health-service.type", havingValue = "GRPC",
6262
matchIfMissing = true)
6363
BindableService grpcHealthService(final HealthStatusManager healthStatusManager) {
6464
return healthStatusManager.getHealthService();
6565
}
6666

6767
@Bean
6868
@GrpcService
69-
@ConditionalOnProperty(prefix = "grpc.server", name = "health-service-type", havingValue = "ACTUATOR")
69+
@ConditionalOnProperty(prefix = "grpc.server", name = "health-service.type", havingValue = "ACTUATOR")
7070
BindableService grpcHealthServiceActuator(final HealthEndpoint healthStatusManager) {
7171
return new ActuatorGrpcHealth(healthStatusManager);
7272
}

grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/GrpcServerProperties.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,18 +223,20 @@ public class GrpcServerProperties {
223223
/**
224224
* Whether gRPC health service is enabled or not. Defaults to {@code true}.
225225
*
226+
* @deprecated Use {@link HealthOptions#type health type} @{@link HealthType#NONE NONE} instead.
226227
* @param healthServiceEnabled Whether gRPC health service is enabled.
227228
* @return True, if the health service is enabled. False otherwise.
228229
*/
230+
@Deprecated
229231
private boolean healthServiceEnabled = true;
230232

231233
/**
232-
* Implementation of gRPC health service. Defaults to {@link HealthType#GRPC GRPC}.
234+
* Implementation of gRPC health service. Defaults the type to {@link HealthType#GRPC GRPC}.
233235
*
234-
* @param healthServiceType The implementation of gRPC health service.
235-
* @return GRPC or Actuator.
236+
* @param healthService The options for the health service.
237+
* @return The type of health service to use.
236238
*/
237-
private HealthType healthServiceType = HealthType.GRPC;
239+
private HealthOptions healthService = new HealthOptions();
238240

239241
/**
240242
* Whether proto reflection service is enabled or not. Defaults to {@code true}.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2016-2024 The gRPC-Spring Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package net.devh.boot.grpc.server.config;
18+
19+
import lombok.Data;
20+
21+
/**
22+
* GRPC Health service options.
23+
*/
24+
@Data
25+
public class HealthOptions {
26+
27+
/**
28+
* Implementation of gRPC health service. Defaults to {@link HealthType#GRPC GRPC}. To disable health service set to
29+
* {@link HealthType#NONE NONE}.
30+
*
31+
* @see net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration
32+
* @param type The implementation of gRPC health service.
33+
* @return GRPC, ACTUATOR or NONE.
34+
*/
35+
private HealthType type = HealthType.GRPC;
36+
}

grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/HealthType.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,22 @@
1616

1717
package net.devh.boot.grpc.server.config;
1818

19+
1920
/**
2021
* Enum to specify the type of health service to use in GRPC.
2122
*/
2223
public enum HealthType {
2324
/**
2425
* Use the standard GRPC health service from io.grpc.
26+
*
27+
* @see net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration#grpcHealthService
2528
*/
2629
GRPC,
2730
/**
2831
* Uses a bridge to the Spring Boot Actuator health service.
32+
*
33+
* @see net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration#grpcHealthServiceActuator
34+
* @see net.devh.boot.grpc.server.health.ActuatorGrpcHealth
2935
*/
3036
ACTUATOR,
3137
/**

grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceFalseAutoConfigurationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import io.grpc.health.v1.HealthCheckResponse;
3131

3232
@SpringBootTest(classes = GrpcHealthServiceDefaultAutoConfigurationTest.TestConfig.class,
33-
properties = "grpc.server.health-service-enabled=false")
33+
properties = "grpc.server.health-service.type=NONE")
3434
@ImportAutoConfiguration({
3535
GrpcServerAutoConfiguration.class,
3636
GrpcServerFactoryAutoConfiguration.class,

grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceTrueActuatorConfigurationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
GrpcHealthServiceDefaultAutoConfigurationTest.TestConfig.class,
4343
GrpcHealthServiceTrueActuatorConfigurationTest.TestConfig.class},
4444
properties = {
45-
"grpc.server.health-service-type=ACTUATOR"})
45+
"grpc.server.health-service.type=ACTUATOR"})
4646
@ImportAutoConfiguration({
4747
GrpcServerAutoConfiguration.class,
4848
GrpcServerFactoryAutoConfiguration.class,

grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceTrueAutoConfigurationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.springframework.test.annotation.DirtiesContext;
2222

2323
@SpringBootTest(classes = GrpcHealthServiceDefaultAutoConfigurationTest.TestConfig.class,
24-
properties = "grpc.server.health-service-enabled=true")
24+
properties = "grpc.server.health-service.type=GRPC")
2525
@ImportAutoConfiguration({
2626
GrpcServerAutoConfiguration.class,
2727
GrpcServerFactoryAutoConfiguration.class,

0 commit comments

Comments
 (0)