EnrichProcessorFactory should not throw NPE if missing metadata (#55977) (#56793)

In some cases the Enrich processor factory may be called before it is
ready to create processors. While these calls are usually made in error,
the response from the Enrich processor is an NPE which is almost always
an unhelpful error when debugging an issue.
This commit is contained in:
James Baiera 2020-05-15 12:02:13 -04:00 committed by GitHub
parent c8278e333a
commit 4809db3ff9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -38,6 +38,9 @@ final class EnrichProcessorFactory implements Processor.Factory, Consumer<Cluste
public Processor create(Map<String, Processor.Factory> processorFactories, String tag, Map<String, Object> config) throws Exception {
String policyName = ConfigurationUtils.readStringProperty(TYPE, tag, config, "policy_name");
String policyAlias = EnrichPolicy.getBaseName(policyName);
if (metadata == null) {
throw new IllegalStateException("enrich processor factory has not yet been initialized with cluster state");
}
IndexAbstraction indexAbstraction = metadata.getIndicesLookup().get(policyAlias);
if (indexAbstraction == null) {
throw new IllegalArgumentException("no enrich index exists for policy with name [" + policyName + "]");