Skip to content

Commit

Permalink
Merge pull request #42444 from gsmet/fix-smallrye-health-roots
Browse files Browse the repository at this point in the history
Fix consistency of SmallRye Health config roots
  • Loading branch information
gsmet authored Aug 9, 2024
2 parents 7e7de79 + 5f3f6e7 commit 818a58d
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.smallrye.health.deployment;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;

/**
* This class is deprecated, don't add any more properties here.
*
* When dropping this class please make the properties in {@link SmallRyeHealthBuildTimeConfig} non optional.
*
* @deprecated Use {@link SmallRyeHealthBuildTimeConfig} instead.
*/
@ConfigRoot(name = "health")
@Deprecated(since = "3.14", forRemoval = true)
public class DeprecatedHealthBuildTimeConfig {

/**
* Whether extensions published health check should be enabled.
*
* @deprecated Use {@code quarkus.smallrye-health.extensions.enabled} instead.
*/
@ConfigItem(name = "extensions.enabled", defaultValue = "true")
@Deprecated(since = "3.14", forRemoval = true)
public boolean extensionsEnabled;

/**
* Whether to include the Liveness and Readiness Health endpoints in the generated OpenAPI document
*
* @deprecated Use {@code quarkus.smallrye-health.openapi.included} instead.
*/
@ConfigItem(name = "openapi.included", defaultValue = "false")
@Deprecated(since = "3.14", forRemoval = true)
public boolean openapiIncluded;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

public class SmallRyeHealthActive implements BooleanSupplier {

private final HealthBuildTimeConfig config;
private final SmallRyeHealthBuildTimeConfig config;

SmallRyeHealthActive(HealthBuildTimeConfig config) {
SmallRyeHealthActive(SmallRyeHealthBuildTimeConfig config) {
this.config = config;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.quarkus.smallrye.health.deployment;

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;

@ConfigRoot(name = "health")
public class HealthBuildTimeConfig {
@ConfigRoot(name = "smallrye-health")
public class SmallRyeHealthBuildTimeConfig {
/**
* Activate or disable this extension. Disabling this extension means that no health related information is exposed.
*/
Expand All @@ -14,12 +16,12 @@ public class HealthBuildTimeConfig {
/**
* Whether extensions published health check should be enabled.
*/
@ConfigItem(name = "extensions.enabled", defaultValue = "true")
public boolean extensionsEnabled;
@ConfigItem(name = "extensions.enabled", defaultValueDocumentation = "true")
public Optional<Boolean> extensionsEnabled;

/**
* Whether to include the Liveness and Readiness Health endpoints in the generated OpenAPI document
*/
@ConfigItem(name = "openapi.included", defaultValue = "false")
public boolean openapiIncluded;
@ConfigItem(name = "openapi.included", defaultValueDocumentation = "false")
public Optional<Boolean> openapiIncluded;
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,14 @@ class SmallRyeHealthProcessor {
"key-files");

static class OpenAPIIncluded implements BooleanSupplier {
HealthBuildTimeConfig config;
SmallRyeHealthBuildTimeConfig smallryeHealthBuildTimeConfig;
DeprecatedHealthBuildTimeConfig deprecatedHealthBuildTimeConfig;

public boolean getAsBoolean() {
return config.openapiIncluded;
return smallryeHealthBuildTimeConfig.openapiIncluded.orElse(deprecatedHealthBuildTimeConfig.openapiIncluded);
}
}

HealthBuildTimeConfig config;

@BuildStep
List<HotDeploymentWatchedFileBuildItem> brandingFiles() {
return Stream.of(BRANDING_LOGO_GENERAL,
Expand All @@ -140,8 +139,11 @@ List<HotDeploymentWatchedFileBuildItem> brandingFiles() {

@BuildStep
void healthCheck(BuildProducer<AdditionalBeanBuildItem> buildItemBuildProducer,
List<HealthBuildItem> healthBuildItems) {
boolean extensionsEnabled = config.extensionsEnabled &&
List<HealthBuildItem> healthBuildItems,
SmallRyeHealthBuildTimeConfig smallryeHealthBuildTimeConfig,
DeprecatedHealthBuildTimeConfig deprecatedHealthBuildTimeConfig) {
boolean extensionsEnabled = smallryeHealthBuildTimeConfig.extensionsEnabled
.orElse(deprecatedHealthBuildTimeConfig.extensionsEnabled) &&
!ConfigProvider.getConfig().getOptionalValue("mp.health.disable-default-procedures", boolean.class)
.orElse(false);
if (extensionsEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DeactiveHealthWithConfigTest {
.withApplicationRoot((jar) -> jar
.addClasses(BasicHealthCheck.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"))
.overrideConfigKey("quarkus.health.enabled", "false");
.overrideConfigKey("quarkus.smallrye-health.enabled", "false");

@Test
void testAdditionalJsonPropertyInclusions() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.quarkus.smallrye.health.test;

import org.hamcrest.Matchers;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

@Deprecated(since = "3.14", forRemoval = true)
class DeprecatedHealthOpenAPITest {

private static final String OPEN_API_PATH = "/q/openapi";

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(BasicHealthCheck.class, OpenApiRoute.class)
.addAsResource(new StringAsset("quarkus.health.openapi.included=true\n"
+ "quarkus.smallrye-openapi.store-schema-directory=target"), "application.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));

@Test
void testOpenApiPathAccessResource() {

RestAssured.given().header("Accept", "application/json")
.when().get(OPEN_API_PATH)
.then()
.header("Content-Type", "application/json;charset=UTF-8")
.body("paths", Matchers.hasKey("/q/health/ready"))
.body("paths", Matchers.hasKey("/q/health/live"))
.body("paths", Matchers.hasKey("/q/health/started"))
.body("paths", Matchers.hasKey("/q/health"))
.body("components.schemas.HealthCheckResponse.type", Matchers.equalTo("object"));

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class HealthOpenAPITest {
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(BasicHealthCheck.class, OpenApiRoute.class)
.addAsResource(new StringAsset("quarkus.health.openapi.included=true\n"
.addAsResource(new StringAsset("quarkus.smallrye-health.openapi.included=true\n"
+ "quarkus.smallrye-openapi.store-schema-directory=target"), "application.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));

Expand Down

0 comments on commit 818a58d

Please sign in to comment.