Adds ingest processor headers to exception for unknown processor. (#22315)

Optimistically check for `tag` of an unknown processor for better tracking of which
processor declaration is to blame in an invalid configuration.

Closes #21429.
This commit is contained in:
Tal Levy 2016-12-22 08:24:00 -08:00 committed by GitHub
parent f5f2149ff2
commit 6d7261c4d3
2 changed files with 10 additions and 3 deletions

View File

@ -280,6 +280,7 @@ public final class ConfigurationUtils {
public static Processor readProcessor(Map<String, Processor.Factory> processorFactories, public static Processor readProcessor(Map<String, Processor.Factory> processorFactories,
String type, Map<String, Object> config) throws Exception { String type, Map<String, Object> config) throws Exception {
String tag = ConfigurationUtils.readOptionalStringProperty(null, null, config, TAG_KEY);
Processor.Factory factory = processorFactories.get(type); Processor.Factory factory = processorFactories.get(type);
if (factory != null) { if (factory != null) {
boolean ignoreFailure = ConfigurationUtils.readBooleanProperty(null, null, config, "ignore_failure", false); boolean ignoreFailure = ConfigurationUtils.readBooleanProperty(null, null, config, "ignore_failure", false);
@ -287,7 +288,6 @@ public final class ConfigurationUtils {
ConfigurationUtils.readOptionalList(null, null, config, Pipeline.ON_FAILURE_KEY); ConfigurationUtils.readOptionalList(null, null, config, Pipeline.ON_FAILURE_KEY);
List<Processor> onFailureProcessors = readProcessorConfigs(onFailureProcessorConfigs, processorFactories); List<Processor> onFailureProcessors = readProcessorConfigs(onFailureProcessorConfigs, processorFactories);
String tag = ConfigurationUtils.readOptionalStringProperty(null, null, config, TAG_KEY);
if (onFailureProcessorConfigs != null && onFailureProcessors.isEmpty()) { if (onFailureProcessorConfigs != null && onFailureProcessors.isEmpty()) {
throw newConfigurationException(type, tag, Pipeline.ON_FAILURE_KEY, throw newConfigurationException(type, tag, Pipeline.ON_FAILURE_KEY,
@ -309,6 +309,6 @@ public final class ConfigurationUtils {
throw newConfigurationException(type, tag, null, e); throw newConfigurationException(type, tag, null, e);
} }
} }
throw new ElasticsearchParseException("No processor type exists with name [" + type + "]"); throw newConfigurationException(type, tag, null, "No processor type exists with name [" + type + "]");
} }
} }

View File

@ -31,6 +31,8 @@ import org.elasticsearch.test.ESTestCase;
import org.junit.Before; import org.junit.Before;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance; import static org.hamcrest.Matchers.sameInstance;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -105,12 +107,17 @@ public class ConfigurationUtilsTests extends ESTestCase {
assertThat(result.get(0), sameInstance(processor)); assertThat(result.get(0), sameInstance(processor));
assertThat(result.get(1), sameInstance(processor)); assertThat(result.get(1), sameInstance(processor));
config.add(Collections.singletonMap("unknown_processor", emptyConfig)); Map<String, Object> unknownTaggedConfig = new HashMap<>();
unknownTaggedConfig.put("tag", "my_unknown");
config.add(Collections.singletonMap("unknown_processor", unknownTaggedConfig));
try { try {
ConfigurationUtils.readProcessorConfigs(config, registry); ConfigurationUtils.readProcessorConfigs(config, registry);
fail("exception expected"); fail("exception expected");
} catch (ElasticsearchParseException e) { } catch (ElasticsearchParseException e) {
assertThat(e.getMessage(), equalTo("No processor type exists with name [unknown_processor]")); assertThat(e.getMessage(), equalTo("No processor type exists with name [unknown_processor]"));
assertThat(e.getHeader("processor_tag"), equalTo(Collections.singletonList("my_unknown")));
assertThat(e.getHeader("processor_type"), equalTo(Collections.singletonList("unknown_processor")));
assertThat(e.getHeader("property_name"), is(nullValue()));
} }
} }