mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
Handle rename ingest processor (#7332)
* Handle rename ingest processor Fixes #7325
This commit is contained in:
parent
6a1cfcf4b9
commit
ed94b46706
12 changed files with 122 additions and 1 deletions
|
@ -18,7 +18,7 @@ final class JsUtil {
|
|||
*/
|
||||
|
||||
private static final String[] SCRIPTS =
|
||||
{"shared", "date", "grok", "geoip", "gsub", "pipeline", "convert", "append", "json"};
|
||||
{"shared", "date", "grok", "geoip", "gsub", "pipeline", "convert", "append", "json", "rename"};
|
||||
|
||||
private JsUtil() {
|
||||
// Utility Class
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package org.logstash.ingest;
|
||||
|
||||
import javax.script.ScriptException;
|
||||
|
||||
public class Rename {
|
||||
private Rename() {
|
||||
// Utility Wrapper for JS Script.
|
||||
}
|
||||
|
||||
public static void main(final String... args) throws ScriptException, NoSuchMethodException {
|
||||
JsUtil.convert(args, "ingest_rename_to_logstash");
|
||||
}
|
||||
}
|
|
@ -41,6 +41,11 @@ function ingest_pipeline_to_logstash(json) {
|
|||
IngestConverter.create_hash("json", IngestJson.json_hash(processor))
|
||||
);
|
||||
}
|
||||
if (IngestRename.has_rename(processor)) {
|
||||
filter_blocks.push(
|
||||
IngestConverter.create_hash("mutate", IngestRename.rename_hash(processor))
|
||||
);
|
||||
}
|
||||
return IngestConverter.join_hash_fields(filter_blocks);
|
||||
}
|
||||
|
||||
|
|
30
tools/ingest-converter/src/main/resources/ingest-rename.js
Normal file
30
tools/ingest-converter/src/main/resources/ingest-rename.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
var IngestRename = {
|
||||
has_rename: function (processor) {
|
||||
return !!processor["rename"];
|
||||
},
|
||||
rename_hash: function (processor) {
|
||||
var rename_json = processor["rename"];
|
||||
var mutate_contents = IngestConverter.create_field(
|
||||
IngestConverter.quote_string(IngestConverter.dots_to_square_brackets(rename_json["field"])),
|
||||
IngestConverter.quote_string(IngestConverter.dots_to_square_brackets(rename_json["target_field"]))
|
||||
);
|
||||
return IngestConverter.create_field("rename", IngestConverter.wrap_in_curly(mutate_contents));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts Ingest Rename JSON to LS mutate filter.
|
||||
*/
|
||||
function ingest_rename_to_logstash(json) {
|
||||
|
||||
function map_processor(processor) {
|
||||
|
||||
return IngestConverter.filter_hash(
|
||||
IngestConverter.create_hash(
|
||||
"mutate", IngestRename.rename_hash(processor)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return IngestConverter.filters_to_file(JSON.parse(json)["processors"].map(map_processor));
|
||||
}
|
|
@ -22,6 +22,7 @@ public final class PipelineTest extends IngestTest {
|
|||
GsubTest.data().forEach(cases::add);
|
||||
AppendTest.data().forEach(cases::add);
|
||||
JsonTest.data().forEach(cases::add);
|
||||
RenameTest.data().forEach(cases::add);
|
||||
return cases;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package org.logstash.ingest;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
public final class RenameTest extends IngestTest {
|
||||
|
||||
@Parameters
|
||||
public static Iterable<String> data() {
|
||||
return Arrays.asList("Rename", "DotsInRenameField");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertsConvertProcessorCorrectly() throws Exception {
|
||||
final String rename = getResultPath(temp);
|
||||
Rename.main(resourcePath(String.format("ingest%s.json", testCase)), rename);
|
||||
assertThat(
|
||||
utf8File(rename), is(utf8File(resourcePath(String.format("logstash%s.conf", testCase))))
|
||||
);
|
||||
}
|
||||
}
|
|
@ -41,6 +41,12 @@
|
|||
"json": {
|
||||
"field": "string_source"
|
||||
}
|
||||
},
|
||||
{
|
||||
"rename": {
|
||||
"field": "foo",
|
||||
"target_field": "foobar"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"description": "ExampleRename",
|
||||
"processors": [
|
||||
{
|
||||
"rename": {
|
||||
"field": "foo.bar",
|
||||
"target_field": "foo.baz"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"description": "ExampleRename",
|
||||
"processors": [
|
||||
{
|
||||
"rename": {
|
||||
"field": "foo",
|
||||
"target_field": "foobar"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -33,4 +33,9 @@ filter {
|
|||
json {
|
||||
source => "string_source"
|
||||
}
|
||||
mutate {
|
||||
rename => {
|
||||
"foo" => "foobar"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
filter {
|
||||
mutate {
|
||||
rename => {
|
||||
"[foo][bar]" => "[foo][baz]"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
filter {
|
||||
mutate {
|
||||
rename => {
|
||||
"foo" => "foobar"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue