@@ -40,6 +40,7 @@ public class CompoundProcessor implements Processor {
4040 public static final String ON_FAILURE_MESSAGE_FIELD = "on_failure_message" ;
4141 public static final String ON_FAILURE_PROCESSOR_TYPE_FIELD = "on_failure_processor_type" ;
4242 public static final String ON_FAILURE_PROCESSOR_TAG_FIELD = "on_failure_processor_tag" ;
43+ public static final String ON_FAILURE_PIPELINE_FIELD = "on_failure_pipeline" ;
4344
4445 private final boolean ignoreFailure ;
4546 private final List <Processor > processors ;
@@ -144,7 +145,7 @@ void innerExecute(int currentProcessor, IngestDocument ingestDocument, BiConsume
144145 innerExecute (currentProcessor + 1 , ingestDocument , handler );
145146 } else {
146147 IngestProcessorException compoundProcessorException =
147- newCompoundProcessorException (e , processor . getType (), processor . getTag () );
148+ newCompoundProcessorException (e , processor , ingestDocument );
148149 if (onFailureProcessors .isEmpty ()) {
149150 handler .accept (null , compoundProcessorException );
150151 } else {
@@ -177,7 +178,7 @@ void executeOnFailureAsync(int currentOnFailureProcessor, IngestDocument ingestD
177178 onFailureProcessor .execute (ingestDocument , (result , e ) -> {
178179 if (e != null ) {
179180 removeFailureMetadata (ingestDocument );
180- handler .accept (null , newCompoundProcessorException (e , onFailureProcessor . getType (), onFailureProcessor . getTag () ));
181+ handler .accept (null , newCompoundProcessorException (e , onFailureProcessor , ingestDocument ));
181182 return ;
182183 }
183184 if (result == null ) {
@@ -192,34 +193,46 @@ void executeOnFailureAsync(int currentOnFailureProcessor, IngestDocument ingestD
192193 private void putFailureMetadata (IngestDocument ingestDocument , ElasticsearchException cause ) {
193194 List <String > processorTypeHeader = cause .getHeader ("processor_type" );
194195 List <String > processorTagHeader = cause .getHeader ("processor_tag" );
196+ List <String > processorOriginHeader = cause .getHeader ("pipeline_origin" );
195197 String failedProcessorType = (processorTypeHeader != null ) ? processorTypeHeader .get (0 ) : null ;
196198 String failedProcessorTag = (processorTagHeader != null ) ? processorTagHeader .get (0 ) : null ;
199+ String failedPipelineId = (processorOriginHeader != null ) ? processorOriginHeader .get (0 ) : null ;
197200 Map <String , Object > ingestMetadata = ingestDocument .getIngestMetadata ();
198201 ingestMetadata .put (ON_FAILURE_MESSAGE_FIELD , cause .getRootCause ().getMessage ());
199202 ingestMetadata .put (ON_FAILURE_PROCESSOR_TYPE_FIELD , failedProcessorType );
200203 ingestMetadata .put (ON_FAILURE_PROCESSOR_TAG_FIELD , failedProcessorTag );
204+ if (failedPipelineId != null ) {
205+ ingestMetadata .put (ON_FAILURE_PIPELINE_FIELD , failedPipelineId );
206+ }
201207 }
202208
203209 private void removeFailureMetadata (IngestDocument ingestDocument ) {
204210 Map <String , Object > ingestMetadata = ingestDocument .getIngestMetadata ();
205211 ingestMetadata .remove (ON_FAILURE_MESSAGE_FIELD );
206212 ingestMetadata .remove (ON_FAILURE_PROCESSOR_TYPE_FIELD );
207213 ingestMetadata .remove (ON_FAILURE_PROCESSOR_TAG_FIELD );
214+ ingestMetadata .remove (ON_FAILURE_PIPELINE_FIELD );
208215 }
209216
210- private IngestProcessorException newCompoundProcessorException (Exception e , String processorType , String processorTag ) {
217+ static IngestProcessorException newCompoundProcessorException (Exception e , Processor processor , IngestDocument document ) {
211218 if (e instanceof IngestProcessorException && ((IngestProcessorException ) e ).getHeader ("processor_type" ) != null ) {
212219 return (IngestProcessorException ) e ;
213220 }
214221
215222 IngestProcessorException exception = new IngestProcessorException (e );
216223
224+ String processorType = processor .getType ();
217225 if (processorType != null ) {
218226 exception .addHeader ("processor_type" , processorType );
219227 }
228+ String processorTag = processor .getTag ();
220229 if (processorTag != null ) {
221230 exception .addHeader ("processor_tag" , processorTag );
222231 }
232+ List <String > pipelineStack = document .getPipelineStack ();
233+ if (pipelineStack .size () > 1 ) {
234+ exception .addHeader ("pipeline_origin" , pipelineStack );
235+ }
223236
224237 return exception ;
225238 }
0 commit comments