Skip to content

Commit

Permalink
Fixed the VerifyError in the health example fixes #1517
Browse files Browse the repository at this point in the history
  • Loading branch information
aldettinger committed Aug 11, 2020
1 parent 349d9a9 commit 5f816a0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 39 deletions.
17 changes: 9 additions & 8 deletions examples/health/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ them automatic discovered by Camel and used as parts of its health-check system.
TIP: Check the https://camel.apache.org/camel-quarkus/latest/first-steps.html[Camel Quarkus User guide] for prerequisites
and other general information.

The example has two routes, a timer that calls a bean that flips a boolean that
causes the custom health check to be in either UP or DOWN state.
The example has two routes. The timer route performs a given task at regular interval. For the sake of this example we'll say
that this task unexpectedly freezes the service from time to time. The details can be consulted at http://localhost:8080/health.
The custom health check is expected to report UNKNOWN on first consultation, then UP during 10 seconds, and finally DOWN so as to
simulate that the service is frozen.

The 2nd route is on purpose made to fail on startup by configuring netty to an unknown host.
Camel supervising route controller will attempt to restart the route up till 10 times before exhausting.
The routes health check will therefore report this route as DOWN until its exhausted where the states are changed to UNKNOWN.

The routes health check will therefore report this route as DOWN until its exhausted
where the states are changed to UNKNOWN.

The details can be seen at runtime from the calling the following url from a web browser: http://localhost:8080/health
The details can be seen at runtime via the following url from a web browser: http://localhost:8080/health.

=== Start in the Development mode

Expand Down Expand Up @@ -44,10 +44,11 @@ https://camel.apache.org/camel-quarkus/latest/first-steps.html#_package_and_run_

[source,shell]
----
$ mvn clean package
$ java -jar target/*-runner.jar
...
[io.quarkus] (main) Quarkus 1.3.2 started in 1.163s. Listening on: http://[::]:8080
[io.quarkus] (main) camel-quarkus-examples-... started in 0.885s. Listening on: http://0.0.0.0:8080
----

=== Native mode
Expand All @@ -62,7 +63,7 @@ To prepare a native executable using GraalVM, run the following command:
$ mvn clean package -Pnative
$ ./target/*-runner
...
[io.quarkus] (main) Quarkus 1.3.2 started in 0.013s. Listening on: http://[::]:8080
[io.quarkus] (main) camel-quarkus-examples-... started in 0.026s. Listening on: http://0.0.0.0:8080
...
----

Expand Down
4 changes: 4 additions & 0 deletions examples/health/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-log</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-main</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-netty</artifactId>
Expand Down
14 changes: 2 additions & 12 deletions examples/health/src/main/java/org/acme/health/MyRouteBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,13 @@
*/
package org.acme.health;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.apache.camel.builder.RouteBuilder;

@ApplicationScoped
public class MyRouteBuilder extends RouteBuilder {

// we can inject the bean via this annotation
@Inject
MonkeyHealthCheck monkey;

@Override
public void configure() throws Exception {
from("timer:foo?period={{myPeriod}}").routeId("timer")
.bean(monkey, "chaos")
.log("${body}");
public void configure() {
from("timer:foo?period={{myPeriod}}").routeId("timer").log("Doing one more task");

// this route is invalid and fails during startup
// the supervising route controller will take over and attempt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,36 @@

import java.util.Map;

import javax.enterprise.context.ApplicationScoped;

import org.apache.camel.health.HealthCheckResultBuilder;
import org.apache.camel.impl.health.AbstractHealthCheck;

/**
* A chaos monkey health check that reports UP or DOWN in a chaotic way.
*
* This is a custom implementation of a Camel {@link org.apache.camel.health.HealthCheck}
* which is automatic discovered if bound in the {@link org.apache.camel.spi.Registry} and
* used as part of Camel's health-check system.
* A user defined health check that reports UNKNOWN on first call, then UP for
* 10 seconds and finally DOWN afterward. This is a custom implementation of a
* Camel {@link org.apache.camel.health.HealthCheck} and used as part of Camel's
* health-check system.
*/
@ApplicationScoped
public class MonkeyHealthCheck extends AbstractHealthCheck {
public class RunTooLongHealthCheck extends AbstractHealthCheck {

private boolean up = true;
private volatile long firstCallTimeMillis = 0;

public MonkeyHealthCheck() {
super("custom", "monkey");
public RunTooLongHealthCheck() {
super("custom", "toolong");
}

@Override
protected void doCall(HealthCheckResultBuilder builder, Map<String, Object> options) {
builder.detail("monkey", "The chaos monkey was here");
if (up) {
builder.detail("toolong", "Reports DOWN when run for too long");
if (firstCallTimeMillis == 0) {
builder.unknown();
firstCallTimeMillis = System.currentTimeMillis();
} else if ((System.currentTimeMillis() - firstCallTimeMillis) < 10 * 1000L) {
builder.up();
} else {
builder.down();
}
}

public String chaos() {
up = !up;
return up ? "All is okay" : "Chaos monkey was here";
}

@Override
public boolean isReadiness() {
// only liveness probe
Expand Down

0 comments on commit 5f816a0

Please sign in to comment.