io.smallrye.health.SmallRyeHealthReporter Java Examples

The following examples show how to use io.smallrye.health.SmallRyeHealthReporter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HealthExtension.java    From thorntail with Apache License 2.0 6 votes vote down vote up
public void afterDeploymentValidation(@Observes final AfterDeploymentValidation abd, BeanManager beanManager) {
    try {
        if (delegate != null) {
            Unmanaged<SmallRyeHealthReporter> unmanagedHealthCheck =
                new Unmanaged<>(beanManager, SmallRyeHealthReporter.class);
            reporterInstance = unmanagedHealthCheck.newInstance();
            reporter =  reporterInstance.produce().inject().postConstruct().get();
            monitor.registerHealthReporter(reporter);

            // THORN-2195: Use the correct TCCL when health checks are obtained
            // In WildFly, the TCCL should always be set to the top-level deployment CL during extension notification
            monitor.registerContextClassLoader(Thread.currentThread().getContextClassLoader());

            log.info(">> Added health reporter bean " + reporter);
            delegate = null;
        }

    } catch (Exception e) {
        throw new RuntimeException("Failed to register health reporter bean", e);
    }
}
 
Example #2
Source File: HttpContexts.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    if (NODE.equals(exchange.getRequestPath())) {
        nodeInfo(exchange);
        return;
    } else if (HEAP.equals(exchange.getRequestPath())) {
        heap(exchange);
        return;
    } else if (THREADS.equals(exchange.getRequestPath())) {
        threads(exchange);
        return;
    } else if (HEALTH.equals(exchange.getRequestPath())) {
        health(exchange, SmallRyeHealthReporter::getHealth, this::defaultUpHealthInfo);
        return;
    } else if (HEALTH_LIVE.equals(exchange.getRequestPath())) {
        health(exchange, SmallRyeHealthReporter::getLiveness, this::defaultUpHealthInfo);
        return;
    } else if (HEALTH_READY.equals(exchange.getRequestPath())) {
        health(exchange, SmallRyeHealthReporter::getReadiness, this::defaultDownHealthInfo);
        return;
    }

    next.handleRequest(exchange);
}
 
Example #3
Source File: SmallRyeHealthHandlerBase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private void doHandle(RoutingContext ctx) {
    SmallRyeHealthReporter reporter = Arc.container().instance(SmallRyeHealthReporter.class).get();
    SmallRyeHealth health = getHealth(reporter, ctx);
    HttpServerResponse resp = ctx.response();
    if (health.isDown()) {
        resp.setStatusCode(503);
    }
    resp.headers().set(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
        reporter.reportHealth(outputStream, health);
        resp.end(Buffer.buffer(outputStream.toByteArray()));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #4
Source File: SmallRyeHealthProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BuildStep
@Record(ExecutionTime.STATIC_INIT)
@SuppressWarnings("unchecked")
void build(SmallRyeHealthRecorder recorder, RecorderContext recorderContext,
        BuildProducer<FeatureBuildItem> feature,
        BuildProducer<AdditionalBeanBuildItem> additionalBean,
        BuildProducer<BeanDefiningAnnotationBuildItem> beanDefiningAnnotation,
        BuildProducer<NotFoundPageDisplayableEndpointBuildItem> displayableEndpoints,
        LaunchModeBuildItem launchModeBuildItem) throws IOException {

    feature.produce(new FeatureBuildItem(Feature.SMALLRYE_HEALTH));

    // add health endpoints to not found page
    if (launchModeBuildItem.getLaunchMode().isDevOrTest()) {
        displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(health.rootPath));
        displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(health.rootPath + health.livenessPath));
        displayableEndpoints
                .produce(new NotFoundPageDisplayableEndpointBuildItem(health.rootPath + health.readinessPath));
        displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(health.rootPath + health.groupPath));
    }

    // Discover the beans annotated with @Health, @Liveness, @Readiness, @HealthGroup and @HealthGroups even if no scope is defined
    beanDefiningAnnotation.produce(new BeanDefiningAnnotationBuildItem(HEALTH));
    beanDefiningAnnotation.produce(new BeanDefiningAnnotationBuildItem(LIVENESS));
    beanDefiningAnnotation.produce(new BeanDefiningAnnotationBuildItem(READINESS));
    beanDefiningAnnotation.produce(new BeanDefiningAnnotationBuildItem(HEALTH_GROUP));
    beanDefiningAnnotation.produce(new BeanDefiningAnnotationBuildItem(HEALTH_GROUPS));

    // Add additional beans
    additionalBean.produce(new AdditionalBeanBuildItem(SmallRyeHealthReporter.class));

    // Make ArC discover @HealthGroup as a qualifier
    additionalBean.produce(new AdditionalBeanBuildItem(HealthGroup.class));

    // Discover and register the HealthCheckResponseProvider
    Set<String> providers = ServiceUtil.classNamesNamedIn(getClass().getClassLoader(),
            "META-INF/services/" + HealthCheckResponseProvider.class.getName());

    if (providers.isEmpty()) {
        throw new IllegalStateException("No HealthCheckResponseProvider implementation found.");
    } else if (providers.size() > 1) {
        throw new IllegalStateException(
                String.format("Multiple HealthCheckResponseProvider implementations found: %s", providers));
    }

    recorder.registerHealthCheckResponseProvider(
            (Class<? extends HealthCheckResponseProvider>) recorderContext.classProxy(providers.iterator().next()));
}
 
Example #5
Source File: SmallRyeHealthGroupHandler.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
protected SmallRyeHealth getHealth(SmallRyeHealthReporter reporter, RoutingContext ctx) {
    return reporter.getHealthGroups();
}
 
Example #6
Source File: SmallRyeHealthHandler.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
protected SmallRyeHealth getHealth(SmallRyeHealthReporter reporter, RoutingContext ctx) {
    return reporter.getHealth();
}
 
Example #7
Source File: SmallRyeLivenessHandler.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
protected SmallRyeHealth getHealth(SmallRyeHealthReporter reporter, RoutingContext ctx) {
    return reporter.getLiveness();
}
 
Example #8
Source File: SmallRyeIndividualHealthGroupHandler.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
protected SmallRyeHealth getHealth(SmallRyeHealthReporter reporter, RoutingContext ctx) {
    String group = ctx.normalisedPath().substring(ctx.normalisedPath().lastIndexOf("/") + 1);
    return reporter.getHealthGroup(group);
}
 
Example #9
Source File: SmallRyeReadinessHandler.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
protected SmallRyeHealth getHealth(SmallRyeHealthReporter reporter, RoutingContext routingContext) {
    return reporter.getReadiness();
}
 
Example #10
Source File: HealthExtension.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public void observeResources(@Observes ProcessAnnotatedType<SmallRyeHealthReporter> event) {
    delegate = event.getAnnotatedType();
}
 
Example #11
Source File: SmallRyeHealthHandlerBase.java    From quarkus with Apache License 2.0 votes vote down vote up
protected abstract SmallRyeHealth getHealth(SmallRyeHealthReporter reporter, RoutingContext routingContext);