Search in sources :

Example 6 with Health

use of io.pravega.shared.health.Health in project pravega by pravega.

the class HealthImpl method getHealth.

private void getHealth(String id, SecurityContext securityContext, AsyncResponse asyncResponse, String method) {
    long traceId = LoggerHelpers.traceEnter(log, method);
    processRequest(() -> {
        Health health = endpoint.getHealth(id);
        Response response = Response.status(Response.Status.OK).entity(adapter(health)).build();
        asyncResponse.resume(response);
    }, asyncResponse, method, traceId, id);
}
Also used : AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) Health(io.pravega.shared.health.Health)

Example 7 with Health

use of io.pravega.shared.health.Health in project pravega by pravega.

the class AbstractHealthContributor method getHealthSnapshot.

/**
 * Recursively build (in post-order fashion) the {@link Health} result for a given {@link HealthContributor}.
 *
 * @return The {@link Health} result of the {@link HealthContributor}.
 */
@Override
public final synchronized Health getHealthSnapshot() {
    Exceptions.checkNotClosed(isClosed(), this);
    Health.HealthBuilder builder = Health.builder().name(getName());
    Collection<Status> statuses = new ArrayList<>();
    Map<String, Health> children = new HashMap<>();
    for (val entry : contributors.entrySet()) {
        HealthContributor contributor = entry.getValue();
        synchronized (contributor) {
            if (!contributor.isClosed()) {
                Health health = contributor.getHealthSnapshot();
                children.put(entry.getKey(), health);
                statuses.add(health.getStatus());
            } else {
                contributors.remove(name);
            }
        }
    }
    Status status = Status.DOWN;
    // Perform own health check logic.
    try {
        status = doHealthCheck(builder);
    } catch (Exception ex) {
        log.warn("HealthCheck for {} has failed.", this.name, ex);
        builder.status(Status.FAILED);
    }
    // If there are no child statuses, return the Status from its own health check, else
    // return the least 'healthy' status between the child aggregate and its own.
    status = statuses.isEmpty() ? status : Status.min(StatusAggregator.aggregate(aggregator, statuses), status);
    this.status = status;
    return builder.name(name).status(status).children(children).build();
}
Also used : Status(io.pravega.shared.health.Status) lombok.val(lombok.val) Health(io.pravega.shared.health.Health) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HealthContributor(io.pravega.shared.health.HealthContributor)

Example 8 with Health

use of io.pravega.shared.health.Health in project pravega by pravega.

the class HealthContributorTests method testChildHealths.

/**
 * Tests that children {@link HealthContributor} can be properly registered to another contributor and the {@link Health}
 * of the individual children is properly reflected in the overall health of the top most contributor.
 */
@Test
public void testChildHealths() {
    @Cleanup HealthContributor contributor = new HealthyContributor();
    @Cleanup HealthContributor first = new HealthyContributor("first");
    @Cleanup HealthContributor second = new FailingContributor("second");
    contributor.register(first, second);
    Health health = contributor.getHealthSnapshot();
    Assert.assertEquals("Expected 'contributor' to report an unhealthy status.", Status.DOWN, health.getStatus());
    Assert.assertEquals("Expected to see two children registered to 'contributor'.", 2, health.getChildren().size());
}
Also used : FailingContributor(io.pravega.shared.health.TestHealthContributors.FailingContributor) Health(io.pravega.shared.health.Health) HealthyContributor(io.pravega.shared.health.TestHealthContributors.HealthyContributor) HealthContributor(io.pravega.shared.health.HealthContributor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 9 with Health

use of io.pravega.shared.health.Health in project pravega by pravega.

the class HealthTests method testDefaultReadyLogic.

/**
 * Tests that the default/empty {@link Health} reports the expected readiness result.
 */
@Test
public void testDefaultReadyLogic() {
    Health health = Health.builder().build();
    Assert.assertEquals("isReady() should be false by default if no Status is set.", false, health.isReady());
    health = Health.builder().status(Status.UP).build();
    Assert.assertEquals("isReady() should be true by default if an UP Status is supplied.", true, health.isReady());
}
Also used : Health(io.pravega.shared.health.Health) Test(org.junit.Test)

Example 10 with Health

use of io.pravega.shared.health.Health in project pravega by pravega.

the class CacheManagerTests method testCacheHealth.

/**
 * Tests the health contributor made with cache manager
 */
@Test
public void testCacheHealth() {
    final CachePolicy policy = new CachePolicy(Integer.MAX_VALUE, Duration.ofHours(10000), Duration.ofHours(1));
    @Cleanup val cache = new TestCache(policy.getMaxSize());
    // The Cache Manager won't do anything if there's no stored data.
    cache.setStoredBytes(1);
    @Cleanup TestCacheManager cm = new TestCacheManager(policy, cache, executorService());
    CacheManagerHealthContributor cacheManagerHealthContributor = new CacheManagerHealthContributor(cm);
    Health.HealthBuilder builder = Health.builder().name(cacheManagerHealthContributor.getName());
    Status status = cacheManagerHealthContributor.doHealthCheck(builder);
    Assert.assertEquals("HealthContributor should report an 'UP' Status.", Status.UP, status);
    cm.close();
    status = cacheManagerHealthContributor.doHealthCheck(builder);
    Assert.assertEquals("HealthContributor should report an 'DOWN' Status.", Status.DOWN, status);
}
Also used : lombok.val(lombok.val) Status(io.pravega.shared.health.Status) Health(io.pravega.shared.health.Health) CacheManagerHealthContributor(io.pravega.segmentstore.server.CacheManager.CacheManagerHealthContributor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Aggregations

Health (io.pravega.shared.health.Health)14 Test (org.junit.Test)11 Cleanup (lombok.Cleanup)6 Status (io.pravega.shared.health.Status)5 HealthContributor (io.pravega.shared.health.HealthContributor)2 HealthyContributor (io.pravega.shared.health.TestHealthContributors.HealthyContributor)2 lombok.val (lombok.val)2 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)1 TableStore (io.pravega.segmentstore.contracts.tables.TableStore)1 CacheManagerHealthContributor (io.pravega.segmentstore.server.CacheManager.CacheManagerHealthContributor)1 PassingTokenVerifier (io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier)1 SegmentContainerRegistryHealthContributor (io.pravega.segmentstore.server.host.health.SegmentContainerRegistryHealthContributor)1 ContributorNotFoundException (io.pravega.shared.health.ContributorNotFoundException)1 HealthServiceManager (io.pravega.shared.health.HealthServiceManager)1 FailingContributor (io.pravega.shared.health.TestHealthContributors.FailingContributor)1 ThrowingContributor (io.pravega.shared.health.TestHealthContributors.ThrowingContributor)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AsyncResponse (javax.ws.rs.container.AsyncResponse)1