use of org.springframework.boot.actuate.health.Health in project sofa-boot by alipay.
the class AfterHealthCheckCallbackProcessor method doApplicationAfterHealthCheckCallback.
/**
* process application afterHealthCheckCallback
* @return
*/
private boolean doApplicationAfterHealthCheckCallback() {
boolean result = true;
logger.info("Begin ApplicationAfterHealthCheckCallback startup health check");
List<SofaBootApplicationAfterHealthCheckCallback> afterHealthCheckCallbacks = HealthCheckManager.getApplicationAfterHealthCheckCallbacks();
for (SofaBootApplicationAfterHealthCheckCallback afterHealthCheckCallback : afterHealthCheckCallbacks) {
try {
Health health = afterHealthCheckCallback.onHealthy(HealthCheckManager.getApplicationContext());
Status status = health.getStatus();
if (!status.equals(Status.UP)) {
result = false;
logger.error("sofaboot application afterHealthCheck callback(" + afterHealthCheckCallback.getClass() + ") failed, the details is: " + JSON.toJSONString(health.getDetails()));
} else {
logger.info("sofaboot application afterHealthCheck callback(" + afterHealthCheckCallback.getClass() + ") ]success.");
}
StartUpHealthCheckStatus.putAfterHealthCheckCallbackDetail(getKey(afterHealthCheckCallback.getClass().getName()), health);
} catch (Throwable t) {
result = false;
logger.error("Invoking ApplicationAfterHealthCheckCallback " + afterHealthCheckCallback.getClass().getName() + " got an exception.", t);
}
}
if (result) {
logger.info("ApplicationAfterHealthCheckCallback startup health check result: success.");
} else {
logger.error("ApplicationAfterHealthCheckCallback startup health check result: failed.");
}
return result;
}
use of org.springframework.boot.actuate.health.Health in project resilience4j by resilience4j.
the class CircuitBreakerHealthIndicatorTest method health.
@Test
public void health() throws Exception {
// given
CircuitBreakerConfig config = mock(CircuitBreakerConfig.class);
CircuitBreaker.Metrics metrics = mock(CircuitBreaker.Metrics.class);
CircuitBreaker circuitBreaker = mock(CircuitBreaker.class);
CircuitBreakerHealthIndicator healthIndicator = new CircuitBreakerHealthIndicator(circuitBreaker);
// when
when(config.getFailureRateThreshold()).thenReturn(0.3f);
when(metrics.getFailureRate()).thenReturn(0.2f);
when(metrics.getMaxNumberOfBufferedCalls()).thenReturn(100);
when(metrics.getNumberOfBufferedCalls()).thenReturn(100);
when(metrics.getNumberOfFailedCalls()).thenReturn(20);
when(metrics.getNumberOfNotPermittedCalls()).thenReturn(0L);
when(circuitBreaker.getCircuitBreakerConfig()).thenReturn(config);
when(circuitBreaker.getMetrics()).thenReturn(metrics);
when(circuitBreaker.getState()).thenReturn(CLOSED, OPEN, HALF_OPEN, CLOSED);
// then
Health health = healthIndicator.health();
then(health.getStatus()).isEqualTo(Status.UP);
health = healthIndicator.health();
then(health.getStatus()).isEqualTo(Status.DOWN);
health = healthIndicator.health();
then(health.getStatus()).isEqualTo(Status.UNKNOWN);
health = healthIndicator.health();
then(health.getStatus()).isEqualTo(Status.UP);
then(health.getDetails()).contains(entry("failureRate", "0.2%"), entry("failureRateThreshold", "0.3%"), entry("bufferedCalls", 100), entry("failedCalls", 20), entry("notPermittedCalls", 0L), entry("maxBufferedCalls", 100));
}
use of org.springframework.boot.actuate.health.Health in project resilience4j by resilience4j.
the class RateLimiterHealthIndicatorTest method health.
@Test
public void health() throws Exception {
// given
RateLimiterConfig config = mock(RateLimiterConfig.class);
AtomicRateLimiter.AtomicRateLimiterMetrics metrics = mock(AtomicRateLimiter.AtomicRateLimiterMetrics.class);
AtomicRateLimiter rateLimiter = mock(AtomicRateLimiter.class);
// when
when(rateLimiter.getRateLimiterConfig()).thenReturn(config);
when(rateLimiter.getMetrics()).thenReturn(metrics);
when(rateLimiter.getDetailedMetrics()).thenReturn(metrics);
when(config.getTimeoutDuration()).thenReturn(Duration.ofNanos(30L));
when(metrics.getAvailablePermissions()).thenReturn(5, -1, -2);
when(metrics.getNumberOfWaitingThreads()).thenReturn(0, 1, 2);
when(metrics.getNanosToWait()).thenReturn(20L, 40L);
// then
RateLimiterHealthIndicator healthIndicator = new RateLimiterHealthIndicator(rateLimiter);
Health health = healthIndicator.health();
then(health.getStatus()).isEqualTo(Status.UP);
health = healthIndicator.health();
then(health.getStatus()).isEqualTo(Status.UNKNOWN);
health = healthIndicator.health();
then(health.getStatus()).isEqualTo(Status.DOWN);
then(health.getDetails()).contains(entry("availablePermissions", -2), entry("numberOfWaitingThreads", 2));
}
use of org.springframework.boot.actuate.health.Health in project dubbo by alibaba.
the class DubboHealthIndicatorTest method testHealth.
@Test
public void testHealth() {
Health health = dubboHealthIndicator.health();
Assert.assertEquals(Status.UNKNOWN, health.getStatus());
}
use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.
the class CloudFoundryHealthEndpointWebExtensionTests method healthComponentsAlwaysPresent.
@Test
void healthComponentsAlwaysPresent() {
this.contextRunner.run((context) -> {
CloudFoundryHealthEndpointWebExtension extension = context.getBean(CloudFoundryHealthEndpointWebExtension.class);
HealthComponent body = extension.health(ApiVersion.V3).getBody();
HealthComponent health = ((CompositeHealth) body).getComponents().entrySet().iterator().next().getValue();
assertThat(((Health) health).getDetails()).containsEntry("spring", "boot");
});
}
Aggregations