Skip to content

Conversation

@hub-cap
Copy link
Contributor

@hub-cap hub-cap commented Aug 2, 2019

This commit adds a helper method to the ingest service allowing it to
inspect a pipeline by id and verify the existence of a processor in the
pipeline. This work exposed a potential bug in that some processors
contain inner processors that are passed in at instantiation. These
processors needed a common way to expose their inner processors, so the
WrappedProcessor was created in order to expose the inner processor.

This commit adds a helper method to the ingest service allowing it to
inspect a pipeline by id and verify the existence of a processor in the
pipeline. This work exposed a potential bug in that some processors
contain inner processors that are passed in at instantiation. These
processors needed a common way to expose their inner processors, so the
WrappedProcessor was created in order to expose the inner processor.
@hub-cap hub-cap added >enhancement :Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP v8.0.0 v7.4.0 labels Aug 2, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features

@hub-cap
Copy link
Contributor Author

hub-cap commented Aug 2, 2019

@elasticmachine run elasticsearch-ci/2

Copy link
Member

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the comment about hasProcessor(...) method, this PR LGTM.

}

for (Processor processor: pipeline.flattenAllProcessors()) {
if (processor instanceof WrappedProcessor) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method does not work as expected in the following cases:

  1. hasProcessor("_id", ForEachProcessor.class/ConditionalProcessor.class) invocations, because both classes implemented WrappedProcessor, we never end up checking whether processor is assignable from clazz and straight check the inner processor.
  2. In the case that a wrapped processor is wrapped by another wrapped processor (for example: foreach processor wraps a conditional processor) then we never check the 2nd wrapped processor or any processor below that.

I think something like the following fixes the above cases:

if (clazz.isAssignableFrom(processor.getClass())) {
   return true;
}

while (processor instanceof WrappedProcessor) {
   WrappedProcessor wrappedProcessor = (WrappedProcessor) processor;
   if (clazz.isAssignableFrom(wrappedProcessor.getInnerProcessor().getClass())) {
      return true;
   }
   processor = wrappedProcessor.getInnerProcessor();
   if (wrappedProcessor == processor) {
      break;
   }
}

(replaces the body of the for loop)

Copy link
Member

@jbaiera jbaiera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, pending the name nitpicks

* A wrapped processor is one that encapsulates an inner processor, or a processor that the wrapped processor enacts upon. All processors
* that contain an "inner" processor should implement this interface, such that the actual processor can be obtained.
*/
public interface WrappedProcessor extends Processor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think originally we had wanted to call this WrappingProcessor


import java.util.function.Consumer;

class WrappedProcessorImpl extends FakeProcessor implements WrappedProcessor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here re: WrappingProcessor vs WrappedProcessor

@hub-cap
Copy link
Contributor Author

hub-cap commented Aug 7, 2019

@elasticmachine update branch

@hub-cap hub-cap merged commit 4ec68ec into elastic:master Aug 7, 2019
@hub-cap hub-cap deleted the ingest_has_processor_helper branch August 7, 2019 15:52
hub-cap added a commit that referenced this pull request Aug 7, 2019
This commit adds a helper method to the ingest service allowing it to
inspect a pipeline by id and verify the existence of a processor in the
pipeline. This work exposed a potential bug in that some processors
contain inner processors that are passed in at instantiation. These
processors needed a common way to expose their inner processors, so the
WrappingProcessor was created in order to expose the inner processor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP >enhancement v7.4.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants