From 592d29d3b38e030052eeebaad3ee0d63bf955b42 Mon Sep 17 00:00:00 2001 From: Chris Bono Date: Thu, 21 Nov 2024 21:26:23 -0600 Subject: [PATCH] Move health autoconfig into health package This commit moves the health autoconfiguration into its own package as well as moves the ActuatorHealthAdapter into its own class. Signed-off-by: Chris Bono --- .../server/ServerBuilderCustomizers.java | 6 ++-- .../server/health/ActuatorHealthAdapter.java | 33 +++++++++++++++++++ .../GrpcServerHealthAutoConfiguration.java | 14 ++------ ...ot.autoconfigure.AutoConfiguration.imports | 2 +- ...rpcServerHealthAutoConfigurationTests.java | 7 ++-- 5 files changed, 44 insertions(+), 18 deletions(-) create mode 100644 spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/health/ActuatorHealthAdapter.java rename spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/{ => health}/GrpcServerHealthAutoConfiguration.java (87%) rename spring-grpc-spring-boot-autoconfigure/src/test/java/org/springframework/grpc/autoconfigure/server/{ => health}/GrpcServerHealthAutoConfigurationTests.java (95%) diff --git a/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/ServerBuilderCustomizers.java b/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/ServerBuilderCustomizers.java index 3226cb9..f46c1d3 100644 --- a/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/ServerBuilderCustomizers.java +++ b/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/ServerBuilderCustomizers.java @@ -20,18 +20,18 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import io.grpc.ServerBuilder; - import org.springframework.boot.util.LambdaSafe; import org.springframework.grpc.server.ServerBuilderCustomizer; +import io.grpc.ServerBuilder; + /** * Invokes the available {@link ServerBuilderCustomizer} instances in the context for a * given {@link ServerBuilder}. * * @author Chris Bono */ -class ServerBuilderCustomizers { +public class ServerBuilderCustomizers { private final List> customizers; diff --git a/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/health/ActuatorHealthAdapter.java b/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/health/ActuatorHealthAdapter.java new file mode 100644 index 0000000..3757a10 --- /dev/null +++ b/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/health/ActuatorHealthAdapter.java @@ -0,0 +1,33 @@ +/* + * Copyright 2023-2024 the original author or 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 + * + * https://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 org.springframework.grpc.autoconfigure.server.health; + +import org.springframework.boot.actuate.health.HealthContributor; +import org.springframework.boot.actuate.health.HealthEndpoint; + +import io.grpc.protobuf.services.HealthStatusManager; + +/** + * Adapts {@link HealthContributor Actuator health checks} into gRPC health checks by + * periodically invoking {@link HealthEndpoint health endpoints} and updating the health + * status in gRPC {@link HealthStatusManager}. + * + * @author Chris Bono + */ +public class ActuatorHealthAdapter { + +} diff --git a/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/GrpcServerHealthAutoConfiguration.java b/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/health/GrpcServerHealthAutoConfiguration.java similarity index 87% rename from spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/GrpcServerHealthAutoConfiguration.java rename to spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/health/GrpcServerHealthAutoConfiguration.java index 256f344..8fbd596 100644 --- a/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/GrpcServerHealthAutoConfiguration.java +++ b/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/health/GrpcServerHealthAutoConfiguration.java @@ -16,9 +16,8 @@ * Partial copy from net.devh:grpc-spring-boot-starter. */ -package org.springframework.grpc.autoconfigure.server; +package org.springframework.grpc.autoconfigure.server.health; -import org.springframework.boot.actuate.health.HealthContributor; import org.springframework.boot.actuate.health.HealthEndpoint; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -30,6 +29,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.grpc.autoconfigure.server.GrpcServerFactoryAutoConfiguration; +import org.springframework.grpc.autoconfigure.server.GrpcServerProperties; import io.grpc.BindableService; import io.grpc.protobuf.services.HealthStatusManager; @@ -71,13 +72,4 @@ public class GrpcServerHealthAutoConfiguration { } - /** - * Adapts {@link HealthContributor Actuator health checks} into gRPC health checks by - * periodically invoking {@link HealthEndpoint health endpoints} and updating the - * health status in gRPC {@link HealthStatusManager}. - */ - static class ActuatorHealthAdapter { - - } - } diff --git a/spring-grpc-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-grpc-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 0351d81..195bf58 100644 --- a/spring-grpc-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/spring-grpc-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,7 +1,7 @@ org.springframework.grpc.autoconfigure.client.GrpcClientAutoConfiguration org.springframework.grpc.autoconfigure.server.GrpcServerFactoryAutoConfiguration org.springframework.grpc.autoconfigure.server.GrpcServerAutoConfiguration -org.springframework.grpc.autoconfigure.server.GrpcServerHealthAutoConfiguration +org.springframework.grpc.autoconfigure.server.health.GrpcServerHealthAutoConfiguration org.springframework.grpc.autoconfigure.server.GrpcServerObservationAutoConfiguration org.springframework.grpc.autoconfigure.server.GrpcServerReflectionAutoConfiguration org.springframework.grpc.autoconfigure.server.exception.GrpcExceptionHandlerAutoConfiguration diff --git a/spring-grpc-spring-boot-autoconfigure/src/test/java/org/springframework/grpc/autoconfigure/server/GrpcServerHealthAutoConfigurationTests.java b/spring-grpc-spring-boot-autoconfigure/src/test/java/org/springframework/grpc/autoconfigure/server/health/GrpcServerHealthAutoConfigurationTests.java similarity index 95% rename from spring-grpc-spring-boot-autoconfigure/src/test/java/org/springframework/grpc/autoconfigure/server/GrpcServerHealthAutoConfigurationTests.java rename to spring-grpc-spring-boot-autoconfigure/src/test/java/org/springframework/grpc/autoconfigure/server/health/GrpcServerHealthAutoConfigurationTests.java index 4e1c2f3..8481e84 100644 --- a/spring-grpc-spring-boot-autoconfigure/src/test/java/org/springframework/grpc/autoconfigure/server/GrpcServerHealthAutoConfigurationTests.java +++ b/spring-grpc-spring-boot-autoconfigure/src/test/java/org/springframework/grpc/autoconfigure/server/health/GrpcServerHealthAutoConfigurationTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.grpc.autoconfigure.server; +package org.springframework.grpc.autoconfigure.server.health; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -34,8 +34,9 @@ import org.springframework.boot.ssl.SslBundles; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.grpc.autoconfigure.server.GrpcServerHealthAutoConfiguration.ActuatorHealthAdapter; -import org.springframework.grpc.autoconfigure.server.GrpcServerHealthAutoConfiguration.ActuatorHealthAdapterConfiguration; +import org.springframework.grpc.autoconfigure.server.GrpcServerFactoryAutoConfiguration; +import org.springframework.grpc.autoconfigure.server.ServerBuilderCustomizers; +import org.springframework.grpc.autoconfigure.server.health.GrpcServerHealthAutoConfiguration.ActuatorHealthAdapterConfiguration; import org.springframework.grpc.server.lifecycle.GrpcServerLifecycle; import org.springframework.grpc.server.service.GrpcServiceDiscoverer; import org.springframework.util.StringUtils;