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);
}
}
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);
}
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);
}
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");
}
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]");
}
}
Aggregations