Skip to content

Commit 937a078

Browse files
authored
Merge pull request #42361 from xstefank/disable-health-i42356
Allow disabling health extension with configuration
2 parents 075f28b + 71f02d7 commit 937a078

File tree

5 files changed

+71
-5
lines changed

5 files changed

+71
-5
lines changed

extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/HealthBuildTimeConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
@ConfigRoot(name = "health")
77
public class HealthBuildTimeConfig {
8+
/**
9+
* Activate or disable this extension. Disabling this extension means that no health related information is exposed.
10+
*/
11+
@ConfigItem(defaultValue = "true")
12+
public boolean enabled;
13+
814
/**
915
* Whether extensions published health check should be enabled.
1016
*/
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.quarkus.smallrye.health.deployment;
2+
3+
import java.util.function.BooleanSupplier;
4+
5+
public class SmallRyeHealthActive implements BooleanSupplier {
6+
7+
private final HealthBuildTimeConfig config;
8+
9+
SmallRyeHealthActive(HealthBuildTimeConfig config) {
10+
this.config = config;
11+
}
12+
13+
@Override
14+
public boolean getAsBoolean() {
15+
return config.enabled;
16+
}
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.quarkus.smallrye.health.deployment;
2+
3+
import io.quarkus.deployment.Feature;
4+
import io.quarkus.deployment.annotations.BuildProducer;
5+
import io.quarkus.deployment.annotations.BuildStep;
6+
import io.quarkus.deployment.builditem.FeatureBuildItem;
7+
8+
public class SmallRyeHealthFeatureProcessor {
9+
10+
@BuildStep
11+
public void defineFeature(BuildProducer<FeatureBuildItem> feature) {
12+
feature.produce(new FeatureBuildItem(Feature.SMALLRYE_HEALTH));
13+
}
14+
}

extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@
3232
import io.quarkus.arc.processor.BuiltinScope;
3333
import io.quarkus.deployment.Capabilities;
3434
import io.quarkus.deployment.Capability;
35-
import io.quarkus.deployment.Feature;
3635
import io.quarkus.deployment.annotations.BuildProducer;
3736
import io.quarkus.deployment.annotations.BuildStep;
37+
import io.quarkus.deployment.annotations.BuildSteps;
3838
import io.quarkus.deployment.annotations.Consume;
3939
import io.quarkus.deployment.annotations.ExecutionTime;
4040
import io.quarkus.deployment.annotations.Record;
41-
import io.quarkus.deployment.builditem.FeatureBuildItem;
4241
import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem;
4342
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
4443
import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem;
@@ -80,6 +79,7 @@
8079
import io.vertx.core.Handler;
8180
import io.vertx.ext.web.RoutingContext;
8281

82+
@BuildSteps(onlyIf = SmallRyeHealthActive.class)
8383
class SmallRyeHealthProcessor {
8484
private static final Logger LOG = Logger.getLogger(SmallRyeHealthProcessor.class);
8585

@@ -157,14 +157,11 @@ void healthCheck(BuildProducer<AdditionalBeanBuildItem> buildItemBuildProducer,
157157
@Record(ExecutionTime.STATIC_INIT)
158158
@SuppressWarnings("unchecked")
159159
void build(SmallRyeHealthRecorder recorder,
160-
BuildProducer<FeatureBuildItem> feature,
161160
BuildProducer<ExcludedTypeBuildItem> excludedTypes,
162161
BuildProducer<AdditionalBeanBuildItem> additionalBean,
163162
BuildProducer<BeanDefiningAnnotationBuildItem> beanDefiningAnnotation)
164163
throws IOException, ClassNotFoundException {
165164

166-
feature.produce(new FeatureBuildItem(Feature.SMALLRYE_HEALTH));
167-
168165
// Discover the beans annotated with @Health, @Liveness, @Readiness, @Startup, @HealthGroup,
169166
// @HealthGroups and @Wellness even if no scope is defined
170167
beanDefiningAnnotation.produce(new BeanDefiningAnnotationBuildItem(LIVENESS, BuiltinScope.SINGLETON.getName()));
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.quarkus.smallrye.health.test;
2+
3+
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
4+
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.api.extension.RegisterExtension;
6+
7+
import io.quarkus.test.QuarkusUnitTest;
8+
import io.restassured.RestAssured;
9+
import io.restassured.parsing.Parser;
10+
11+
class DeactiveHealthWithConfigTest {
12+
13+
@RegisterExtension
14+
static final QuarkusUnitTest config = new QuarkusUnitTest()
15+
.withApplicationRoot((jar) -> jar
16+
.addClasses(BasicHealthCheck.class)
17+
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"))
18+
.overrideConfigKey("quarkus.health.enabled", "false");
19+
20+
@Test
21+
void testAdditionalJsonPropertyInclusions() {
22+
try {
23+
RestAssured.defaultParser = Parser.JSON;
24+
RestAssured.when().get("/q/health").then()
25+
.statusCode(404);
26+
} finally {
27+
RestAssured.reset();
28+
}
29+
}
30+
31+
}

0 commit comments

Comments
 (0)