Skip to content

Commit

Permalink
vertx3 and vertx4 /healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeauchesne committed Oct 10, 2024
1 parent 604d0db commit 7b8683d
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
5 changes: 5 additions & 0 deletions utils/build/docker/java/vertx3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<artifactId>vertx-web</artifactId>
<version>3.9.13</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>3.9.13</version>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
import java.util.logging.LogManager;
import java.util.stream.Stream;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Optional;

import okhttp3.*;

public class Main {
Expand Down Expand Up @@ -63,6 +68,9 @@ public static void main(String[] args) {
span.finish();
}
});

router.get("/healthcheck").handler(Main::healthCheck);

router.get("/headers")
.produces("text/plain")
.handler(ctx -> ctx.response()
Expand Down Expand Up @@ -258,4 +266,32 @@ private static void consumeParsedBody(final RoutingContext ctx) {
ctx.getBodyAsString();
}
}


private static void healthCheck(RoutingContext context) {
String version = getVersion().orElse("0.0.0");

Map<String, Object> response = new HashMap<>();
Map<String, String> library = new HashMap<>();
library.put("language", "java");
library.put("version", version);
response.put("status", "ok");
response.put("library", library);

JsonObject jsonResponse = new JsonObject(response);

context.response()
.putHeader("content-type", "application/json")
.end(jsonResponse.encode());
}

private static Optional<String> getVersion() {
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(Main.class.getClassLoader().getResourceAsStream("dd-java-agent.version"), StandardCharsets.ISO_8859_1))) {
String line = reader.readLine();
return Optional.ofNullable(line);
} catch (Exception e) {
return Optional.empty();
}
}
}
5 changes: 5 additions & 0 deletions utils/build/docker/java/vertx4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<artifactId>vertx-web</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
import java.util.logging.LogManager;
import java.util.stream.Stream;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Optional;

import okhttp3.*;

public class Main {
Expand Down Expand Up @@ -62,6 +67,9 @@ public static void main(String[] args) {
span.finish();
}
});

router.get("/healthcheck").handler(Main::healthCheck);

router.get("/headers")
.produces("text/plain")
.handler(ctx -> ctx.response()
Expand Down Expand Up @@ -257,4 +265,31 @@ private static void consumeParsedBody(final RoutingContext ctx) {
ctx.getBodyAsString();
}
}

private static void healthCheck(RoutingContext context) {
String version = getVersion().orElse("0.0.0");

Map<String, Object> response = new HashMap<>();
Map<String, String> library = new HashMap<>();
library.put("language", "java");
library.put("version", version);
response.put("status", "ok");
response.put("library", library);

JsonObject jsonResponse = new JsonObject(response);

context.response()
.putHeader("content-type", "application/json")
.end(jsonResponse.encode());
}

private static Optional<String> getVersion() {
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(Main.class.getClassLoader().getResourceAsStream("dd-java-agent.version"), StandardCharsets.ISO_8859_1))) {
String line = reader.readLine();
return Optional.ofNullable(line);
} catch (Exception e) {
return Optional.empty();
}
}
}

0 comments on commit 7b8683d

Please sign in to comment.