Skip to content

Commit bc9af21

Browse files
committed
Replace ES classes with their Bridge Stable API pairs.
1 parent a9d7625 commit bc9af21

17 files changed

+293
-261
lines changed

build.gradle

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,45 @@ task buildElasticsearchLocalDistro(dependsOn: unzipDownloadedElasticsearchSource
257257
}
258258
}
259259

260+
task buildElasticsearchLogstashBridge(type: Exec) {
261+
description "builds logstash-bridge lib module"
262+
263+
dependsOn buildElasticsearchLocalDistro
264+
mustRunAfter buildElasticsearchLocalDistro
265+
266+
def logFile = project.file("${buildDir}/logstash-bridge-build.log")
267+
doFirst {
268+
def funneler = new OutputStreamFunneler(new LazyFileOutputStream(logFile))
269+
standardOutput = funneler.funnelInstance
270+
errorOutput = funneler.funnelInstance
271+
}
272+
273+
def esSource = "${buildDir}/elasticsearch-source/"
274+
def esBuildDir = "${esSource}/build"
275+
276+
inputs.dir esSource
277+
outputs.dir "${esBuildDir}/libs/logstash-bridge"
278+
279+
ext.buildRoot = esBuildDir
280+
workingDir esSource
281+
commandLine "./gradlew", ":lib:logstash-bridge:build"
282+
283+
ignoreExitValue true // handled in doLast
284+
doLast {
285+
def exitValue = executionResult.get().exitValue
286+
if (exitValue != 0) {
287+
if (logFile.exists()) {
288+
println "\n===== Elasticsearch logstash-bridge build Log ====="
289+
println logFile.text
290+
println "===== End of Elasticsearch logstash-bridge build Log =====\n"
291+
} else {
292+
"Elasticsearch logstash-bridge build failed and ${logFile.path} log does not exist"
293+
}
294+
throw new GradleException("Elasticsearch logstash-bridge build failed, see the logs for details.")
295+
}
296+
}
297+
}
298+
260299
task shadeElasticsearchIngestGeoIpModule(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
261300
description "Shades embedded dependencies of the Elasticsearch Ingest GeoIP module"
262301

@@ -316,13 +355,30 @@ task shadeElasticsearchRedactPlugin(type: com.github.jengelman.gradle.plugins.sh
316355
exclude '**/module-info.class'
317356
}
318357

358+
task shadeElasticsearchLogstashBridge(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
359+
description "Shades the Elasticsearch logstash-bridge jar"
360+
361+
dependsOn buildElasticsearchLogstashBridge
362+
363+
from("${buildDir}/elasticsearch-source/libs/logstash-bridge/build/distributions") {
364+
include "elasticsearch-logstash-bridge-*.jar"
365+
}
366+
367+
archiveFileName = "elasticsearch-logstash-bridge-shaded.jar"
368+
destinationDirectory = file("${buildDir}/shaded")
369+
370+
exclude '**/module-info.class'
371+
}
372+
319373
task importMinimalElasticsearch() {
320374
description "Imports minimal portions of Elasticsearch localDistro"
321375

322376
dependsOn buildElasticsearchLocalDistro
377+
dependsOn buildElasticsearchLogstashBridge
323378
dependsOn shadeElasticsearchIngestGeoIpModule
324379
dependsOn shadeElasticsearchGrokImplementation
325380
dependsOn shadeElasticsearchRedactPlugin
381+
dependsOn shadeElasticsearchLogstashBridge
326382

327383
ext.jars = "${buildDir}/elasticsearch-minimal-jars"
328384

@@ -341,6 +397,7 @@ task importMinimalElasticsearch() {
341397
include jarPackageNamed("lucene-core")
342398
include jarPackageNamed("lucene-analysis-common")
343399
}
400+
from(shadeElasticsearchLogstashBridge)
344401
from(shadeElasticsearchGrokImplementation)
345402
from(buildElasticsearchLocalDistro.module("x-pack-core"))
346403

src/main/java/co/elastic/logstash/filters/elasticintegration/ElasticsearchPipelineConfigurationResolver.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.elasticsearch.client.Response;
1616
import org.elasticsearch.client.ResponseException;
1717
import org.elasticsearch.client.RestClient;
18-
import org.elasticsearch.ingest.PipelineConfiguration;
18+
import org.elasticsearch.logstashbridge.ingest.PipelineConfigurationBridge;
1919

2020
import java.util.Optional;
2121

@@ -24,7 +24,7 @@
2424
* that retrieves pipelines from Elasticsearch.
2525
*/
2626
public class ElasticsearchPipelineConfigurationResolver
27-
extends AbstractSimpleResolver<String,PipelineConfiguration>
27+
extends AbstractSimpleResolver<String, PipelineConfigurationBridge>
2828
implements PipelineConfigurationResolver {
2929
private final RestClient elasticsearchRestClient;
3030
private final PipelineConfigurationFactory pipelineConfigurationFactory;
@@ -37,13 +37,13 @@ public ElasticsearchPipelineConfigurationResolver(final RestClient elasticsearch
3737
}
3838

3939
@Override
40-
public Optional<PipelineConfiguration> resolveSafely(String pipelineName) throws Exception {
40+
public Optional<PipelineConfigurationBridge> resolveSafely(String pipelineName) throws Exception {
4141
final Response response;
4242
try {
4343
final Request request = new Request("GET", URLEncodedUtils.formatSegments("_ingest", "pipeline", pipelineName));
4444
response = elasticsearchRestClient.performRequest(request);
4545
final String jsonEncodedPayload = EntityUtils.toString(response.getEntity());
46-
final PipelineConfiguration pipelineConfiguration = pipelineConfigurationFactory.parseNamedObject(jsonEncodedPayload);
46+
final PipelineConfigurationBridge pipelineConfiguration = pipelineConfigurationFactory.parseNamedObject(jsonEncodedPayload);
4747
return Optional.of(pipelineConfiguration);
4848
} catch (ResponseException re) {
4949
if (re.getResponse().getStatusLine().getStatusCode() == 404) {

src/main/java/co/elastic/logstash/filters/elasticintegration/EventProcessor.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
import org.apache.logging.log4j.LogManager;
1515
import org.apache.logging.log4j.Logger;
1616
import org.elasticsearch.action.support.RefCountingRunnable;
17-
import org.elasticsearch.core.IOUtils;
18-
import org.elasticsearch.ingest.IngestDocument;
19-
import org.elasticsearch.ingest.LogstashInternalBridge;
2017
import org.elasticsearch.ingest.common.FailProcessorException;
18+
import org.elasticsearch.logstashbridge.core.IOUtilsBridge;
19+
import org.elasticsearch.logstashbridge.ingest.IngestDocumentBridge;
2120

2221
import java.io.Closeable;
2322
import java.io.IOException;
2423
import java.util.Collection;
2524
import java.util.List;
25+
import java.util.Locale;
2626
import java.util.Map;
2727
import java.util.Objects;
2828
import java.util.Optional;
@@ -32,7 +32,6 @@
3232

3333
import static co.elastic.logstash.filters.elasticintegration.util.EventUtil.eventAsMap;
3434
import static co.elastic.logstash.filters.elasticintegration.util.EventUtil.serializeEventForLog;
35-
import static org.elasticsearch.core.Strings.format;
3635

3736
/**
3837
* An {@link EventProcessor} processes {@link Event}s by:
@@ -151,7 +150,7 @@ void processRequest(final IntegrationRequest request) {
151150

152151
final IngestPipeline ingestPipeline = loadedPipeline.get();
153152
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());
155154

156155
resolvedIndexName.ifPresent(indexName -> {
157156
ingestDocument.getMetadata().setIndex(indexName);
@@ -170,7 +169,7 @@ void processRequest(final IntegrationRequest request) {
170169
}
171170
}
172171

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) {
174173
final String pipelineName = ingestPipeline.getId();
175174
final String originalIndex = ingestDocument.getMetadata().getIndex();
176175
ingestPipeline.execute(ingestDocument, (resultIngestDocument, ingestPipelineException) -> {
@@ -193,17 +192,17 @@ private void executePipeline(final IngestDocument ingestDocument, final IngestPi
193192
} else {
194193

195194
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();
198197
boolean cycle = !resultIngestDocument.updateIndexHistory(newIndex);
199198
if (cycle) {
200199
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+
));
207206
});
208207
return;
209208
}
@@ -214,12 +213,14 @@ private void executePipeline(final IngestDocument ingestDocument, final IngestPi
214213
final Optional<IngestPipeline> reroutePipeline = resolve(reroutePipelineName.get(), internalPipelineProvider);
215214
if (reroutePipeline.isEmpty()) {
216215
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,
219218
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())));
223224
});
224225
} else {
225226
executePipeline(resultIngestDocument, reroutePipeline.get(), request);
@@ -277,6 +278,6 @@ static private <T,R> Optional<R> resolve(T resolvable, Resolver<T,R> resolver) {
277278

278279
@Override
279280
public void close() throws IOException {
280-
IOUtils.closeWhileHandlingException(this.resourcesToClose);
281+
IOUtilsBridge.closeWhileHandlingException(this.resourcesToClose);
281282
}
282283
}

0 commit comments

Comments
 (0)