fix(parsers.xpath): Handle explicitly defined fields correctly (#13550)

This commit is contained in:
Sven Rebhan 2023-07-06 16:16:35 +02:00 committed by GitHub
parent 64ea1d00cb
commit 57bcdaf695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 0 deletions

View File

@ -397,6 +397,13 @@ func (p *Parser) parseQuery(starttime time.Time, doc, selected dataNode, config
if err != nil {
return nil, fmt.Errorf("failed to query field %q: %w", name, err)
}
if config.FieldsHexFilter != nil && config.FieldsHexFilter.Match(name) {
if b, ok := v.([]byte); ok {
v = hex.EncodeToString(b)
}
}
fields[name] = v
}

View File

@ -0,0 +1 @@
data fieldc="this is a test",fielda="0001020304050607",fieldb="666f6f626172" 1687852514000000000

View File

@ -0,0 +1,29 @@
# Example data:
# [
# {
# "str_a": bytearray("this is a test"),
# "str_b": bytearray("foobar"),
# "bytes_a": bytearray([0, 1, 2, 3, 4, 5, 6, 7]),
# "bytes_b": bytearray("foobar"),
# "timestamp": 1687852514
# }
# ]
[[inputs.file]]
files = ["./testcases/cbor_hex_encoding/data.bin"]
data_format = "xpath_cbor"
xpath_native_types = true
[[inputs.file.xpath]]
metric_name = "'data'"
metric_selection = "child::*"
timestamp = "timestamp"
timestamp_format = "unix"
fields_bytes_as_hex = ["fielda", "fieldb"]
[inputs.file.xpath.fields]
fielda = "bytes_a"
fieldb = "bytes_b"
fieldc = "str_a"