diff --git a/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceAutoConfiguration.java b/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceAutoConfiguration.java index f6f4587ff..27ea591b1 100644 --- a/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceAutoConfiguration.java +++ b/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceAutoConfiguration.java @@ -50,7 +50,7 @@ public class GrpcHealthServiceAutoConfiguration { */ @Bean @ConditionalOnMissingBean - @ConditionalOnProperty(prefix = "grpc.server", name = "health-service-type", havingValue = "GRPC", + @ConditionalOnProperty(prefix = "grpc.server", name = "health-service.type", havingValue = "GRPC", matchIfMissing = true) HealthStatusManager healthStatusManager() { return new HealthStatusManager(); @@ -58,7 +58,7 @@ HealthStatusManager healthStatusManager() { @Bean @GrpcService - @ConditionalOnProperty(prefix = "grpc.server", name = "health-service-type", havingValue = "GRPC", + @ConditionalOnProperty(prefix = "grpc.server", name = "health-service.type", havingValue = "GRPC", matchIfMissing = true) BindableService grpcHealthService(final HealthStatusManager healthStatusManager) { return healthStatusManager.getHealthService(); @@ -66,7 +66,7 @@ BindableService grpcHealthService(final HealthStatusManager healthStatusManager) @Bean @GrpcService - @ConditionalOnProperty(prefix = "grpc.server", name = "health-service-type", havingValue = "ACTUATOR") + @ConditionalOnProperty(prefix = "grpc.server", name = "health-service.type", havingValue = "ACTUATOR") BindableService grpcHealthServiceActuator(final HealthEndpoint healthStatusManager) { return new ActuatorGrpcHealth(healthStatusManager); } diff --git a/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/GrpcServerProperties.java b/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/GrpcServerProperties.java index 64916c712..cb4605d03 100644 --- a/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/GrpcServerProperties.java +++ b/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/GrpcServerProperties.java @@ -223,18 +223,20 @@ public class GrpcServerProperties { /** * Whether gRPC health service is enabled or not. Defaults to {@code true}. * + * @deprecated Use {@link HealthOptions#type health type} @{@link HealthType#NONE NONE} instead. * @param healthServiceEnabled Whether gRPC health service is enabled. * @return True, if the health service is enabled. False otherwise. */ + @Deprecated private boolean healthServiceEnabled = true; /** - * Implementation of gRPC health service. Defaults to {@link HealthType#GRPC GRPC}. + * Implementation of gRPC health service. Defaults the type to {@link HealthType#GRPC GRPC}. * - * @param healthServiceType The implementation of gRPC health service. - * @return GRPC or Actuator. + * @param healthService The options for the health service. + * @return The type of health service to use. */ - private HealthType healthServiceType = HealthType.GRPC; + private HealthOptions healthService = new HealthOptions(); /** * Whether proto reflection service is enabled or not. Defaults to {@code true}. diff --git a/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/HealthOptions.java b/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/HealthOptions.java new file mode 100644 index 000000000..69ad21da1 --- /dev/null +++ b/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/HealthOptions.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2016-2024 The gRPC-Spring Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.devh.boot.grpc.server.config; + +import lombok.Data; + +/** + * GRPC Health service options. + */ +@Data +public class HealthOptions { + + /** + * Implementation of gRPC health service. Defaults to {@link HealthType#GRPC GRPC}. To disable health service set to + * {@link HealthType#NONE NONE}. + * + * @see net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration + * @param type The implementation of gRPC health service. + * @return GRPC, ACTUATOR or NONE. + */ + private HealthType type = HealthType.GRPC; +} diff --git a/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/HealthType.java b/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/HealthType.java index f67e83b88..1c0b0f5bd 100644 --- a/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/HealthType.java +++ b/grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/HealthType.java @@ -16,16 +16,21 @@ package net.devh.boot.grpc.server.config; + /** * Enum to specify the type of health service to use in GRPC. */ public enum HealthType { /** * Use the standard GRPC health service from io.grpc. + * + * @see net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration#grpcHealthService */ GRPC, /** * Uses a bridge to the Spring Boot Actuator health service. + * + * @see net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration#grpcHealthServiceActuator */ ACTUATOR, /** diff --git a/grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceFalseAutoConfigurationTest.java b/grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceFalseAutoConfigurationTest.java index 36abb92a1..b1f1753fe 100644 --- a/grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceFalseAutoConfigurationTest.java +++ b/grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceFalseAutoConfigurationTest.java @@ -30,7 +30,7 @@ import io.grpc.health.v1.HealthCheckResponse; @SpringBootTest(classes = GrpcHealthServiceDefaultAutoConfigurationTest.TestConfig.class, - properties = "grpc.server.health-service-enabled=false") + properties = "grpc.server.health-service.type=NONE") @ImportAutoConfiguration({ GrpcServerAutoConfiguration.class, GrpcServerFactoryAutoConfiguration.class, diff --git a/grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceTrueActuatorConfigurationTest.java b/grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceTrueActuatorConfigurationTest.java index 293a521ed..cb5055c4a 100644 --- a/grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceTrueActuatorConfigurationTest.java +++ b/grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceTrueActuatorConfigurationTest.java @@ -42,7 +42,7 @@ GrpcHealthServiceDefaultAutoConfigurationTest.TestConfig.class, GrpcHealthServiceTrueActuatorConfigurationTest.TestConfig.class}, properties = { - "grpc.server.health-service-type=ACTUATOR"}) + "grpc.server.health-service.type=ACTUATOR"}) @ImportAutoConfiguration({ GrpcServerAutoConfiguration.class, GrpcServerFactoryAutoConfiguration.class, diff --git a/grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceTrueAutoConfigurationTest.java b/grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceTrueAutoConfigurationTest.java index be455d65a..3bc1eb544 100644 --- a/grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceTrueAutoConfigurationTest.java +++ b/grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceTrueAutoConfigurationTest.java @@ -21,7 +21,7 @@ import org.springframework.test.annotation.DirtiesContext; @SpringBootTest(classes = GrpcHealthServiceDefaultAutoConfigurationTest.TestConfig.class, - properties = "grpc.server.health-service-enabled=true") + properties = "grpc.server.health-service.type=GRPC") @ImportAutoConfiguration({ GrpcServerAutoConfiguration.class, GrpcServerFactoryAutoConfiguration.class,