chore(parsers.xpath): Add tracing mode to output empty-node-selection messages (#14939)

This commit is contained in:
Sven Rebhan 2024-03-06 16:46:10 +01:00 committed by GitHub
parent 9a9bb16c08
commit 7adc32efcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -135,6 +135,10 @@ XPath expressions.
## Currently, CBOR, protobuf, msgpack and JSON support native data-types.
# xpath_native_types = false
## Trace empty node selections for debugging
## This will only produce output in debugging mode.
# xpath_trace = false
## Multiple parsing sections are allowed
[[inputs.file.xpath]]
## Optional: XPath-query to select a subset of nodes from the XML document.

View File

@ -43,6 +43,7 @@ type Parser struct {
PrintDocument bool `toml:"xpath_print_document"`
AllowEmptySelection bool `toml:"xpath_allow_empty_selection"`
NativeTypes bool `toml:"xpath_native_types"`
Trace bool `toml:"xpath_trace"`
Configs []Config `toml:"xpath"`
DefaultMetricName string `toml:"-"`
DefaultTags map[string]string `toml:"-"`
@ -623,7 +624,7 @@ func (p *Parser) constructFieldName(root, node dataNode, name string, expand boo
}
func (p *Parser) debugEmptyQuery(operation string, root dataNode, initialquery string) {
if p.Log == nil {
if p.Log == nil || !p.Trace {
return
}