then(health.getStatus()).isEqualTo(Status.UP); then(health.getStatus()).isEqualTo(Status.UNKNOWN); then(health.getStatus()).isEqualTo(Status.DOWN); then(health.getDetails()) .contains( entry("availablePermissions", -2),
private Health rateLimiterHealth(Status status, int availablePermissions, int numberOfWaitingThreads) { return Health.status(status) .withDetail("availablePermissions", availablePermissions) .withDetail("numberOfWaitingThreads", numberOfWaitingThreads) .build(); } }
private Health mapBackendMonitorState(CircuitBreaker circuitBreaker) { switch (circuitBreaker.getState()) { case CLOSED: return addDetails(Health.up(), circuitBreaker).build(); case OPEN: return addDetails(Health.down(), circuitBreaker).build(); case HALF_OPEN: return addDetails(Health.unknown(),circuitBreaker).build(); default: return addDetails(Health.unknown(), circuitBreaker).build(); } }
@Override public Health health() { return Optional.of(circuitBreaker) .map(this::mapBackendMonitorState) .orElse(Health.up().build()); }
private boolean isUp(Env env) { Health health = healthAPI.health(env); return "UP".equals(health.getStatus().getCode()); }
@Override public Health health() { final GithubRateLimit rateLimit = githubGateway.getRateLimit().getCore(); if (rateLimit.getRemaining() == 0) { return addDetails(Health.down(), rateLimit).build(); } if (rateLimit.getRemaining() > calculateThreshold(rateLimit.getLimit())) { return addDetails(Health.up(), rateLimit).build(); } return addDetails(Health.status(new Status("THRESHOLD REACHED")), rateLimit).build(); }
/** * Create a new {@link Builder} instance with an {@link Status#DOWN} status and the * specified exception details. * @param ex the exception * @return a new {@link Builder} instance */ public static Builder down(Exception ex) { return down().withException(ex); }
/** * Return the health state. * @return OK or OUT_OF_SERVICE */ public Health health() { if(gracefulShutdownEndpoint.getStartShutdown() == null) { return Health.up().build(); } else { return Health.outOfService().build(); } } }
@Override public Health health() { try { final List<Health> healths = getIssues().keySet() .stream() .map(number -> getGithubScraper().fetchGithubIssue(getOwner(), getRepo(), number)) .map(this::check) .collect(Collectors.toList()); return Health.status(calculateOverallStatus(healths)).withDetail("healths", healths).build(); } catch (Exception e) { return Health.down().withDetail(DOWN_PROBLEM_KEY, "Exception thrown while fetching GitHub issue").build(); } }
/** * Maps the given {@code health} to a {@link WebEndpointResponse}, honouring the given * {@code showDetails} using the given {@code securityContext}. * @param health the health to map * @param securityContext the security context * @param showDetails when to show details in the response * @return the mapped response */ public WebEndpointResponse<Health> map(Health health, SecurityContext securityContext, ShowDetails showDetails) { if (showDetails == ShowDetails.NEVER || (showDetails == ShowDetails.WHEN_AUTHORIZED && (securityContext.getPrincipal() == null || !isUserInRole(securityContext)))) { health = Health.status(health.getStatus()).build(); } return createWebEndpointResponse(health); }
@ManagedAttribute public Map getHealth() { Health health = healthEndpoint.invoke(); Map healthMap = new LinkedHashMap(); healthMap.put("status", getStatus(health)); healthMap.put("detail", getDetails(health.getDetails())); return healthMap; }
private Health mapBackendMonitorState(CircuitBreaker circuitBreaker) { switch (circuitBreaker.getState()) { case CLOSED: return addDetails(Health.up(), circuitBreaker).build(); case OPEN: return addDetails(Health.down(), circuitBreaker).build(); case HALF_OPEN: return addDetails(Health.unknown(),circuitBreaker).build(); default: return addDetails(Health.unknown(), circuitBreaker).build(); } }
@Override public Health health() { return Optional.of(circuitBreaker) .map(this::mapBackendMonitorState) .orElse(Health.up().build()); }
private WebEndpointResponse<Health> createWebEndpointResponse(Health health) { Integer status = this.statusHttpMapper.mapStatus(health.getStatus()); return new WebEndpointResponse<>(health, status); }
private void indicateDown() { health = down().build(); }
/** * {@inheritDoc} */ @Override public Health health() { final boolean plugins = this.pluginsLoaded.get(); final boolean catalogs = this.catalogsLoaded.get(); final boolean thrift = this.thriftStarted.get(); final Health.Builder builder = plugins && catalogs && thrift ? Health.up() : Health.outOfService(); builder.withDetail(PLUGIN_KEY, plugins); builder.withDetail(CATALOG_KEY, catalogs); builder.withDetail(THRIFT_KEY, thrift); return builder.build(); }