diff --git a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/HealthBuildTimeConfig.java b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/HealthBuildTimeConfig.java index b7bbb6ec3f816..1cca5c30fe8c2 100644 --- a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/HealthBuildTimeConfig.java +++ b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/HealthBuildTimeConfig.java @@ -5,6 +5,12 @@ @ConfigRoot(name = "health") public class HealthBuildTimeConfig { + /** + * Activate or disable this extension. Disabling this extension means that no health related information is exposed. + */ + @ConfigItem(defaultValue = "true") + public boolean enabled; + /** * Whether extensions published health check should be enabled. */ diff --git a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthActive.java b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthActive.java new file mode 100644 index 0000000000000..5eaac369674ec --- /dev/null +++ b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthActive.java @@ -0,0 +1,18 @@ +package io.quarkus.smallrye.health.deployment; + +import java.util.function.BooleanSupplier; + +public class SmallRyeHealthActive implements BooleanSupplier { + + private final HealthBuildTimeConfig config; + + SmallRyeHealthActive(HealthBuildTimeConfig config) { + this.config = config; + } + + @Override + public boolean getAsBoolean() { + return config.enabled; + } + +} diff --git a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthFeatureProcessor.java b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthFeatureProcessor.java new file mode 100644 index 0000000000000..13d5882b71bf2 --- /dev/null +++ b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthFeatureProcessor.java @@ -0,0 +1,14 @@ +package io.quarkus.smallrye.health.deployment; + +import io.quarkus.deployment.Feature; +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.FeatureBuildItem; + +public class SmallRyeHealthFeatureProcessor { + + @BuildStep + public void defineFeature(BuildProducer feature) { + feature.produce(new FeatureBuildItem(Feature.SMALLRYE_HEALTH)); + } +} diff --git a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java index 8b7101bf10751..e95a7d4e1b511 100644 --- a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java +++ b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java @@ -32,13 +32,12 @@ import io.quarkus.arc.processor.BuiltinScope; import io.quarkus.deployment.Capabilities; import io.quarkus.deployment.Capability; -import io.quarkus.deployment.Feature; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.annotations.BuildSteps; import io.quarkus.deployment.annotations.Consume; import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Record; -import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem; @@ -80,6 +79,7 @@ import io.vertx.core.Handler; import io.vertx.ext.web.RoutingContext; +@BuildSteps(onlyIf = SmallRyeHealthActive.class) class SmallRyeHealthProcessor { private static final Logger LOG = Logger.getLogger(SmallRyeHealthProcessor.class); @@ -157,14 +157,11 @@ void healthCheck(BuildProducer buildItemBuildProducer, @Record(ExecutionTime.STATIC_INIT) @SuppressWarnings("unchecked") void build(SmallRyeHealthRecorder recorder, - BuildProducer feature, BuildProducer excludedTypes, BuildProducer additionalBean, BuildProducer beanDefiningAnnotation) throws IOException, ClassNotFoundException { - feature.produce(new FeatureBuildItem(Feature.SMALLRYE_HEALTH)); - // Discover the beans annotated with @Health, @Liveness, @Readiness, @Startup, @HealthGroup, // @HealthGroups and @Wellness even if no scope is defined beanDefiningAnnotation.produce(new BeanDefiningAnnotationBuildItem(LIVENESS, BuiltinScope.SINGLETON.getName())); diff --git a/extensions/smallrye-health/deployment/src/test/java/io/quarkus/smallrye/health/test/DeactiveHealthWithConfigTest.java b/extensions/smallrye-health/deployment/src/test/java/io/quarkus/smallrye/health/test/DeactiveHealthWithConfigTest.java new file mode 100644 index 0000000000000..a655c4e928a65 --- /dev/null +++ b/extensions/smallrye-health/deployment/src/test/java/io/quarkus/smallrye/health/test/DeactiveHealthWithConfigTest.java @@ -0,0 +1,31 @@ +package io.quarkus.smallrye.health.test; + +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; +import io.restassured.parsing.Parser; + +class DeactiveHealthWithConfigTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClasses(BasicHealthCheck.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")) + .overrideConfigKey("quarkus.health.enabled", "false"); + + @Test + void testAdditionalJsonPropertyInclusions() { + try { + RestAssured.defaultParser = Parser.JSON; + RestAssured.when().get("/q/health").then() + .statusCode(404); + } finally { + RestAssured.reset(); + } + } + +}