Skip to content

Commit

Permalink
Align Logstash bracket field syntax with Logstash
Browse files Browse the repository at this point in the history
  • Loading branch information
breml committed Sep 24, 2021
1 parent fa66034 commit 3e559ab
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/testcase/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func parseAllBracketProperties(data map[string]interface{}) map[string]interface

// extractBracketFields convert bracket notation to slice of key.
func extractBracketFields(key string) []string {
rValidator := regexp.MustCompile(`^(\[\w+\])+$`)
rExtractField := regexp.MustCompile(`\[(\w+)\]`)
rValidator := regexp.MustCompile(`^(\[[^\[\],]+\])+$`)
rExtractField := regexp.MustCompile(`\[([^\[\],]+)\]`)
listKeys := make([]string, 0, 1)

if rValidator.MatchString(key) {
Expand Down
6 changes: 6 additions & 0 deletions internal/testcase/testcase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ func TestConvertBracketFields(t *testing.T) {
"type": "test",
"[log][file][path]": "/tmp/file.log",
"[log][origin][file]": "test.java",
"[log][special_field.name-with some+spice]": "value",
"[@metadata][field]": "value",
},
Codec: "json_lines",
InputLines: []string{
Expand All @@ -487,6 +489,10 @@ func TestConvertBracketFields(t *testing.T) {
"origin": map[string]interface{}{
"file": "test.java",
},
"special_field.name-with some+spice": "value",
},
"@metadata": map[string]interface{}{
"field": "value",
},
},
Codec: "json_lines",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"ignore": [
"@timestamp"
],
"input_plugin": "stdin",
"export_metadata": true,
"testcases": [
{
"fields": {
"[@metadata][testcase]": "value"
},
"expected": [
{
"@metadata": {
"filter": "value",
"testcase": "value"
}
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"ignore": [
"@timestamp"
],
"input_plugin": "stdin",
"export_metadata": true,
"fields": {
"[@metadata][global]": "value"
},
"testcases": [
{
"fields": {
"key": "value"
},
"expected": [
{
"@metadata": {
"filter": "value",
"global": "value"
},
"key": "value"
}
]
}
]
}
24 changes: 24 additions & 0 deletions testdata/testcases/testcases_event/testcases_metadata_nested.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"ignore": [
"@timestamp"
],
"input_plugin": "stdin",
"export_metadata": true,
"testcases": [
{
"fields": {
"@metadata": {
"testcase": "value"
}
},
"expected": [
{
"@metadata": {
"filter": "value",
"testcase": "value"
}
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"ignore": [
"@timestamp"
],
"input_plugin": "stdin",
"export_metadata": true,
"fields": {
"@metadata": {
"global": "value"
}
},
"testcases": [
{
"fields": {
"key": "value"
},
"expected": [
{
"@metadata": {
"filter": "value",
"global": "value"
},
"key": "value"
}
]
}
]
}
6 changes: 6 additions & 0 deletions testdata/testcases_event/testcases_event.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ input {
id => "stdin"
}
}
filter {
mutate {
id => "add_metadata"
add_field => { "[@metadata][filter]" => "value" }
}
}
output {
stdout {
id => "stdout"
Expand Down

0 comments on commit 3e559ab

Please sign in to comment.