Hook up json_strict option with default of true (#6909)
This commit is contained in:
parent
5f1f4b9e8d
commit
c6519c7793
|
@ -1411,7 +1411,9 @@ func buildParser(name string, tbl *ast.Table) (parsers.Parser, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getParserConfig(name string, tbl *ast.Table) (*parsers.Config, error) {
|
func getParserConfig(name string, tbl *ast.Table) (*parsers.Config, error) {
|
||||||
c := &parsers.Config{}
|
c := &parsers.Config{
|
||||||
|
JSONStrict: true,
|
||||||
|
}
|
||||||
|
|
||||||
if node, ok := tbl.Fields["data_format"]; ok {
|
if node, ok := tbl.Fields["data_format"]; ok {
|
||||||
if kv, ok := node.(*ast.KeyValue); ok {
|
if kv, ok := node.(*ast.KeyValue); ok {
|
||||||
|
@ -1512,6 +1514,18 @@ func getParserConfig(name string, tbl *ast.Table) (*parsers.Config, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if node, ok := tbl.Fields["json_strict"]; ok {
|
||||||
|
if kv, ok := node.(*ast.KeyValue); ok {
|
||||||
|
if b, ok := kv.Value.(*ast.Boolean); ok {
|
||||||
|
var err error
|
||||||
|
c.JSONStrict, err = b.Boolean()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if node, ok := tbl.Fields["data_type"]; ok {
|
if node, ok := tbl.Fields["data_type"]; ok {
|
||||||
if kv, ok := node.(*ast.KeyValue); ok {
|
if kv, ok := node.(*ast.KeyValue); ok {
|
||||||
if str, ok := kv.Value.(*ast.String); ok {
|
if str, ok := kv.Value.(*ast.String); ok {
|
||||||
|
@ -1808,6 +1822,7 @@ func getParserConfig(name string, tbl *ast.Table) (*parsers.Config, error) {
|
||||||
delete(tbl.Fields, "json_time_format")
|
delete(tbl.Fields, "json_time_format")
|
||||||
delete(tbl.Fields, "json_time_key")
|
delete(tbl.Fields, "json_time_key")
|
||||||
delete(tbl.Fields, "json_timezone")
|
delete(tbl.Fields, "json_timezone")
|
||||||
|
delete(tbl.Fields, "json_strict")
|
||||||
delete(tbl.Fields, "data_type")
|
delete(tbl.Fields, "data_type")
|
||||||
delete(tbl.Fields, "collectd_auth_file")
|
delete(tbl.Fields, "collectd_auth_file")
|
||||||
delete(tbl.Fields, "collectd_security_level")
|
delete(tbl.Fields, "collectd_security_level")
|
||||||
|
|
|
@ -149,6 +149,7 @@ func TestConfig_LoadDirectory(t *testing.T) {
|
||||||
p, err := parsers.NewParser(&parsers.Config{
|
p, err := parsers.NewParser(&parsers.Config{
|
||||||
MetricName: "exec",
|
MetricName: "exec",
|
||||||
DataFormat: "json",
|
DataFormat: "json",
|
||||||
|
JSONStrict: true,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
ex.SetParser(p)
|
ex.SetParser(p)
|
||||||
|
|
|
@ -20,7 +20,7 @@ ignored unless specified in the `tag_key` or `json_string_fields` options.
|
||||||
|
|
||||||
## When strict is true and a JSON array is being parsed, all objects within the
|
## When strict is true and a JSON array is being parsed, all objects within the
|
||||||
## array must be valid
|
## array must be valid
|
||||||
strict = false
|
json_strict = true
|
||||||
|
|
||||||
## Query is a GJSON path that specifies a specific chunk of JSON to be
|
## Query is a GJSON path that specifies a specific chunk of JSON to be
|
||||||
## parsed, if not specified the whole document will be parsed.
|
## parsed, if not specified the whole document will be parsed.
|
||||||
|
|
Loading…
Reference in New Issue