[Monitoring] LocalExporter should catch synchronous exceptions (#36606)

In the unlikely scenario that `LocalExporter::resolveBulk` throws
an exception, then we should mark the `listener` as having failed.
This commit is contained in:
Chris Earle 2018-12-13 16:13:26 -05:00 committed by GitHub
parent 64da98070c
commit 42d76a7e86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -71,7 +71,6 @@ import java.util.stream.Collectors;
import static org.elasticsearch.common.Strings.collectionToCommaDelimitedString;
import static org.elasticsearch.xpack.core.ClientHelper.MONITORING_ORIGIN;
import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin;
import static org.elasticsearch.xpack.core.ClientHelper.stashWithOrigin;
import static org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils.LAST_UPDATED_VERSION;
import static org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils.PIPELINE_IDS;
import static org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils.TEMPLATE_VERSION;
@ -145,7 +144,11 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
if (state.get() != State.RUNNING) {
listener.onResponse(null);
} else {
listener.onResponse(resolveBulk(clusterService.state(), false));
try {
listener.onResponse(resolveBulk(clusterService.state(), false));
} catch (Exception e) {
listener.onFailure(e);
}
}
}
@ -314,7 +317,7 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
if (asyncActions.size() > 0) {
if (installingSomething.compareAndSet(false, true)) {
pendingResponses.set(asyncActions.size());
try (ThreadContext.StoredContext ignore = stashWithOrigin(client.threadPool().getThreadContext(), MONITORING_ORIGIN)) {
try (ThreadContext.StoredContext ignore = client.threadPool().getThreadContext().stashWithOrigin(MONITORING_ORIGIN)) {
asyncActions.forEach(Runnable::run);
}
} else {