Skip to content

Commit 0a45b13

Browse files
authored
ingest: expose reroute inquiry/reset via Elastic-internal API bridge (#96958)
* 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 #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. * Update docs/changelog/96958.yaml * javadoc: rephrase to avoid use of @APinote
1 parent 7d8aac3 commit 0a45b13

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

docs/changelog/96958.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 96958
2+
summary: "Ingest: expose reroute inquiry/reset via Elastic-internal API bridge"
3+
area: Ingest Node
4+
type: enhancement
5+
issues: []
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 Elastic-internal API bridge class exposes package-private components of Ingest
13+
* in a way that can be consumed by Logstash's Elastic Integration Filter without
14+
* expanding Elasticsearch's externally-consumable API.
15+
*/
16+
public class LogstashInternalBridge {
17+
18+
private LogstashInternalBridge() {}
19+
20+
/**
21+
* The document has been redirected to another target.
22+
* This implies that the default pipeline of the new target needs to be invoked.
23+
*
24+
* @return whether the document is redirected to another target
25+
*/
26+
public static boolean isReroute(final IngestDocument ingestDocument) {
27+
return ingestDocument.isReroute();
28+
}
29+
30+
/**
31+
* Set the reroute flag of the provided {@link IngestDocument} to {@code false}.
32+
*/
33+
public static void resetReroute(final IngestDocument ingestDocument) {
34+
ingestDocument.resetReroute();
35+
}
36+
}
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)