@@ -40,6 +40,7 @@ public class CompoundProcessor implements Processor {
40
40
public static final String ON_FAILURE_MESSAGE_FIELD = "on_failure_message" ;
41
41
public static final String ON_FAILURE_PROCESSOR_TYPE_FIELD = "on_failure_processor_type" ;
42
42
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" ;
43
44
44
45
private final boolean ignoreFailure ;
45
46
private final List <Processor > processors ;
@@ -144,7 +145,7 @@ void innerExecute(int currentProcessor, IngestDocument ingestDocument, BiConsume
144
145
innerExecute (currentProcessor + 1 , ingestDocument , handler );
145
146
} else {
146
147
IngestProcessorException compoundProcessorException =
147
- newCompoundProcessorException (e , processor . getType (), processor . getTag () );
148
+ newCompoundProcessorException (e , processor , ingestDocument );
148
149
if (onFailureProcessors .isEmpty ()) {
149
150
handler .accept (null , compoundProcessorException );
150
151
} else {
@@ -177,7 +178,7 @@ void executeOnFailureAsync(int currentOnFailureProcessor, IngestDocument ingestD
177
178
onFailureProcessor .execute (ingestDocument , (result , e ) -> {
178
179
if (e != null ) {
179
180
removeFailureMetadata (ingestDocument );
180
- handler .accept (null , newCompoundProcessorException (e , onFailureProcessor . getType (), onFailureProcessor . getTag () ));
181
+ handler .accept (null , newCompoundProcessorException (e , onFailureProcessor , ingestDocument ));
181
182
return ;
182
183
}
183
184
if (result == null ) {
@@ -192,34 +193,46 @@ void executeOnFailureAsync(int currentOnFailureProcessor, IngestDocument ingestD
192
193
private void putFailureMetadata (IngestDocument ingestDocument , ElasticsearchException cause ) {
193
194
List <String > processorTypeHeader = cause .getHeader ("processor_type" );
194
195
List <String > processorTagHeader = cause .getHeader ("processor_tag" );
196
+ List <String > processorOriginHeader = cause .getHeader ("pipeline_origin" );
195
197
String failedProcessorType = (processorTypeHeader != null ) ? processorTypeHeader .get (0 ) : null ;
196
198
String failedProcessorTag = (processorTagHeader != null ) ? processorTagHeader .get (0 ) : null ;
199
+ String failedPipelineId = (processorOriginHeader != null ) ? processorOriginHeader .get (0 ) : null ;
197
200
Map <String , Object > ingestMetadata = ingestDocument .getIngestMetadata ();
198
201
ingestMetadata .put (ON_FAILURE_MESSAGE_FIELD , cause .getRootCause ().getMessage ());
199
202
ingestMetadata .put (ON_FAILURE_PROCESSOR_TYPE_FIELD , failedProcessorType );
200
203
ingestMetadata .put (ON_FAILURE_PROCESSOR_TAG_FIELD , failedProcessorTag );
204
+ if (failedPipelineId != null ) {
205
+ ingestMetadata .put (ON_FAILURE_PIPELINE_FIELD , failedPipelineId );
206
+ }
201
207
}
202
208
203
209
private void removeFailureMetadata (IngestDocument ingestDocument ) {
204
210
Map <String , Object > ingestMetadata = ingestDocument .getIngestMetadata ();
205
211
ingestMetadata .remove (ON_FAILURE_MESSAGE_FIELD );
206
212
ingestMetadata .remove (ON_FAILURE_PROCESSOR_TYPE_FIELD );
207
213
ingestMetadata .remove (ON_FAILURE_PROCESSOR_TAG_FIELD );
214
+ ingestMetadata .remove (ON_FAILURE_PIPELINE_FIELD );
208
215
}
209
216
210
- private IngestProcessorException newCompoundProcessorException (Exception e , String processorType , String processorTag ) {
217
+ static IngestProcessorException newCompoundProcessorException (Exception e , Processor processor , IngestDocument document ) {
211
218
if (e instanceof IngestProcessorException && ((IngestProcessorException ) e ).getHeader ("processor_type" ) != null ) {
212
219
return (IngestProcessorException ) e ;
213
220
}
214
221
215
222
IngestProcessorException exception = new IngestProcessorException (e );
216
223
224
+ String processorType = processor .getType ();
217
225
if (processorType != null ) {
218
226
exception .addHeader ("processor_type" , processorType );
219
227
}
228
+ String processorTag = processor .getTag ();
220
229
if (processorTag != null ) {
221
230
exception .addHeader ("processor_tag" , processorTag );
222
231
}
232
+ List <String > pipelineStack = document .getPipelineStack ();
233
+ if (pipelineStack .size () > 1 ) {
234
+ exception .addHeader ("pipeline_origin" , pipelineStack );
235
+ }
223
236
224
237
return exception ;
225
238
}
0 commit comments