我设法整理了一个测试用例,并找出了语法,既可以提供这样的测试数据,也可以提取 VRL 中的数据:
测试用例
---
tests:
- name: hypens
inputs:
- insert_at: hypens
type: log
log_fields:
labels."this-has-hypens": "this is a test"
labels.no_hypens: "normal field"
outputs:
- extract_from: hypens
conditions:
- type: vrl
source: |
assert_eq!("normal field", .no_hypens)
assert_eq!("this is a test", .output_without_hypens)
这将插入并检查输入数据中的两个字段。请注意,需要引用带连字符的关键段。
接下来是变换中的 VRL:
---
transforms:
hypens:
type: remap
inputs:
- route
source: |
log(., "error")
. = {
"no_hypens": .labels.no_hypens,
"output_without_hypens": .labels."this-has-hypens",
}
日志消息在那里,因为在调试它时,我必须弄清楚测试连字符字段甚至没有到达转换,直到我在它周围加上引号。
然后字段引用本身也需要有引号,在点之后(不是方括号)。
这将通过测试,并输出正确的数据。