fix(parsers.xpath): Handle protobuf maps correctly (#13719)

This commit is contained in:
Sven Rebhan 2023-08-07 23:50:49 +02:00 committed by GitHub
parent 424283f138
commit 806b7cd67f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 70 additions and 9 deletions

View File

@ -112,7 +112,6 @@ following works:
- github.com/docker/docker [Apache License 2.0](https://github.com/docker/docker/blob/master/LICENSE) - github.com/docker/docker [Apache License 2.0](https://github.com/docker/docker/blob/master/LICENSE)
- github.com/docker/go-connections [Apache License 2.0](https://github.com/docker/go-connections/blob/master/LICENSE) - github.com/docker/go-connections [Apache License 2.0](https://github.com/docker/go-connections/blob/master/LICENSE)
- github.com/docker/go-units [Apache License 2.0](https://github.com/docker/go-units/blob/master/LICENSE) - github.com/docker/go-units [Apache License 2.0](https://github.com/docker/go-units/blob/master/LICENSE)
- github.com/doclambda/protobufquery [MIT License](https://github.com/doclambda/protobufquery/blob/master/LICENSE)
- github.com/dustin/go-humanize [MIT License](https://github.com/dustin/go-humanize/blob/master/LICENSE) - github.com/dustin/go-humanize [MIT License](https://github.com/dustin/go-humanize/blob/master/LICENSE)
- github.com/dvsekhvalnov/jose2go [MIT License](https://github.com/dvsekhvalnov/jose2go/blob/master/LICENSE) - github.com/dvsekhvalnov/jose2go [MIT License](https://github.com/dvsekhvalnov/jose2go/blob/master/LICENSE)
- github.com/dynatrace-oss/dynatrace-metric-utils-go [Apache License 2.0](https://github.com/dynatrace-oss/dynatrace-metric-utils-go/blob/master/LICENSE) - github.com/dynatrace-oss/dynatrace-metric-utils-go [Apache License 2.0](https://github.com/dynatrace-oss/dynatrace-metric-utils-go/blob/master/LICENSE)
@ -316,6 +315,7 @@ following works:
- github.com/spf13/cast [MIT License](https://github.com/spf13/cast/blob/master/LICENSE) - github.com/spf13/cast [MIT License](https://github.com/spf13/cast/blob/master/LICENSE)
- github.com/spf13/pflag [BSD 3-Clause "New" or "Revised" License](https://github.com/spf13/pflag/blob/master/LICENSE) - github.com/spf13/pflag [BSD 3-Clause "New" or "Revised" License](https://github.com/spf13/pflag/blob/master/LICENSE)
- github.com/srebhan/cborquery [MIT License](https://github.com/srebhan/cborquery/blob/main/LICENSE) - github.com/srebhan/cborquery [MIT License](https://github.com/srebhan/cborquery/blob/main/LICENSE)
- github.com/srebhan/protobufquery [MIT License](https://github.com/srebhan/protobufquery/blob/master/LICENSE)
- github.com/stoewer/go-strcase [MIT License](https://github.com/stoewer/go-strcase/blob/master/LICENSE) - github.com/stoewer/go-strcase [MIT License](https://github.com/stoewer/go-strcase/blob/master/LICENSE)
- github.com/stretchr/objx [MIT License](https://github.com/stretchr/objx/blob/master/LICENSE) - github.com/stretchr/objx [MIT License](https://github.com/stretchr/objx/blob/master/LICENSE)
- github.com/stretchr/testify [MIT License](https://github.com/stretchr/testify/blob/master/LICENSE) - github.com/stretchr/testify [MIT License](https://github.com/stretchr/testify/blob/master/LICENSE)

2
go.mod
View File

@ -66,7 +66,6 @@ require (
github.com/djherbis/times v1.5.0 github.com/djherbis/times v1.5.0
github.com/docker/docker v23.0.5+incompatible github.com/docker/docker v23.0.5+incompatible
github.com/docker/go-connections v0.4.0 github.com/docker/go-connections v0.4.0
github.com/doclambda/protobufquery v0.0.0-20220727165953-0da287796ee9
github.com/dynatrace-oss/dynatrace-metric-utils-go v0.5.0 github.com/dynatrace-oss/dynatrace-metric-utils-go v0.5.0
github.com/eclipse/paho.golang v0.11.0 github.com/eclipse/paho.golang v0.11.0
github.com/eclipse/paho.mqtt.golang v1.4.2 github.com/eclipse/paho.mqtt.golang v1.4.2
@ -167,6 +166,7 @@ require (
github.com/sleepinggenius2/gosmi v0.4.4 github.com/sleepinggenius2/gosmi v0.4.4
github.com/snowflakedb/gosnowflake v1.6.22 github.com/snowflakedb/gosnowflake v1.6.22
github.com/srebhan/cborquery v0.0.0-20230626165538-38be85b82316 github.com/srebhan/cborquery v0.0.0-20230626165538-38be85b82316
github.com/srebhan/protobufquery v0.0.0-20230803132024-ae4c0d878e55
github.com/stretchr/testify v1.8.4 github.com/stretchr/testify v1.8.4
github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62 github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62
github.com/testcontainers/testcontainers-go v0.21.0 github.com/testcontainers/testcontainers-go v0.21.0

5
go.sum
View File

@ -189,7 +189,6 @@ github.com/antchfx/jsonquery v1.3.3 h1:zjZpbnZhYng3uOAbIfdNq81A9mMEeuDJeYIpeKpZ4
github.com/antchfx/jsonquery v1.3.3/go.mod h1:1JG4DqRlRCHgVYDPY1ioYFAGSXGfWHzNgrbiGQHsWck= github.com/antchfx/jsonquery v1.3.3/go.mod h1:1JG4DqRlRCHgVYDPY1ioYFAGSXGfWHzNgrbiGQHsWck=
github.com/antchfx/xmlquery v1.3.17 h1:d0qWjPp/D+vtRw7ivCwT5ApH/3CkQU8JOeo3245PpTk= github.com/antchfx/xmlquery v1.3.17 h1:d0qWjPp/D+vtRw7ivCwT5ApH/3CkQU8JOeo3245PpTk=
github.com/antchfx/xmlquery v1.3.17/go.mod h1:Afkq4JIeXut75taLSuI31ISJ/zeq+3jG7TunF7noreA= github.com/antchfx/xmlquery v1.3.17/go.mod h1:Afkq4JIeXut75taLSuI31ISJ/zeq+3jG7TunF7noreA=
github.com/antchfx/xpath v1.1.7/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk=
github.com/antchfx/xpath v1.2.3/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs= github.com/antchfx/xpath v1.2.3/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
github.com/antchfx/xpath v1.2.4/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs= github.com/antchfx/xpath v1.2.4/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
github.com/antchfx/xpath v1.2.5-0.20230505064641-588960cceeac h1:Et7H7mEPWuivbFEXi3dWa8hobnvF380TS2mq7JmgjEI= github.com/antchfx/xpath v1.2.5-0.20230505064641-588960cceeac h1:Et7H7mEPWuivbFEXi3dWa8hobnvF380TS2mq7JmgjEI=
@ -468,8 +467,6 @@ github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5Xh
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/doclambda/protobufquery v0.0.0-20220727165953-0da287796ee9 h1:677nbAF3nq56BEZ2R/VMl0wROQqJo4vJ/ZWuzm+vsUU=
github.com/doclambda/protobufquery v0.0.0-20220727165953-0da287796ee9/go.mod h1:8Ia4zp86glrUhC29AAdK9hwTYh8RB6v0WRCtpplYqEg=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dropbox/godropbox v0.0.0-20180512210157-31879d3884b9 h1:NAvZb7gqQfLSNBPzVsvI7eZMosXtg2g2kxXrei90CtU= github.com/dropbox/godropbox v0.0.0-20180512210157-31879d3884b9 h1:NAvZb7gqQfLSNBPzVsvI7eZMosXtg2g2kxXrei90CtU=
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo= github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
@ -1416,6 +1413,8 @@ github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5q
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/srebhan/cborquery v0.0.0-20230626165538-38be85b82316 h1:HVv8JjpX24FuI59aET1uInn0ItuEiyj8CZMuR9Uw+lE= github.com/srebhan/cborquery v0.0.0-20230626165538-38be85b82316 h1:HVv8JjpX24FuI59aET1uInn0ItuEiyj8CZMuR9Uw+lE=
github.com/srebhan/cborquery v0.0.0-20230626165538-38be85b82316/go.mod h1:9vX3Dhehey14KFYwWo4K/4JOJRve6jvQf6R9Y8PymLI= github.com/srebhan/cborquery v0.0.0-20230626165538-38be85b82316/go.mod h1:9vX3Dhehey14KFYwWo4K/4JOJRve6jvQf6R9Y8PymLI=
github.com/srebhan/protobufquery v0.0.0-20230803132024-ae4c0d878e55 h1:ksmbrLbJAm+8yxB7fJ245usD0b1v9JHBJrWF+WqGyjs=
github.com/srebhan/protobufquery v0.0.0-20230803132024-ae4c0d878e55/go.mod h1:SIB3zq5pZq2Ff7aJtCdRpGiHc/meKyMLPEj8F5Tf1j8=
github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU= github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

View File

@ -12,8 +12,8 @@ import (
"github.com/antchfx/jsonquery" "github.com/antchfx/jsonquery"
path "github.com/antchfx/xpath" path "github.com/antchfx/xpath"
"github.com/doclambda/protobufquery"
"github.com/srebhan/cborquery" "github.com/srebhan/cborquery"
"github.com/srebhan/protobufquery"
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/filter" "github.com/influxdata/telegraf/filter"
@ -481,7 +481,6 @@ func (p *Parser) parseQuery(starttime time.Time, doc, selected dataNode, config
// Handle complex types which would be dropped otherwise for // Handle complex types which would be dropped otherwise for
// native type handling // native type handling
fmt.Printf("explicit field %q: %v (%T)\n", name, v, v)
if v != nil { if v != nil {
switch reflect.TypeOf(v).Kind() { switch reflect.TypeOf(v).Kind() {
case reflect.Array, reflect.Slice, reflect.Map: case reflect.Array, reflect.Slice, reflect.Map:

View File

@ -9,9 +9,9 @@ import (
"strings" "strings"
path "github.com/antchfx/xpath" path "github.com/antchfx/xpath"
"github.com/doclambda/protobufquery"
"github.com/jhump/protoreflect/desc" "github.com/jhump/protoreflect/desc"
"github.com/jhump/protoreflect/desc/protoparse" "github.com/jhump/protoreflect/desc/protoparse"
"github.com/srebhan/protobufquery"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protodesc" "google.golang.org/protobuf/reflect/protodesc"
"google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoreflect"
@ -138,7 +138,6 @@ func (d *protobufDocument) GetNodePath(node, relativeTo dataNode, sep string) st
if n.Parent != nil && n.Parent.Value() != nil { if n.Parent != nil && n.Parent.Value() != nil {
kind = reflect.TypeOf(n.Parent.Value()).Kind() kind = reflect.TypeOf(n.Parent.Value()).Kind()
} }
fmt.Printf("node %q: %v (value=%v) parent: %v\n", n.Data, kind, n.Value(), n.Parent.Value())
switch kind { switch kind {
case reflect.Slice, reflect.Array: case reflect.Slice, reflect.Array:
// Determine the index for array elements // Determine the index for array elements

View File

@ -0,0 +1 @@
dune,application=ERSStreamTest,session=TestPartition final_context_application_name="ERSStreamTest",final_context_cwd="/afs/cern.ch/user/r/riehecky",final_context_file_name="/tmp/root/spack-stage/spack-stage-erskafka-NB23-07-26-iao7bogflcsyozrhmzbnotd6gfqx6pye/spack-src/test/apps/protobuf_stream_test.cxx",final_context_function_name="int main(int, char**)",final_context_host_name="lxplus790.cern.ch",final_context_line_number=33u,final_context_package_name="unknown",final_context_process_id=31799u,final_context_thread_id=31799u,final_context_user_id=132836u,final_context_user_name="riehecky",final_inheritance_="ers::Issue",final_inheritance__1="erskafka::TestIssue",final_message="this is issue with ID: 14",final_name="erskafka::TestIssue",final_parameters_id="14",final_severity="4" 1690499167530000000

View File

@ -0,0 +1,38 @@
syntax = "proto3";
package dunedaq.ersschema;
message Context {
string cwd = 1;
string file_name = 2;
string function_name = 3;
string host_name = 4;
uint32 line_number = 5;
string package_name = 6;
uint32 process_id = 11;
uint32 thread_id = 12;
uint32 user_id = 13;
string user_name = 14;
string application_name = 15;
}
message SimpleIssue {
Context context = 1;
string name = 2;
repeated string inheritance = 3;
string message = 4;
string severity = 5;
uint64 time = 6;
map<string, string> parameters = 7;
}
message IssueChain {
SimpleIssue final = 1;
repeated SimpleIssue causes = 2;
string session = 10;
string application = 11;
string module = 12;
}

View File

@ -0,0 +1,6 @@
æ
þ
/afs/cern.ch/user/r/rieheckyƒ/tmp/root/spack-stage/spack-stage-erskafka-NB23-07-26-iao7bogflcsyozrhmzbnotd6gfqx6pye/spack-src/test/apps/protobuf_stream_test.cxxint main(int, char**)"lxplus790.cern.ch(!2unknownX·ø`·ø<68>rrieheckyz ERSStreamTesterskafka::TestIssue
ers::Issueerskafka::TestIssue"this is issue with ID: 14*40ªêèÌ™1:
id14R TestPartitionZ ERSStreamTest

View File

@ -0,0 +1,19 @@
[[inputs.file]]
files = ["./testcases/protobuf_issue_13715/message.bin"]
data_format = "xpath_protobuf"
xpath_native_types = true
xpath_protobuf_file = "issue.proto"
xpath_protobuf_type = "dunedaq.ersschema.IssueChain"
xpath_protobuf_import_paths = [".", "./testcases/protobuf_issue_13715"]
[[inputs.file.xpath]]
metric_name = "'dune'"
field_selection = "//final/descendant::*[not(*) and name() != 'time']"
field_name_expansion = true
timestamp = "//time"
timestamp_format = "unix_ms"
[inputs.file.xpath.tags]
application = "/application"
session = "/session"