public HealthCheckResponse call()

in jobs-service/jobs-service-messaging-http/src/main/java/org/kie/kogito/jobs/service/messaging/http/health/knative/KSinkInjectionHealthCheck.java [55:85]


    public HealthCheckResponse call() {
        final HealthCheckResponseBuilder responseBuilder = HealthCheckResponse.named("K_SINK environment variable injection check");
        final String sinkURL = envReader.apply(K_SINK);
        String reason;
        Exception cause = null;
        if (sinkURL == null || sinkURL.isEmpty()) {
            reason = K_SINK + " variable not set in this environment";
            LOGGER.warn("{}. Returning not healthy.", reason);
        } else {
            try {
                final URI uri = new URI(sinkURL);
                final InetAddress address = InetAddress.getByName(uri.getHost());
                if (address != null) {
                    responseBuilder.up();
                    return responseBuilder.build();
                } else {
                    reason = "Impossible to resolve host: " + uri.getHost() + " for URL: " + sinkURL;
                    LOGGER.warn("{}. Check if this host can be resolved from this environment. Returning not healthy.", reason);
                }
            } catch (UnknownHostException e) {
                reason = "Failed to lookup address: " + sinkURL;
                cause = e;
                LOGGER.warn("{}. Returning not healthy.", reason);
            } catch (URISyntaxException e) {
                reason = "The " + K_SINK + " URL syntax is invalid: " + sinkURL;
                cause = e;
                LOGGER.warn(reason + ". Returning not healthy.", e);
            }
        }
        return responseBuilder.withData("reason", buildMessage(reason, cause)).down().build();
    }