Skip to content

Commit

Permalink
Allow disabling health extension with configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
xstefank committed Aug 7, 2024
1 parent fb0009e commit d7a842c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(name = "active", defaultValue = "true")
public boolean active;

/**
* Whether extensions published health check should be enabled.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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.active;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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;
Expand Down Expand Up @@ -80,6 +81,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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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.active", "false");

@Test
void testAdditionalJsonPropertyInclusions() {
try {
RestAssured.defaultParser = Parser.JSON;
RestAssured.when().get("/q/health").then()
.statusCode(404);
} finally {
RestAssured.reset();
}
}

}

0 comments on commit d7a842c

Please sign in to comment.