Skip to content

Commit

Permalink
add nested config object for health service
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesmst committed May 13, 2024
1 parent cced054 commit fd3070e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ 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();
}

@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();
}

@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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fd3070e

Please sign in to comment.