use of org.apache.sling.hc.api.ResultLog in project sling by apache.
the class HealthCheckExecutorImpl method collectResultFromFuture.
/**
* Collect the result from a single future
* @param future The future
* @return The execution result or a result for a reached timeout
*/
HealthCheckExecutionResult collectResultFromFuture(final HealthCheckFuture future) {
HealthCheckExecutionResult result;
HealthCheckMetadata hcMetadata = future.getHealthCheckMetadata();
if (future.isDone()) {
logger.debug("Health Check is done: {}", hcMetadata);
try {
result = future.get();
} catch (final Exception e) {
logger.warn("Unexpected Exception during future.get(): " + e, e);
long futureElapsedTimeMs = new Date().getTime() - future.getCreatedTime().getTime();
result = new ExecutionResult(hcMetadata, Result.Status.HEALTH_CHECK_ERROR, "Unexpected Exception during future.get(): " + e, futureElapsedTimeMs, false);
}
} else {
logger.debug("Health Check timed out: {}", hcMetadata);
// Futures must not be cancelled as interrupting a health check might leave the system in invalid state
// (worst case could be a corrupted repository index if using write operations)
// normally we turn the check into WARN (normal timeout), but if the threshold time for CRITICAL is reached for a certain
// future we turn the result CRITICAL
long futureElapsedTimeMs = new Date().getTime() - future.getCreatedTime().getTime();
FormattingResultLog resultLog = new FormattingResultLog();
if (futureElapsedTimeMs < this.longRunningFutureThresholdForRedMs) {
resultLog.warn("Timeout: Check still running after " + msHumanReadable(futureElapsedTimeMs));
} else {
resultLog.critical("Timeout: Check still running after " + msHumanReadable(futureElapsedTimeMs) + " (exceeding the configured threshold for CRITICAL: " + msHumanReadable(this.longRunningFutureThresholdForRedMs) + ")");
}
// add logs from previous, cached result if exists (using a 1 year TTL)
HealthCheckExecutionResult lastCachedResult = healthCheckResultCache.getValidCacheResult(hcMetadata, 1000 * 60 * 60 * 24 * 365);
if (lastCachedResult != null) {
DateFormat df = new SimpleDateFormat("HH:mm:ss.SSS");
resultLog.info("*** Result log of last execution finished at {} after {} ***", df.format(lastCachedResult.getFinishedAt()), FormattingResultLog.msHumanReadable(lastCachedResult.getElapsedTimeInMs()));
for (ResultLog.Entry entry : lastCachedResult.getHealthCheckResult()) {
resultLog.add(entry);
}
}
result = new ExecutionResult(hcMetadata, new Result(resultLog), futureElapsedTimeMs, true);
}
return result;
}
use of org.apache.sling.hc.api.ResultLog in project sling by apache.
the class HealthCheckMBeanTest method assertJmxValue.
private void assertJmxValue(String mbeanName, String attributeName, String constraint, boolean expected) throws Exception {
final MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
final ObjectName objectName = new ObjectName(mbeanName);
if (jmxServer.queryNames(objectName, null).size() == 0) {
fail("MBean not found: " + objectName);
}
final Object value = jmxServer.getAttribute(objectName, attributeName);
final ResultLog resultLog = new ResultLog();
new SimpleConstraintChecker().check(value, constraint, resultLog);
assertEquals("Expecting result " + expected + "(" + resultLog + ")", expected, resultLog.getAggregateStatus().equals(Result.Status.OK));
}
Aggregations