Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #22 from ralf-ueberfuhr-ars/feature/observability
Browse files Browse the repository at this point in the history
Observability
  • Loading branch information
ralf-ueberfuhr-ars authored Jun 21, 2024
2 parents 52bcd4e + d2d3daa commit 63f0411
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
4 changes: 4 additions & 0 deletions customer-api-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package de.schulung.sample.quarkus.infrastructure;

import io.quarkus.runtime.Startup;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.infrastructure.Infrastructure;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Liveness;
import org.eclipse.microprofile.health.Readiness;

@ApplicationScoped
public class LongRunningStartup {

private volatile boolean initialized = false;
private volatile boolean initializingFailed = false;

// check during startup: http://localhost:9090/q/health/ready

private Uni<Void> doLongRunningInitialization() {
try {
Thread.sleep(5000);
initialized = true;
return Uni.createFrom().voidItem();
} catch (InterruptedException e) {
initializingFailed = true;
return Uni.createFrom().failure(e);
}
}

@Startup
public void init() {
Uni
.createFrom()
.voidItem()
.emitOn(Infrastructure.getDefaultWorkerPool())
.subscribe()
.with(v -> this.doLongRunningInitialization());
}

@Produces
@ApplicationScoped
@Liveness
public HealthCheck myStartupLiveness() {
return () -> {
final var result = HealthCheckResponse
.named("My long-running startup");
return (initializingFailed ? result.down() : result.up()).build();
};
}

@Produces
@ApplicationScoped
@Readiness
public HealthCheck myStartupReadyness() {
return () -> {
final var result = HealthCheckResponse
.named("My long-running startup");
return (initialized ? result.up() : result.down()).build();
};
}

}
11 changes: 11 additions & 0 deletions customer-api-provider/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,15 @@ persistence.sink.implementation=panache
%dev.quarkus.hibernate-orm.database.generation=update


# Observability - serve on another port
# https://quarkus.io/guides/management-interface-reference
# https://quarkus.io/guides/smallrye-health
# https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
# https://developers.redhat.com/blog/2020/11/10/you-probably-need-liveness-and-readiness-probes
quarkus.management.enabled=true
quarkus.management.port=9090
%dev.quarkus.management.host=localhost
quarkus.datasource.health.enabled=true

# Liveness: if fails -> container must be restarted
# Readyness: if fails -> container is just initializing

0 comments on commit 63f0411

Please sign in to comment.