-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add @healthGroup and @HealthGroups support
- Loading branch information
1 parent
f75581c
commit 65c2138
Showing
7 changed files
with
214 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
.../runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeHealthGroupHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.quarkus.smallrye.health.runtime; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
|
||
import javax.enterprise.inject.spi.CDI; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.smallrye.health.SmallRyeHealth; | ||
import io.smallrye.health.SmallRyeHealthReporter; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.buffer.Buffer; | ||
import io.vertx.core.http.HttpHeaders; | ||
import io.vertx.core.http.HttpServerResponse; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
public class SmallRyeHealthGroupHandler implements Handler<RoutingContext> { | ||
|
||
@Override | ||
public void handle(RoutingContext event) { | ||
boolean activated = RequestScopeHelper.activeRequestScope(); | ||
|
||
try { | ||
SmallRyeHealthReporter reporter = CDI.current().select(SmallRyeHealthReporter.class).get(); | ||
SmallRyeHealth health = reporter.getHealthGroups(); | ||
HttpServerResponse resp = event.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); | ||
} | ||
} finally { | ||
if (activated) { | ||
Arc.container().requestContext().terminate(); | ||
} | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...rc/main/java/io/quarkus/smallrye/health/runtime/SmallRyeIndividualHealthGroupHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.quarkus.smallrye.health.runtime; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
|
||
import javax.enterprise.inject.spi.CDI; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.smallrye.health.SmallRyeHealth; | ||
import io.smallrye.health.SmallRyeHealthReporter; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.buffer.Buffer; | ||
import io.vertx.core.http.HttpHeaders; | ||
import io.vertx.core.http.HttpServerResponse; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
public class SmallRyeIndividualHealthGroupHandler implements Handler<RoutingContext> { | ||
|
||
@Override | ||
public void handle(RoutingContext event) { | ||
boolean activated = RequestScopeHelper.activeRequestScope(); | ||
|
||
try { | ||
SmallRyeHealthReporter reporter = CDI.current().select(SmallRyeHealthReporter.class).get(); | ||
String group = event.normalisedPath().substring(event.normalisedPath().lastIndexOf("/") + 1); | ||
SmallRyeHealth health = reporter.getHealthGroup(group); | ||
HttpServerResponse resp = event.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); | ||
} | ||
} finally { | ||
if (activated) { | ||
Arc.container().requestContext().terminate(); | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...gration-tests/main/src/main/java/io/quarkus/it/health/SimpleCombinedHealthGroupCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.quarkus.it.health; | ||
|
||
import org.eclipse.microprofile.health.HealthCheck; | ||
import org.eclipse.microprofile.health.HealthCheckResponse; | ||
|
||
import io.smallrye.health.HealthGroup; | ||
|
||
@HealthGroup("group1") | ||
@HealthGroup("group2") | ||
public class SimpleCombinedHealthGroupCheck implements HealthCheck { | ||
@Override | ||
public HealthCheckResponse call() { | ||
return HealthCheckResponse.up("combined"); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
integration-tests/main/src/main/java/io/quarkus/it/health/SimpleHealthGroupCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.quarkus.it.health; | ||
|
||
import org.eclipse.microprofile.health.HealthCheck; | ||
import org.eclipse.microprofile.health.HealthCheckResponse; | ||
|
||
import io.smallrye.health.HealthGroup; | ||
|
||
@HealthGroup("group1") | ||
public class SimpleHealthGroupCheck implements HealthCheck { | ||
@Override | ||
public HealthCheckResponse call() { | ||
return HealthCheckResponse.up("single"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters