fmcejudo / quarkus-eureka

46 stars 24 forks source link

Instance can't reach own application health check. Ensure this has been implemented #22

Closed jdarosTD closed 2 years ago

jdarosTD commented 4 years ago

Hello. Firstly, thank you for this extension.

I've got actually a problem using it here is my configuration :

quarkus.eureka.host-name=localhost
quarkus.eureka.name=my-app-name
quarkus.eureka.vip-address=my-app-name
quarkus.eureka.home-page-url=/
quarkus.eureka.status-page-url=/info/status
quarkus.eureka.health-check-url=/info/health

quarkus.eureka.region=default
quarkus.eureka.prefer-same-zone=true
quarkus.eureka.service-url.default=https://[login]:[pwd]@[endpoint]/eureka

Here is my controller :

@Path("/info")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
class StatusResource {

    @GET
    @Path("/health")
    fun health() = Response.ok(mapOf("STATUS" to "UP")).build()

    @GET
    @Path("/status")
    fun status() = Response.ok("{}").build()
}

At startup I've got this error while everything works fine without the euraka dependency. Here no routes are available. I compiled the project myself thinking about the delay of 3 secondes inside EurekaRegistrationService could be not enough for the app to be ready, but nothing changed

e] (pool-3-thread-1) Auth cache not set in the context
2020-06-25 09:24:38,272 DEBUG [org.apa.htt.imp.con.PoolingHttpClientConnectionManager] (pool-3-thread-1) Connection request: [route: {}->http://localhost:8090][total available: 0; route allocated: 0 of 50; total allocated: 0 of 50]
2020-06-25 09:24:38,272 DEBUG [org.apa.htt.imp.con.PoolingHttpClientConnectionManager] (pool-3-thread-1) Connection leased: [id: 1][route: {}->http://localhost:8090][total available: 0; route allocated: 1 of 50; total allocated: 1 of 50]
2020-06-25 09:24:38,272 DEBUG [org.apa.htt.imp.exe.MainClientExec] (pool-3-thread-1) Opening connection {}->http://localhost:8090
2020-06-25 09:24:38,273 DEBUG [org.apa.htt.imp.con.DefaultHttpClientConnectionOperator] (pool-3-thread-1) Connecting to localhost/127.0.0.1:8090
2020-06-25 09:24:38,274 DEBUG [org.apa.htt.imp.con.DefaultHttpClientConnectionOperator] (pool-3-thread-1) Connection established 127.0.0.1:51155<->127.0.0.1:8090
2020-06-25 09:24:38,274 DEBUG [org.apa.htt.imp.exe.MainClientExec] (pool-3-thread-1) Executing request GET /info/health HTTP/1.1
2020-06-25 09:24:38,274 DEBUG [org.apa.htt.imp.exe.MainClientExec] (pool-3-thread-1) Target auth state: UNCHALLENGED
2020-06-25 09:24:38,275 DEBUG [org.apa.htt.imp.exe.MainClientExec] (pool-3-thread-1) Proxy auth state: UNCHALLENGED
2020-06-25 09:24:38,275 DEBUG [org.apa.htt.headers] (pool-3-thread-1) http-outgoing-1 >> GET /info/health HTTP/1.1
2020-06-25 09:24:38,275 DEBUG [org.apa.htt.headers] (pool-3-thread-1) http-outgoing-1 >> Accept: application/json
2020-06-25 09:24:38,275 DEBUG [org.apa.htt.headers] (pool-3-thread-1) http-outgoing-1 >> Host: localhost:8090
2020-06-25 09:24:38,276 DEBUG [org.apa.htt.headers] (pool-3-thread-1) http-outgoing-1 >> Connection: Keep-Alive
2020-06-25 09:24:38,276 DEBUG [org.apa.htt.headers] (pool-3-thread-1) http-outgoing-1 >> User-Agent: Apache-HttpClient/4.5.12 (Java/1.8.0_181)
2020-06-25 09:24:38,276 DEBUG [org.apa.htt.wire] (pool-3-thread-1) http-outgoing-1 >> "GET /info/health HTTP/1.1[\r][\n]"
2020-06-25 09:24:38,277 DEBUG [org.apa.htt.wire] (pool-3-thread-1) http-outgoing-1 >> "Accept: application/json[\r][\n]"
2020-06-25 09:24:38,277 DEBUG [org.apa.htt.wire] (pool-3-thread-1) http-outgoing-1 >> "Host: localhost:8090[\r][\n]"
2020-06-25 09:24:38,277 DEBUG [org.apa.htt.wire] (pool-3-thread-1) http-outgoing-1 >> "Connection: Keep-Alive[\r][\n]"
2020-06-25 09:24:38,277 DEBUG [org.apa.htt.wire] (pool-3-thread-1) http-outgoing-1 >> "User-Agent: Apache-HttpClient/4.5.12 (Java/1.8.0_181)[\r][\n]"
2020-06-25 09:24:38,278 DEBUG [org.apa.htt.wire] (pool-3-thread-1) http-outgoing-1 >> "[\r][\n]"
2020-06-25 09:24:38,291 DEBUG [io.net.han.cod.com.ZlibCodecFactory] (vert.x-eventloop-thread-7) -Dio.netty.noJdkZlibDecoder: false
2020-06-25 09:24:38,291 DEBUG [io.net.han.cod.com.ZlibCodecFactory] (vert.x-eventloop-thread-7) -Dio.netty.noJdkZlibEncoder: false
2020-06-25 09:24:38,335 DEBUG [org.apa.htt.wire] (pool-3-thread-1) http-outgoing-1 << "HTTP/1.1 404 Not Found[\r][\n]"
2020-06-25 09:24:38,335 DEBUG [org.apa.htt.wire] (pool-3-thread-1) http-outgoing-1 << "content-type: text/html; charset=utf-8[\r][\n]"
2020-06-25 09:24:38,335 DEBUG [org.apa.htt.wire] (pool-3-thread-1) http-outgoing-1 << "content-length: 53[\r][\n]"
2020-06-25 09:24:38,335 DEBUG [org.apa.htt.wire] (pool-3-thread-1) http-outgoing-1 << "[\r][\n]"
2020-06-25 09:24:38,335 DEBUG [org.apa.htt.wire] (pool-3-thread-1) http-outgoing-1 << "<html><body><h1>Resource not found</h1></body></html>"
2020-06-25 09:24:38,335 DEBUG [org.apa.htt.headers] (pool-3-thread-1) http-outgoing-1 << HTTP/1.1 404 Not Found
2020-06-25 09:24:38,335 DEBUG [org.apa.htt.headers] (pool-3-thread-1) http-outgoing-1 << content-type: text/html; charset=utf-8
2020-06-25 09:24:38,335 DEBUG [org.apa.htt.headers] (pool-3-thread-1) http-outgoing-1 << content-length: 53
2020-06-25 09:24:38,336 DEBUG [org.apa.htt.imp.exe.MainClientExec] (pool-3-thread-1) Connection can be kept alive indefinitely
2020-06-25 09:24:38,341 DEBUG [org.apa.htt.imp.con.PoolingHttpClientConnectionManager] (pool-3-thread-1) Connection [id: 1][route: {}->http://localhost:8090] can be kept alive indefinitely
2020-06-25 09:24:38,341 DEBUG [org.apa.htt.imp.con.DefaultManagedHttpClientConnection] (pool-3-thread-1) http-outgoing-1: set socket timeout to 0
2020-06-25 09:24:38,341 DEBUG [org.apa.htt.imp.con.PoolingHttpClientConnectionManager] (pool-3-thread-1) Connection released: [id: 1][route: {}->http://localhost:8090][total available: 1; route allocated: 1 of 50; total allocated: 1 of 50]
2020-06-25 09:24:38,342 DEBUG [org.apa.htt.imp.con.PoolingHttpClientConnectionManager] (pool-3-thread-1) Connection manager is shutting down
2020-06-25 09:24:38,342 DEBUG [org.apa.htt.imp.con.DefaultManagedHttpClientConnection] (pool-3-thread-1) http-outgoing-1: Close connection
2020-06-25 09:24:38,342 DEBUG [org.apa.htt.imp.con.PoolingHttpClientConnectionManager] (pool-3-thread-1) Connection manager shut down
2020-06-25 09:24:38,342 WARNING [io.qua.eur.reg.EurekaRegistrationService$RegistrationFlow] (pool-3-thread-1) Instance can't reach own application health check. Ensure this has been implemented

I tried on quarkus 1.5.2.Final and 1.4.2.Final For information, while compiling the project and testing, i got a failed on

InstanceHealthCheckServiceTest#shouldWrapExceptionWithHealthCheckException and this error in particulary

'Throwable that failed the check:

io.quarkus.eureka.exception.HealthCheckException: Instance can't reach own application health check. Ensure this has been implemented'

Thanks for your interest Jonathan

fmcejudo commented 4 years ago

Hi @jdarosTD , thanks for raising the issue. I haven't tried yet with Quarkus 1.5.2, I will give it a go today and see if I find out something.

jdarosTD commented 4 years ago

Thanks @fmcejudo 👍

fmcejudo commented 4 years ago

@jdarosTD, in a first try, I have run all tests again with Quarkus 1.4.2 and I didn't get any issue, after I have moved it on to Quarkus 1.5.2 and run again tests and I didn't get any issue either. What is the JVM you are running? Might we have a simple project to test these stuff? I was wondering if it is possible those endpoints are not ready yet when the plugin try to hit them.

jdarosTD commented 4 years ago

@fmcejudo I was in jdk1.8 mvn 3.0.5. To test I've tried on jdk11 with mvn last release 3.6.3. Same error in test while building your project.

Actually i was working on quarkus 1.5.2 or 1.4.2 whatever, the problem still here. I've commented all controllers to only get the StatusResource as described in my post. Unfortunately I cannot give access to my code. Do you have any sample that i can try ? On a github repo for instance ?

Nota : i also use kotlin

here is one extract of my gradle project :

dependencies {
    implementation 'io.quarkus:quarkus-resteasy-jackson'
    implementation 'io.quarkus:quarkus-jackson'
//    implementation 'io.quarkus:quarkus-spring-web'
    implementation 'io.quarkus:quarkus-oidc'
    implementation 'io.quarkus:quarkus-kotlin'
//    implementation 'io.quarkus:quarkus-resteasy-jsonb'
    implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
//    implementation 'io.quarkus:quarkus-resteasy'
    implementation 'io.quarkus:quarkus-spring-di'
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
    implementation 'io.quarkus:quarkus-spring-cloud-config-client'

    implementation 'io.quarkus:quarkus-rest-client'
    implementation 'com.github.fmcejudo:quarkus-eureka:0.0.9'

    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
    implementation("com.squareup.okhttp3:logging-interceptor:4.3.1")
//    implementation("com.squareup.okhttp3:okhttp:4.3.1")
    implementation 'net.iakovlev:timeshape:2018d.6'

    testImplementation 'io.quarkus:quarkus-junit5'
    testImplementation 'io.rest-assured:rest-assured'
}

group '.....'
version '1.0.0-SNAPSHOT'

quarkus {
    setOutputDirectory("$projectDir/build/classes/kotlin/main")
}

quarkusDev {
    setSourceDir("$projectDir/src/main/kotlin")
}

allOpen {
    annotation("javax.ws.rs.Path")
    annotation("javax.enterprise.context.ApplicationScoped")
    annotation("io.quarkus.test.junit.QuarkusTest")
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

compileKotlin {
    kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8
    kotlinOptions.javaParameters = true
}

compileTestKotlin {
    kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8
}
fmcejudo commented 4 years ago

I have this project as example of using the quarkus-eureka:

https://github.com/currofy/coffee-shop-parent

which is using now Quarkus 1.5.2 and the most recent released plugin I did (0.0.9), I have started the three modules and they joined to eureka server. Can you try to clone those projects and check if they work for you?

Also I would recommend you to clean up your repository for this project:

mvn dependency:purge-local-repository

https://maven.apache.org/plugins/maven-dependency-plugin/examples/purging-local-repository.html

Just to make it easy you might tweak toolchains.xml and build with script build.sh

Then, just run eureka-server with mvn spring-boot:run and quarkus modules with mvn quarkus:dev for both projects supplier and client, checking they are bound to eureka-server.

If you face any problem, let me know and we can check it

jdarosTD commented 4 years ago

@fmcejudo thanks for your answer. I've successful started your example. What i don't really understand in theses is the configuration for the status and health pathes Sans titre

as we can see here we've a reference of uri http://kubernetes.docker.internal:8001/ i was expecting using localhost I have not yet all the knowledge about this so, sorry if I misunderstand

I tried on a basic project, with maven, it works fine on my eureka server I will now try with a gradle project and see. I will keep you in touch about that. Maybe it's something about another dependency

Thanks for you help Regards

fmcejudo commented 4 years ago

I see, this is something also happen to me at some point. I was in a very complicated network architecture in the office and somehow I was given a wrong DNS to point to my address in my host over wired network, but the right one in wireless.

https://github.com/fmcejudo/quarkus-eureka/issues/2

What I don't understand is why if you have property quarkus.eureka.host-name to localhost it does not apply to you.

Here is where that address should be built:

io.quarkus.eureka.config.EurekaRuntimeConfiguration.NetworkConverter

Related to that logic you pointed at, it means to check periodically the state of the the services and trying to register in Eureka if this was not in the list for the given locations. Scheduled every 40 seconds as the Eureka Server might not be ready yet (let's say you start the eureka as last service).

Please, keep my post if possible and if there is any issue we can try to fix it.

Thank you for giving a try and helping to improve the plugin.

renatojava commented 3 years ago

Hello,

I have faced the same problem,

But in my case, I have several kafka endpoints and the app late to startup. For me the problem is the following code if app is not running, an exception is thrown and never try again, I think the catch should be silent and a health check after a period of time would get register to eureka:

private static class RegistrationFlow {

    private static final Logger LOGGER = Logger.getLogger(RegistrationFlow.class.getName());

    private Status status;

    private RegistrationFlow(final Status status) {
        this.status = status;
    }

    private static RegistrationFlow instanceHealthCheck(final Supplier<Status> statusSupplier) {
        try {
            return new RegistrationFlow(statusSupplier.get());
        } catch (Exception e) {
            // We need to log the errors in this thread, as this is inside of an Executor which is not bind to
            // the main thread
            LOGGER.warning(e.getMessage());
            throw e;
        }
    }

    private InstanceResult eurekaHealthCheck(final Supplier<InstanceResult> eurekaHealthSupplier) {
        if (UP.equals(this.status)) {
            return eurekaHealthSupplier.get();
        }
        return InstanceResult.error();
    }

}

If change as follow work fine:

image