14
14
import org .apache .logging .log4j .LogManager ;
15
15
import org .apache .logging .log4j .Logger ;
16
16
import org .elasticsearch .action .support .RefCountingRunnable ;
17
- import org .elasticsearch .core .IOUtils ;
18
- import org .elasticsearch .ingest .IngestDocument ;
19
- import org .elasticsearch .ingest .LogstashInternalBridge ;
20
17
import org .elasticsearch .ingest .common .FailProcessorException ;
18
+ import org .elasticsearch .logstashbridge .core .IOUtilsBridge ;
19
+ import org .elasticsearch .logstashbridge .ingest .IngestDocumentBridge ;
21
20
22
21
import java .io .Closeable ;
23
22
import java .io .IOException ;
24
23
import java .util .Collection ;
25
24
import java .util .List ;
25
+ import java .util .Locale ;
26
26
import java .util .Map ;
27
27
import java .util .Objects ;
28
28
import java .util .Optional ;
32
32
33
33
import static co .elastic .logstash .filters .elasticintegration .util .EventUtil .eventAsMap ;
34
34
import static co .elastic .logstash .filters .elasticintegration .util .EventUtil .serializeEventForLog ;
35
- import static org .elasticsearch .core .Strings .format ;
36
35
37
36
/**
38
37
* An {@link EventProcessor} processes {@link Event}s by:
@@ -151,7 +150,7 @@ void processRequest(final IntegrationRequest request) {
151
150
152
151
final IngestPipeline ingestPipeline = loadedPipeline .get ();
153
152
LOGGER .trace (() -> String .format ("Using loaded pipeline `%s` (%s)" , pipelineName , System .identityHashCode (ingestPipeline )));
154
- final IngestDocument ingestDocument = eventMarshaller .toIngestDocument (request .event ());
153
+ final IngestDocumentBridge ingestDocument = eventMarshaller .toIngestDocument (request .event ());
155
154
156
155
resolvedIndexName .ifPresent (indexName -> {
157
156
ingestDocument .getMetadata ().setIndex (indexName );
@@ -170,7 +169,7 @@ void processRequest(final IntegrationRequest request) {
170
169
}
171
170
}
172
171
173
- private void executePipeline (final IngestDocument ingestDocument , final IngestPipeline ingestPipeline , final IntegrationRequest request ) {
172
+ private void executePipeline (final IngestDocumentBridge ingestDocument , final IngestPipeline ingestPipeline , final IntegrationRequest request ) {
174
173
final String pipelineName = ingestPipeline .getId ();
175
174
final String originalIndex = ingestDocument .getMetadata ().getIndex ();
176
175
ingestPipeline .execute (ingestDocument , (resultIngestDocument , ingestPipelineException ) -> {
@@ -193,17 +192,17 @@ private void executePipeline(final IngestDocument ingestDocument, final IngestPi
193
192
} else {
194
193
195
194
final String newIndex = resultIngestDocument .getMetadata ().getIndex ();
196
- if (!Objects .equals (originalIndex , newIndex ) && LogstashInternalBridge .isReroute (resultIngestDocument )) {
197
- LogstashInternalBridge .resetReroute (resultIngestDocument );
195
+ if (!Objects .equals (originalIndex , newIndex ) && ingestDocument .isReroute ()) {
196
+ ingestDocument .resetReroute ();
198
197
boolean cycle = !resultIngestDocument .updateIndexHistory (newIndex );
199
198
if (cycle ) {
200
199
request .complete (incomingEvent -> {
201
- annotateIngestPipelineFailure (incomingEvent , pipelineName , Map .of ("message" , format (
202
- "index cycle detected while processing pipeline [%s]: %s + %s" ,
203
- pipelineName ,
204
- resultIngestDocument .getIndexHistory (),
205
- newIndex
206
- ))) ;
200
+ annotateIngestPipelineFailure (incomingEvent , pipelineName , Map .of ("message" ,
201
+ String . format ( Locale . ROOT , "index cycle detected while processing pipeline [%s]: %s + %s" ,
202
+ pipelineName ,
203
+ resultIngestDocument .getIndexHistory (),
204
+ newIndex )
205
+ ));
207
206
});
208
207
return ;
209
208
}
@@ -214,12 +213,14 @@ private void executePipeline(final IngestDocument ingestDocument, final IngestPi
214
213
final Optional <IngestPipeline > reroutePipeline = resolve (reroutePipelineName .get (), internalPipelineProvider );
215
214
if (reroutePipeline .isEmpty ()) {
216
215
request .complete (incomingEvent -> {
217
- annotateIngestPipelineFailure (incomingEvent , pipelineName , Map . of ( "message" , format (
218
- "reroute failed to load next pipeline [%s]: %s -> %s" ,
216
+ annotateIngestPipelineFailure (
217
+ incomingEvent ,
219
218
pipelineName ,
220
- resultIngestDocument .getIndexHistory (),
221
- reroutePipelineName .get ()
222
- )));
219
+ Map .of ("message" ,
220
+ String .format (Locale .ROOT , "reroute failed to load next pipeline [%s]: %s -> %s" ,
221
+ pipelineName ,
222
+ resultIngestDocument .getIndexHistory (),
223
+ reroutePipelineName .get ())));
223
224
});
224
225
} else {
225
226
executePipeline (resultIngestDocument , reroutePipeline .get (), request );
@@ -277,6 +278,6 @@ static private <T,R> Optional<R> resolve(T resolvable, Resolver<T,R> resolver) {
277
278
278
279
@ Override
279
280
public void close () throws IOException {
280
- IOUtils .closeWhileHandlingException (this .resourcesToClose );
281
+ IOUtilsBridge .closeWhileHandlingException (this .resourcesToClose );
281
282
}
282
283
}
0 commit comments