Skip to content
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

libbeat: fix decode_json_fields config validation (bp #24862) #25031

Merged
merged 1 commit into from
Apr 13, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix ILM alias not being created if `setup.ilm.check_exists: false` and `setup.ilm.overwrite: true` has been configured. {pull}24480[24480]
- Allow cgroup self-monitoring to see alternate `hostfs` paths {pull}24334[24334]

- Add `expand_keys` to the list of permitted config fields for `decode_json_fields` {24862}[24862]
- Fix 'make setup' instructions for a new beat {pull}24944[24944]
- Fix inode removal tracking code when files are replaced by files with the same name {pull}25002[25002]

Expand Down
2 changes: 1 addition & 1 deletion libbeat/processors/actions/decode_json_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func init() {
processors.RegisterPlugin("decode_json_fields",
checks.ConfigChecked(NewDecodeJSONFields,
checks.RequireFields("fields"),
checks.AllowedFields("fields", "max_depth", "overwrite_keys", "add_error_key", "process_array", "target", "when", "document_id")))
checks.AllowedFields("fields", "max_depth", "overwrite_keys", "add_error_key", "process_array", "target", "when", "document_id", "expand_keys")))

jsprocessor.RegisterPlugin("DecodeJSONFields", NewDecodeJSONFields)
}
Expand Down
24 changes: 24 additions & 0 deletions libbeat/processors/actions/decode_json_fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/beats/v7/libbeat/processors"
)

var fields = [1]string{"msg"}
Expand All @@ -35,6 +36,29 @@ var testConfig, _ = common.NewConfigFrom(map[string]interface{}{
"processArray": false,
})

func TestDecodeJSONFieldsCheckConfig(t *testing.T) {
// All fields defined in config should be allowed.
cfg := common.MustNewConfigFrom(map[string]interface{}{
"decode_json_fields": &config{
// Rely on zero values for all fields that don't have validation.
MaxDepth: 1,
},
})
_, err := processors.New(processors.PluginConfig([]*common.Config{cfg}))
assert.NoError(t, err)

// Unknown fields should not be allowed.
cfg = common.MustNewConfigFrom(map[string]interface{}{
"decode_json_fields": map[string]interface{}{
"fields": []string{"required"},
"extraneous": "field",
},
})
_, err = processors.New(processors.PluginConfig([]*common.Config{cfg}))
assert.Error(t, err)
assert.EqualError(t, err, "unexpected extraneous option in decode_json_fields")
}

func TestMissingKey(t *testing.T) {
input := common.MapStr{
"pipeline": "us1",
Expand Down