Search in sources :

Example 26 with HealthCheckRegistry

use of com.codahale.metrics.health.HealthCheckRegistry in project jstorm by alibaba.

the class JStormHealthReporter method run.

@Override
public void run() {
    StormClusterState clusterState = workerData.getZkCluster();
    String topologyId = workerData.getTopologyId();
    Map<Integer, HealthCheckRegistry> taskHealthCheckMap = JStormHealthCheck.getTaskhealthcheckmap();
    int cnt = 0;
    for (Map.Entry<Integer, HealthCheckRegistry> entry : taskHealthCheckMap.entrySet()) {
        Integer taskId = entry.getKey();
        Map<String, Result> results = entry.getValue().runHealthChecks();
        for (Map.Entry<String, Result> result : results.entrySet()) {
            if (!result.getValue().isHealthy()) {
                try {
                    clusterState.report_task_error(topologyId, taskId, result.getValue().getMessage(), ErrorConstants.WARN, ErrorConstants.CODE_QUEUE_FULL, ErrorConstants.DURATION_SECS_QUEUE_FULL);
                    cnt++;
                } catch (Exception e) {
                    LOG.error("Failed to update health data in ZK for topo-{} task-{}.", topologyId, taskId, e);
                }
            }
        }
    }
    if (cnt > 0) {
        LOG.info("Successfully updated {} health data to ZK for topology:{}", cnt, topologyId);
    }
}
Also used : StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) Map(java.util.Map) Result(com.codahale.metrics.health.HealthCheck.Result)

Example 27 with HealthCheckRegistry

use of com.codahale.metrics.health.HealthCheckRegistry in project jstorm by alibaba.

the class JStormHealthCheck method registerTaskHealthCheck.

public static void registerTaskHealthCheck(int taskId, String name, HealthCheck healthCheck) {
    HealthCheckRegistry healthCheckRegister = taskHealthCheckMap.get(taskId);
    if (healthCheckRegister == null) {
        healthCheckRegister = new HealthCheckRegistry();
        taskHealthCheckMap.put(taskId, healthCheckRegister);
    }
    healthCheckRegister.register(name, healthCheck);
}
Also used : HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry)

Example 28 with HealthCheckRegistry

use of com.codahale.metrics.health.HealthCheckRegistry in project dropwizard by dropwizard.

the class BootstrapTest method canUseCustomHealthCheckRegistry.

@Test
void canUseCustomHealthCheckRegistry() {
    final HealthCheckRegistry healthCheckRegistry = new HealthCheckRegistry();
    bootstrap.setHealthCheckRegistry(healthCheckRegistry);
    assertThat(bootstrap.getHealthCheckRegistry()).isSameAs(healthCheckRegistry);
}
Also used : HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) Test(org.junit.jupiter.api.Test)

Example 29 with HealthCheckRegistry

use of com.codahale.metrics.health.HealthCheckRegistry in project dropwizard by dropwizard.

the class HealthCheckConfigValidatorTest method startValidationsShouldSucceedButLogWhenNotAllHealthChecksAreConfigured.

@Test
void startValidationsShouldSucceedButLogWhenNotAllHealthChecksAreConfigured() throws Exception {
    // given
    ArgumentCaptor<LoggingEvent> captor = ArgumentCaptor.forClass(LoggingEvent.class);
    HealthCheckConfiguration check1 = new HealthCheckConfiguration();
    check1.setName("check-1");
    List<HealthCheckConfiguration> configs = singletonList(check1);
    HealthCheckRegistry registry = new HealthCheckRegistry();
    registry.register("check-1", mock(HealthCheck.class));
    registry.register("check-2", mock(HealthCheck.class));
    registry.register("check-3", mock(HealthCheck.class));
    // when
    HealthCheckConfigValidator validator = new HealthCheckConfigValidator(configs, registry);
    validator.start();
    // then
    verify(mockLogAppender).doAppend(captor.capture());
    LoggingEvent logEvent = captor.getValue();
    assertThat(logEvent.getLevel()).isEqualTo(Level.INFO);
    assertThat(logEvent.getFormattedMessage()).doesNotContain("  * check-1");
    assertThat(logEvent.getFormattedMessage()).contains("  * check-2");
    assertThat(logEvent.getFormattedMessage()).contains("  * check-3");
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) HealthCheck(com.codahale.metrics.health.HealthCheck) Test(org.junit.jupiter.api.Test)

Example 30 with HealthCheckRegistry

use of com.codahale.metrics.health.HealthCheckRegistry in project dropwizard by dropwizard.

the class HealthCheckConfigValidatorTest method startValidationsShouldFailIfAHealthCheckConfiguredButNotRegistered.

@Test
void startValidationsShouldFailIfAHealthCheckConfiguredButNotRegistered() throws Exception {
    // given
    ArgumentCaptor<LoggingEvent> captor = ArgumentCaptor.forClass(LoggingEvent.class);
    List<HealthCheckConfiguration> configs = new ArrayList<>();
    HealthCheckConfiguration check1 = new HealthCheckConfiguration();
    check1.setName("check-1");
    configs.add(check1);
    HealthCheckConfiguration check2 = new HealthCheckConfiguration();
    check2.setName("check-2");
    configs.add(check2);
    HealthCheckConfiguration check3 = new HealthCheckConfiguration();
    check3.setName("check-3");
    configs.add(check3);
    HealthCheckRegistry registry = new HealthCheckRegistry();
    registry.register("check-1", mock(HealthCheck.class));
    // when
    try {
        HealthCheckConfigValidator validator = new HealthCheckConfigValidator(unmodifiableList(configs), registry);
        validator.start();
        fail("configured health checks that aren't registered should fail");
    } catch (IllegalStateException e) {
        // then
        verify(mockLogAppender).doAppend(captor.capture());
        LoggingEvent logEvent = captor.getValue();
        assertThat(logEvent.getLevel()).isEqualTo(Level.ERROR);
        assertThat(logEvent.getFormattedMessage()).doesNotContain("  * check-1");
        assertThat(logEvent.getFormattedMessage()).contains("  * check-3");
        assertThat(logEvent.getFormattedMessage()).contains("  * check-3");
        assertThat(e.getMessage()).contains("[check-3, check-2]");
    }
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) ArrayList(java.util.ArrayList) HealthCheck(com.codahale.metrics.health.HealthCheck) Test(org.junit.jupiter.api.Test)

Aggregations

HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)31 Test (org.junit.Test)11 MetricRegistry (com.codahale.metrics.MetricRegistry)6 HealthCheck (com.codahale.metrics.health.HealthCheck)6 Test (org.junit.jupiter.api.Test)6 HikariDataSource (com.zaxxer.hikari.HikariDataSource)3 ServletContext (jakarta.servlet.ServletContext)3 ServletContext (javax.servlet.ServletContext)3 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)2 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)2 Result (com.codahale.metrics.health.HealthCheck.Result)2 HealthCheckFilter (com.codahale.metrics.health.HealthCheckFilter)2 HealthCheckModule (com.codahale.metrics.json.HealthCheckModule)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ServletConfig (jakarta.servlet.ServletConfig)2 Connection (java.sql.Connection)2 ExecutorService (java.util.concurrent.ExecutorService)2 Connector (org.eclipse.jetty.server.Connector)2 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)2 Server (org.eclipse.jetty.server.Server)2