Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix consistency of SmallRye Health config roots #42444

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the test can stay right, we just need to update the config? This test needs to be updated nevertheless. Just mentioning it so it's not removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the test will get dropped. I added another test with the updated config (but GitHub shows it to you the other way around).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now.

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
Loading