Skip to content

ingest: expose reroute inquiry/reset via Elastic-internal API bridge #96958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/96958.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 96958
summary: "Ingest: expose reroute inquiry/reset via Elastic-internal API bridge"
area: Ingest Node
type: enhancement
issues: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.ingest;

/**
* This Elastic-internal API bridge class exposes package-private components of Ingest
* in a way that can be consumed by Logstash's Elastic Integration Filter without
* expanding Elasticsearch's externally-consumable API.
*/
public class LogstashInternalBridge {

private LogstashInternalBridge() {}

/**
* The document has been redirected to another target.
* This implies that the default pipeline of the new target needs to be invoked.
*
* @return whether the document is redirected to another target
*/
public static boolean isReroute(final IngestDocument ingestDocument) {
return ingestDocument.isReroute();
}

/**
* Set the reroute flag of the provided {@link IngestDocument} to {@code false}.
*/
public static void resetReroute(final IngestDocument ingestDocument) {
ingestDocument.resetReroute();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.ingest;

import org.elasticsearch.test.ESTestCase;

import static org.elasticsearch.ingest.TestIngestDocument.emptyIngestDocument;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

public class LogstashInternalBridgeTests extends ESTestCase {
public void testIngestDocumentRerouteBridge() {
final IngestDocument ingestDocument = emptyIngestDocument();
ingestDocument.setFieldValue("_index", "nowhere");
assertThat(ingestDocument.getFieldValue("_index", String.class), is(equalTo("nowhere")));
assertThat(LogstashInternalBridge.isReroute(ingestDocument), is(false));

ingestDocument.reroute("somewhere");
assertThat(ingestDocument.getFieldValue("_index", String.class), is(equalTo("somewhere")));
assertThat(LogstashInternalBridge.isReroute(ingestDocument), is(true));

LogstashInternalBridge.resetReroute(ingestDocument);
assertThat(ingestDocument.getFieldValue("_index", String.class), is(equalTo("somewhere")));
assertThat(LogstashInternalBridge.isReroute(ingestDocument), is(false));
}
}