Search in sources :

Example 1 with NotFoundHandler

use of org.keycloak.quarkus.runtime.integration.web.NotFoundHandler in project keycloak by keycloak.

the class KeycloakProcessor method initializeMetrics.

/**
 * <p>Initialize metrics and health endpoints.
 *
 * <p>The only reason for manually registering these endpoints is that by default they run as blocking hence
 * running in a different thread than the worker thread started by {@link QuarkusRequestFilter}.
 * See https://github.com/quarkusio/quarkus/issues/12990.
 *
 * <p>By doing this, custom health checks such as {@link org.keycloak.quarkus.runtime.services.health.KeycloakReadyHealthCheck} is
 * executed within an active {@link org.keycloak.models.KeycloakSession}, making possible to use it when calculating the
 * status.
 *
 * @param routes
 */
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
void initializeMetrics(KeycloakRecorder recorder, BuildProducer<RouteBuildItem> routes, NonApplicationRootPathBuildItem nonAppRootPath) {
    final Handler<RoutingContext> healthHandler = (isHealthEnabled()) ? new SmallRyeHealthHandler() : new NotFoundHandler();
    Handler<RoutingContext> metricsHandler;
    if (isMetricsEnabled()) {
        String rootPath = nonAppRootPath.getNormalizedHttpRootPath();
        metricsHandler = recorder.createMetricsHandler(rootPath.concat(DEFAULT_METRICS_ENDPOINT).replace("//", "/"));
    } else {
        metricsHandler = new NotFoundHandler();
    }
    routes.produce(RouteBuildItem.builder().route(DEFAULT_HEALTH_ENDPOINT).handler(healthHandler).build());
    routes.produce(RouteBuildItem.builder().route(DEFAULT_HEALTH_ENDPOINT.concat("/live")).handler(healthHandler).build());
    routes.produce(RouteBuildItem.builder().route(DEFAULT_HEALTH_ENDPOINT.concat("/ready")).handler(healthHandler).build());
    routes.produce(RouteBuildItem.builder().route(DEFAULT_METRICS_ENDPOINT).handler(metricsHandler).build());
}
Also used : SmallRyeHealthHandler(io.quarkus.smallrye.health.runtime.SmallRyeHealthHandler) RoutingContext(io.vertx.ext.web.RoutingContext) NotFoundHandler(org.keycloak.quarkus.runtime.integration.web.NotFoundHandler) Record(io.quarkus.deployment.annotations.Record) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)1 Record (io.quarkus.deployment.annotations.Record)1 SmallRyeHealthHandler (io.quarkus.smallrye.health.runtime.SmallRyeHealthHandler)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 NotFoundHandler (org.keycloak.quarkus.runtime.integration.web.NotFoundHandler)1