Skip to content

Commit

Permalink
WIP - management interface
Browse files Browse the repository at this point in the history
  • Loading branch information
cescoffier committed Jan 23, 2023
1 parent c8a2a45 commit 6941cfe
Show file tree
Hide file tree
Showing 21 changed files with 1,240 additions and 451 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void createPrometheusRoute(BuildProducer<RouteBuildItem> routes,

// Exact match for resources matched to the root path
routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.management()
.routeFunction(pConfig.path, recorder.route())
.routeConfigKey("quarkus.micrometer.export.prometheus.path")
.handler(recorder.getHandler())
Expand All @@ -104,17 +105,20 @@ void createPrometheusRoute(BuildProducer<RouteBuildItem> routes,

// Match paths that begin with the deployment path
routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.management()
.routeFunction(pConfig.path + (pConfig.path.endsWith("/") ? "*" : "/*"), recorder.route())
.handler(recorder.getHandler())
.blockingRoute()
.build());

// Fallback paths (for non text/plain requests)
routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.management()
.routeFunction(pConfig.path, recorder.fallbackRoute())
.handler(recorder.getFallbackHandler())
.build());
routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.management()
.routeFunction(pConfig.path + (pConfig.path.endsWith("/") ? "*" : "/*"), recorder.fallbackRoute())
.handler(recorder.getFallbackHandler())
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.configuration.ConfigInstantiator;
import io.quarkus.vertx.http.runtime.management.ManagementInterfaceBuildTimeConfig;
import io.quarkus.vertx.http.runtime.HttpBuildTimeConfig;
import io.quarkus.vertx.http.runtime.HttpConfiguration;
import io.quarkus.vertx.http.runtime.VertxHttpRecorder;
Expand All @@ -19,7 +20,8 @@ void setup(@Observes Router router) {
HttpConfiguration httpConfiguration = new HttpConfiguration();
ConfigInstantiator.handleObject(httpConfiguration);
Handler<RoutingContext> bodyHandler = new VertxHttpRecorder(new HttpBuildTimeConfig(),
new RuntimeValue<>(httpConfiguration))
new ManagementInterfaceBuildTimeConfig(),
new RuntimeValue<>(httpConfiguration), null)
.createBodyHandler();
router.route().order(Integer.MIN_VALUE + 1).handler(new Handler<RoutingContext>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import io.quarkus.vertx.http.deployment.webjar.WebJarBuildItem;
import io.quarkus.vertx.http.deployment.webjar.WebJarResourcesFilter;
import io.quarkus.vertx.http.deployment.webjar.WebJarResultsBuildItem;
import io.quarkus.vertx.http.runtime.management.ManagementInterfaceBuildTimeConfig;
import io.smallrye.health.SmallRyeHealthReporter;
import io.smallrye.health.api.HealthGroup;
import io.smallrye.health.api.HealthGroups;
Expand Down Expand Up @@ -197,6 +198,7 @@ public void defineHealthRoutes(BuildProducer<RouteBuildItem> routes,

// Register the health handler
routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.management()
.route(healthConfig.rootPath)
.routeConfigKey("quarkus.smallrye-health.root-path")
.handler(new SmallRyeHealthHandler())
Expand All @@ -206,6 +208,7 @@ public void defineHealthRoutes(BuildProducer<RouteBuildItem> routes,

// Register the liveness handler
routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.management()
.nestedRoute(healthConfig.rootPath, healthConfig.livenessPath)
.handler(new SmallRyeLivenessHandler())
.displayOnNotFoundPage()
Expand All @@ -214,6 +217,7 @@ public void defineHealthRoutes(BuildProducer<RouteBuildItem> routes,

// Register the readiness handler
routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.management()
.nestedRoute(healthConfig.rootPath, healthConfig.readinessPath)
.handler(new SmallRyeReadinessHandler())
.displayOnNotFoundPage()
Expand All @@ -235,6 +239,7 @@ public void defineHealthRoutes(BuildProducer<RouteBuildItem> routes,

// Register the health group handlers
routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.management()
.nestedRoute(healthConfig.rootPath, healthConfig.groupPath)
.handler(new SmallRyeHealthGroupHandler())
.displayOnNotFoundPage()
Expand All @@ -243,6 +248,7 @@ public void defineHealthRoutes(BuildProducer<RouteBuildItem> routes,

SmallRyeIndividualHealthGroupHandler handler = new SmallRyeIndividualHealthGroupHandler();
routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.management()
.nestedRoute(healthConfig.rootPath, healthConfig.groupPath + "/*")
.handler(handler)
.displayOnNotFoundPage()
Expand All @@ -251,6 +257,7 @@ public void defineHealthRoutes(BuildProducer<RouteBuildItem> routes,

// Register the wellness handler
routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.management()
.nestedRoute(healthConfig.rootPath, healthConfig.wellnessPath)
.handler(new SmallRyeWellnessHandler())
.displayOnNotFoundPage()
Expand All @@ -259,6 +266,7 @@ public void defineHealthRoutes(BuildProducer<RouteBuildItem> routes,

// Register the startup handler
routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.management()
.nestedRoute(healthConfig.rootPath, healthConfig.startupPath)
.handler(new SmallRyeStartupHandler())
.displayOnNotFoundPage()
Expand Down Expand Up @@ -287,17 +295,17 @@ public void processSmallRyeHealthConfigValues(SmallRyeHealthConfig healthConfig,
@BuildStep(onlyIf = OpenAPIIncluded.class)
public void includeInOpenAPIEndpoint(BuildProducer<AddToOpenAPIDefinitionBuildItem> openAPIProducer,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
ManagementInterfaceBuildTimeConfig managementInterfaceBuildTimeConfig,
Capabilities capabilities,
SmallRyeHealthConfig healthConfig) {

// Add to OpenAPI if OpenAPI is available
if (capabilities.isPresent(Capability.SMALLRYE_OPENAPI)) {
if (capabilities.isPresent(Capability.SMALLRYE_OPENAPI) && !managementInterfaceBuildTimeConfig.enabled) {
String healthRootPath = nonApplicationRootPathBuildItem.resolvePath(healthConfig.rootPath);

HealthOpenAPIFilter filter = new HealthOpenAPIFilter(healthRootPath,
nonApplicationRootPathBuildItem.resolveNestedPath(healthRootPath, healthConfig.livenessPath),
nonApplicationRootPathBuildItem.resolveNestedPath(healthRootPath, healthConfig.readinessPath),
nonApplicationRootPathBuildItem.resolveNestedPath(healthRootPath, healthConfig.startupPath));
nonApplicationRootPathBuildItem.resolveManagementNestedPath(healthRootPath, healthConfig.livenessPath),
nonApplicationRootPathBuildItem.resolveManagementNestedPath(healthRootPath, healthConfig.readinessPath),
nonApplicationRootPathBuildItem.resolveManagementNestedPath(healthRootPath, healthConfig.startupPath));

openAPIProducer.produce(new AddToOpenAPIDefinitionBuildItem(filter));
}
Expand Down Expand Up @@ -333,15 +341,19 @@ public void kubernetes(NonApplicationRootPathBuildItem nonApplicationRootPathBui
BuildProducer<KubernetesHealthReadinessPathBuildItem> readinessPathItemProducer,
BuildProducer<KubernetesHealthStartupPathBuildItem> startupPathItemProducer) {

// TODO Not that simple here... we need the port and stuff.
livenessPathItemProducer.produce(
new KubernetesHealthLivenessPathBuildItem(
nonApplicationRootPathBuildItem.resolveNestedPath(healthConfig.rootPath, healthConfig.livenessPath)));
nonApplicationRootPathBuildItem.resolveManagementNestedPath(healthConfig.rootPath,
healthConfig.livenessPath)));
readinessPathItemProducer.produce(
new KubernetesHealthReadinessPathBuildItem(
nonApplicationRootPathBuildItem.resolveNestedPath(healthConfig.rootPath, healthConfig.readinessPath)));
nonApplicationRootPathBuildItem.resolveManagementNestedPath(healthConfig.rootPath,
healthConfig.readinessPath)));
startupPathItemProducer.produce(
new KubernetesHealthStartupPathBuildItem(
nonApplicationRootPathBuildItem.resolveNestedPath(healthConfig.rootPath, healthConfig.startupPath)));
nonApplicationRootPathBuildItem.resolveManagementNestedPath(healthConfig.rootPath,
healthConfig.startupPath)));
}

@BuildStep
Expand All @@ -353,6 +365,7 @@ ShutdownListenerBuildItem shutdownListener() {
@BuildStep
void registerUiExtension(
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
ManagementInterfaceBuildTimeConfig managementInterfaceBuildTimeConfig,
SmallRyeHealthConfig healthConfig,
LaunchModeBuildItem launchModeBuildItem,
BuildProducer<WebJarBuildItem> webJarBuildProducer) {
Expand All @@ -365,7 +378,9 @@ void registerUiExtension(
Set.of("quarkus.smallrye-health.root-path-ui"));
}

String healthPath = nonApplicationRootPathBuildItem.resolvePath(healthConfig.rootPath);
String healthPath = nonApplicationRootPathBuildItem.resolveManagementPath(healthConfig.rootPath,
managementInterfaceBuildTimeConfig, launchModeBuildItem);
System.out.println("health path is " + healthPath);

webJarBuildProducer.produce(
WebJarBuildItem.builder().artifactKey(HEALTH_UI_WEBJAR_ARTIFACT_KEY) //
Expand Down Expand Up @@ -413,6 +428,7 @@ void registerHealthUiHandler(

Handler<RoutingContext> handler = recorder.uiHandler(result.getFinalDestination(),
healthUiPath, result.getWebRootConfigurations(), runtimeConfig, shutdownContext);
// The health ui is not a management route.
routeProducer.produce(nonApplicationRootPathBuildItem.routeBuilder()
.route(healthConfig.ui.rootPath)
.displayOnNotFoundPage("Health UI")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,13 @@ void createRoute(BuildProducer<RouteBuildItem> routes,
displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(metrics.path));
}
routes.produce(frameworkRoot.routeBuilder()
.management()
.route(metrics.path + (metrics.path.endsWith("/") ? "*" : "/*"))
.handler(recorder.handler(frameworkRoot.resolvePath(metrics.path)))
.blockingRoute()
.build());
routes.produce(frameworkRoot.routeBuilder()
.management()
.route(metrics.path)
.routeConfigKey("quarkus.smallrye-metrics.path")
.handler(recorder.handler(frameworkRoot.resolvePath(metrics.path)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,20 @@ public Builder routeConfigKey(String attributeName) {

@Override
public RouteBuildItem build() {
return new RouteBuildItem(this, routeType, routerType);
return new RouteBuildItem(this, routeType, routerType, isManagement);
}

@Override
protected ConfiguredPathInfo getRouteConfigInfo() {
return super.getRouteConfigInfo();
}

@Override
public Builder management() {
super.management();
return this;
}

@Override
protected NotFoundPageDisplayableEndpointBuildItem getNotFoundEndpoint() {
return super.getNotFoundEndpoint();
Expand Down
Loading

0 comments on commit 6941cfe

Please sign in to comment.