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:
parent
f5f2149ff2
commit
6d7261c4d3
|
@ -280,6 +280,7 @@ public final class ConfigurationUtils {
|
|||
|
||||
public static Processor readProcessor(Map<String, Processor.Factory> processorFactories,
|
||||
String type, Map<String, Object> config) throws Exception {
|
||||
String tag = ConfigurationUtils.readOptionalStringProperty(null, null, config, TAG_KEY);
|
||||
Processor.Factory factory = processorFactories.get(type);
|
||||
if (factory != null) {
|
||||
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);
|
||||
|
||||
List<Processor> onFailureProcessors = readProcessorConfigs(onFailureProcessorConfigs, processorFactories);
|
||||
String tag = ConfigurationUtils.readOptionalStringProperty(null, null, config, TAG_KEY);
|
||||
|
||||
if (onFailureProcessorConfigs != null && onFailureProcessors.isEmpty()) {
|
||||
throw newConfigurationException(type, tag, Pipeline.ON_FAILURE_KEY,
|
||||
|
@ -309,6 +309,6 @@ public final class ConfigurationUtils {
|
|||
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 + "]");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ import org.elasticsearch.test.ESTestCase;
|
|||
import org.junit.Before;
|
||||
|
||||
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.mockito.Mockito.mock;
|
||||
|
||||
|
@ -105,12 +107,17 @@ public class ConfigurationUtilsTests extends ESTestCase {
|
|||
assertThat(result.get(0), 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 {
|
||||
ConfigurationUtils.readProcessorConfigs(config, registry);
|
||||
fail("exception expected");
|
||||
} catch (ElasticsearchParseException e) {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue