@Test public void testStatusOk() throws Exception { when(registry.runHealthChecks()).thenReturn(new TreeMap<>()); Response r = status.get(); assertThat(r.getStatus()).isEqualTo(200); }
@Timed @ExceptionMetered @GET public Response get() { SortedMap<String, HealthCheck.Result> results = memoizedCheck.get(); List<String> failing = results.entrySet().stream() .filter(r -> !r.getValue().isHealthy()) .map(Map.Entry::getKey) .collect(toList()); if (!failing.isEmpty()) { logger.warn("Health checks failed: {}", results); String message = "failing health checks: " + Arrays.toString(failing.toArray()); StatusResponse sr = new StatusResponse("critical", message, results); return Response.serverError().entity(sr).build(); } StatusResponse sr = new StatusResponse("ok", "ok", results); return Response.ok(sr).build(); }
StatusResource { @Timed @ExceptionMetered @GET public Response get() { SortedMap<String, HealthCheck.Result> results = memoizedCheck.get(); List<String> failing = results.entrySet().stream() .filter(r -> !r.getValue().isHealthy()) .map(Map.Entry::getKey) .collect(toList()); if (!failing.isEmpty()) { logger.warn("Health checks failed: {}", results); String message = "failing health checks: " + Arrays.toString(failing.toArray()); StatusResponse sr = new StatusResponse("critical", message, results); return Response.serverError().entity(sr).build(); } StatusResponse sr = new StatusResponse("ok", "ok", results); return Response.ok(sr).build(); } }
StatusResource { @Timed @ExceptionMetered @GET public Response get() { SortedMap<String, HealthCheck.Result> results = memoizedCheck.get(); List<String> failing = results.entrySet().stream() .filter(r -> !r.getValue().isHealthy()) .map(Map.Entry::getKey) .collect(toList()); if (!failing.isEmpty()) { logger.warn("Health checks failed: {}", results); String message = "failing health checks: " + Arrays.toString(failing.toArray()); StatusResponse sr = new StatusResponse("critical", message, results); return Response.serverError().entity(sr).build(); } StatusResponse sr = new StatusResponse("ok", "ok", results); return Response.ok(sr).build(); } @Inject  StatusResource(KeywhizConfig keywhizConfig, Environment environment); }
StatusResource { @Timed @ExceptionMetered @GET public Response get() { SortedMap<String, HealthCheck.Result> results = memoizedCheck.get(); List<String> failing = results.entrySet().stream() .filter(r -> !r.getValue().isHealthy()) .map(Map.Entry::getKey) .collect(toList()); if (!failing.isEmpty()) { logger.warn("Health checks failed: {}", results); String message = "failing health checks: " + Arrays.toString(failing.toArray()); StatusResponse sr = new StatusResponse("critical", message, results); return Response.serverError().entity(sr).build(); } StatusResponse sr = new StatusResponse("ok", "ok", results); return Response.ok(sr).build(); } @Inject  StatusResource(KeywhizConfig keywhizConfig, Environment environment); @Timed @ExceptionMetered @GET Response get(); }
StatusResource { @Timed @ExceptionMetered @GET public Response get() { SortedMap<String, HealthCheck.Result> results = memoizedCheck.get(); List<String> failing = results.entrySet().stream() .filter(r -> !r.getValue().isHealthy()) .map(Map.Entry::getKey) .collect(toList()); if (!failing.isEmpty()) { logger.warn("Health checks failed: {}", results); String message = "failing health checks: " + Arrays.toString(failing.toArray()); StatusResponse sr = new StatusResponse("critical", message, results); return Response.serverError().entity(sr).build(); } StatusResponse sr = new StatusResponse("ok", "ok", results); return Response.ok(sr).build(); } @Inject  StatusResource(KeywhizConfig keywhizConfig, Environment environment); @Timed @ExceptionMetered @GET Response get();  }