Skip to content

Commit ed27708

Browse files
committed
ingest: expose reroute inquiry/reset via Elastic-internal API bridge
Logstash's Integration filter works directly with the processors, but cannot use the IngestService that is tightly-coupled with cluster state and must therefore emulate the behavior introduced in elastic#94000. To do so, the additional methods for inquiring about and resetting the reroute state need to be externally-accessible. Exposing them through a clearly-named bridge allows us to avoid making these Elastic-internal bits a part of the public APIs that are subject to years-long stability and deprecation notice policies.
1 parent 6cf467f commit ed27708

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.ingest;
10+
11+
/**
12+
* This bridge class exposes package-private components of Ingest in a way
13+
* that can be consumed by Logstash's Elastic Integration Filter without
14+
* expanding our externally-consumable API.
15+
*
16+
* @apiNote this is an Elastic-internal API bridge intended for exclusive use by
17+
* Logstash and its Elastic Integration Filter.
18+
*/
19+
public class LogstashInternalBridge {
20+
21+
private LogstashInternalBridge() {}
22+
23+
/**
24+
* The document has been redirected to another target.
25+
* This implies that the default pipeline of the new target needs to be invoked.
26+
*
27+
* @return whether the document is redirected to another target
28+
*/
29+
public static boolean isReroute(final IngestDocument ingestDocument) {
30+
return ingestDocument.isReroute();
31+
}
32+
33+
/**
34+
* Set the reroute flag of the provided {@link IngestDocument} to {@code false}.
35+
*/
36+
public static void resetReroute(final IngestDocument ingestDocument) {
37+
ingestDocument.resetReroute();
38+
}
39+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.ingest;
10+
11+
import org.elasticsearch.test.ESTestCase;
12+
13+
import static org.elasticsearch.ingest.TestIngestDocument.emptyIngestDocument;
14+
import static org.hamcrest.Matchers.equalTo;
15+
import static org.hamcrest.Matchers.is;
16+
17+
public class LogstashInternalBridgeTests extends ESTestCase {
18+
public void testIngestDocumentRerouteBridge() {
19+
final IngestDocument ingestDocument = emptyIngestDocument();
20+
ingestDocument.setFieldValue("_index", "nowhere");
21+
assertThat(ingestDocument.getFieldValue("_index", String.class), is(equalTo("nowhere")));
22+
assertThat(LogstashInternalBridge.isReroute(ingestDocument), is(false));
23+
24+
ingestDocument.reroute("somewhere");
25+
assertThat(ingestDocument.getFieldValue("_index", String.class), is(equalTo("somewhere")));
26+
assertThat(LogstashInternalBridge.isReroute(ingestDocument), is(true));
27+
28+
LogstashInternalBridge.resetReroute(ingestDocument);
29+
assertThat(ingestDocument.getFieldValue("_index", String.class), is(equalTo("somewhere")));
30+
assertThat(LogstashInternalBridge.isReroute(ingestDocument), is(false));
31+
}
32+
}

0 commit comments

Comments
 (0)