Repository: quarkusio/quarkus
Issue: Health configuration reference does not reflect the new /q namespace

The documentation at https://quarkus.io/guides/microprofile-health#configuration-reference does not reflect the new /q/.. namespace these endpoint defaults have been moved to.



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

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 c86e957657a..3f8d8135b59 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
@@ -163,14 +163,15 @@ void build(SmallRyeHealthRecorder recorder,
         if (launchMode.getLaunchMode().isDevOrTest()) {
             String basePath = nonApplicationRootPathBuildItem.adjustPath(healthConfig.rootPath);
             displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(basePath));
+            String subcontextBasePath = adjustSubcontextBasePath(basePath);
             displayableEndpoints
-                    .produce(new NotFoundPageDisplayableEndpointBuildItem(basePath + healthConfig.livenessPath));
+                    .produce(new NotFoundPageDisplayableEndpointBuildItem(subcontextBasePath + healthConfig.livenessPath));
             displayableEndpoints
-                    .produce(new NotFoundPageDisplayableEndpointBuildItem(basePath + healthConfig.readinessPath));
+                    .produce(new NotFoundPageDisplayableEndpointBuildItem(subcontextBasePath + healthConfig.readinessPath));
             displayableEndpoints
-                    .produce(new NotFoundPageDisplayableEndpointBuildItem(basePath + healthConfig.groupPath));
+                    .produce(new NotFoundPageDisplayableEndpointBuildItem(subcontextBasePath + healthConfig.groupPath));
             displayableEndpoints
-                    .produce(new NotFoundPageDisplayableEndpointBuildItem(basePath + healthConfig.wellnessPath));
+                    .produce(new NotFoundPageDisplayableEndpointBuildItem(subcontextBasePath + healthConfig.wellnessPath));
         }
 
         // Discover the beans annotated with @Health, @Liveness, @Readiness, @HealthGroup,
@@ -225,9 +226,11 @@ public void defineHealthRoutes(BuildProducer<RouteBuildItem> routes,
                 .nonApplicationRoute()
                 .build());
 
+        String subcontextBasePath = adjustSubcontextBasePath(healthConfig.rootPath);
+
         // Register the liveness handler
         routes.produce(new RouteBuildItem.Builder()
-                .route(healthConfig.rootPath + healthConfig.livenessPath)
+                .route(subcontextBasePath + healthConfig.livenessPath)
                 .handler(new SmallRyeLivenessHandler())
                 .blockingRoute()
                 .nonApplicationRoute()
@@ -235,7 +238,7 @@ public void defineHealthRoutes(BuildProducer<RouteBuildItem> routes,
 
         // Register the readiness handler
         routes.produce(new RouteBuildItem.Builder()
-                .route(healthConfig.rootPath + healthConfig.readinessPath)
+                .route(subcontextBasePath + healthConfig.readinessPath)
                 .handler(new SmallRyeReadinessHandler())
                 .blockingRoute()
                 .nonApplicationRoute()
@@ -256,7 +259,7 @@ public void defineHealthRoutes(BuildProducer<RouteBuildItem> routes,
 
         // Register the health group handlers
         routes.produce(new RouteBuildItem.Builder()
-                .route(healthConfig.rootPath + healthConfig.groupPath)
+                .route(subcontextBasePath + healthConfig.groupPath)
                 .handler(new SmallRyeHealthGroupHandler())
                 .blockingRoute()
                 .nonApplicationRoute()
@@ -265,7 +268,7 @@ public void defineHealthRoutes(BuildProducer<RouteBuildItem> routes,
         SmallRyeIndividualHealthGroupHandler handler = new SmallRyeIndividualHealthGroupHandler();
         for (String healthGroup : healthGroups) {
             routes.produce(new RouteBuildItem.Builder()
-                    .route(healthConfig.rootPath + healthConfig.groupPath + "/" + healthGroup)
+                    .route(subcontextBasePath + healthConfig.groupPath + "/" + healthGroup)
                     .handler(handler)
                     .blockingRoute()
                     .nonApplicationRoute()
@@ -274,7 +277,7 @@ public void defineHealthRoutes(BuildProducer<RouteBuildItem> routes,
 
         // Register the wellness handler
         routes.produce(new RouteBuildItem.Builder()
-                .route(healthConfig.rootPath + healthConfig.wellnessPath)
+                .route(subcontextBasePath + healthConfig.wellnessPath)
                 .handler(new SmallRyeWellnessHandler())
                 .blockingRoute()
                 .nonApplicationRoute()
@@ -292,9 +295,10 @@ public void includeInOpenAPIEndpoint(BuildProducer<AddToOpenAPIDefinitionBuildIt
         // Add to OpenAPI if OpenAPI is available
         if (capabilities.isPresent(Capability.SMALLRYE_OPENAPI)) {
             String basePath = httpRootPath.adjustPath(nonApplicationRootPathBuildItem.adjustPath(healthConfig.rootPath));
+            String subcontextBasePath = adjustSubcontextBasePath(basePath);
             HealthOpenAPIFilter filter = new HealthOpenAPIFilter(basePath,
-                    basePath + healthConfig.livenessPath,
-                    basePath + healthConfig.readinessPath);
+                    subcontextBasePath + healthConfig.livenessPath,
+                    subcontextBasePath + healthConfig.readinessPath);
             openAPIProducer.produce(new AddToOpenAPIDefinitionBuildItem(filter));
         }
     }
@@ -328,14 +332,16 @@ public void kubernetes(HttpBuildTimeConfig httpConfig, NonApplicationRootPathBui
             BuildProducer<KubernetesHealthLivenessPathBuildItem> livenessPathItemProducer,
             BuildProducer<KubernetesHealthReadinessPathBuildItem> readinessPathItemProducer) {
 
+        String subcontextBasePath = adjustSubcontextBasePath(healthConfig.rootPath);
+
         livenessPathItemProducer.produce(
                 new KubernetesHealthLivenessPathBuildItem(
                         httpConfig
-                                .adjustPath(frameworkRootPath.adjustPath(healthConfig.rootPath + healthConfig.livenessPath))));
+                                .adjustPath(frameworkRootPath.adjustPath(subcontextBasePath + healthConfig.livenessPath))));
         readinessPathItemProducer.produce(
                 new KubernetesHealthReadinessPathBuildItem(
                         httpConfig
-                                .adjustPath(frameworkRootPath.adjustPath(healthConfig.rootPath + healthConfig.readinessPath))));
+                                .adjustPath(frameworkRootPath.adjustPath(subcontextBasePath + healthConfig.readinessPath))));
     }
 
     @BuildStep
@@ -390,7 +396,6 @@ public void transform(TransformationContext ctx) {
     }
 
     // UI
-
     @BuildStep
     void registerUiExtension(
             BuildProducer<GeneratedResourceBuildItem> generatedResourceProducer,
@@ -499,4 +504,8 @@ public String updateApiUrl(String original, String healthPath) {
     private static boolean shouldInclude(LaunchModeBuildItem launchMode, SmallRyeHealthConfig healthConfig) {
         return launchMode.getLaunchMode().isDevOrTest() || healthConfig.ui.alwaysInclude;
     }
+
+    private String adjustSubcontextBasePath(String basePath) {
+        return basePath.equals("/") ? "" : basePath;
+    }
 }