Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support regex tags search for Elasticseach backend #2049

Merged
merged 8 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions plugin/storage/es/spanstore/fixtures/query_01.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
{
"bool":{
"must":{
"match":{
"regexp":{
"tag.bat@foo":{
"query":"spook"
"value":"spook"
}
}
}
Expand All @@ -15,9 +15,9 @@
{
"bool":{
"must":{
"match":{
"regexp":{
"process.tag.bat@foo":{
"query":"spook"
"value":"spook"
}
}
}
Expand All @@ -37,9 +37,9 @@
}
},
{
"match":{
"regexp":{
"tags.value":{
"query":"spook"
"value":"spook"
}
}
}
Expand All @@ -62,9 +62,9 @@
}
},
{
"match":{
"regexp":{
"process.tags.value":{
"query":"spook"
"value":"spook"
}
}
}
Expand All @@ -87,9 +87,9 @@
}
},
{
"match":{
"regexp":{
"logs.fields.value":{
"query":"spook"
"value":"spook"
}
}
}
Expand Down
103 changes: 103 additions & 0 deletions plugin/storage/es/spanstore/fixtures/query_02.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"bool":{
"should":[
{
"bool":{
"must":{
"regexp":{
"tag.bat@foo":{
"value":"spo.*"
}
}
}
}
},
{
"bool":{
"must":{
"regexp":{
"process.tag.bat@foo":{
"value":"spo.*"
}
}
}
}
},
{
"nested":{
"path":"tags",
"query":{
"bool":{
"must":[
{
"match":{
"tags.key":{
"query":"bat.foo"
}
}
},
{
"regexp":{
"tags.value":{
"value":"spo.*"
}
}
}
]
}
}
}
},
{
"nested":{
"path":"process.tags",
"query":{
"bool":{
"must":[
{
"match":{
"process.tags.key":{
"query":"bat.foo"
}
}
},
{
"regexp":{
"process.tags.value":{
"value":"spo.*"
}
}
}
]
}
}
}
},
{
"nested":{
"path":"logs.fields",
"query":{
"bool":{
"must":[
{
"match":{
"logs.fields.key":{
"query":"bat.foo"
}
}
},
{
"regexp":{
"logs.fields.value":{
"value":"spo.*"
}
}
}
]
}
}
}
}
]
}
}
103 changes: 103 additions & 0 deletions plugin/storage/es/spanstore/fixtures/query_03.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"bool":{
"should":[
{
"bool":{
"must":{
"regexp":{
"tag.bat@foo":{
"value":"spo\\*"
}
}
}
}
},
{
"bool":{
"must":{
"regexp":{
"process.tag.bat@foo":{
"value":"spo\\*"
}
}
}
}
},
{
"nested":{
"path":"tags",
"query":{
"bool":{
"must":[
{
"match":{
"tags.key":{
"query":"bat.foo"
}
}
},
{
"regexp":{
"tags.value":{
"value":"spo\\*"
}
}
}
]
}
}
}
},
{
"nested":{
"path":"process.tags",
"query":{
"bool":{
"must":[
{
"match":{
"process.tags.key":{
"query":"bat.foo"
}
}
},
{
"regexp":{
"process.tags.value":{
"value":"spo\\*"
}
}
}
]
}
}
}
},
{
"nested":{
"path":"logs.fields",
"query":{
"bool":{
"must":[
{
"match":{
"logs.fields.key":{
"query":"bat.foo"
}
}
},
{
"regexp":{
"logs.fields.value":{
"value":"spo\\*"
}
}
}
]
}
}
}
}
]
}
}
4 changes: 2 additions & 2 deletions plugin/storage/es/spanstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,14 +622,14 @@ func (s *SpanReader) buildNestedQuery(field string, k string, v string) elastic.
keyField := fmt.Sprintf("%s.%s", field, tagKeyField)
valueField := fmt.Sprintf("%s.%s", field, tagValueField)
keyQuery := elastic.NewMatchQuery(keyField, k)
valueQuery := elastic.NewMatchQuery(valueField, v)
valueQuery := elastic.NewRegexpQuery(valueField, v)
tagBoolQuery := elastic.NewBoolQuery().Must(keyQuery, valueQuery)
return elastic.NewNestedQuery(field, tagBoolQuery)
}

func (s *SpanReader) buildObjectQuery(field string, k string, v string) elastic.Query {
keyField := fmt.Sprintf("%s.%s", field, k)
keyQuery := elastic.NewMatchQuery(keyField, v)
keyQuery := elastic.NewRegexpQuery(keyField, v)
return elastic.NewBoolQuery().Must(keyQuery)
}

Expand Down
30 changes: 30 additions & 0 deletions plugin/storage/es/spanstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,36 @@ func TestSpanReader_buildTagQuery(t *testing.T) {
})
}

func TestSpanReader_buildTagRegexQuery(t *testing.T) {
inStr, err := ioutil.ReadFile("fixtures/query_02.json")
require.NoError(t, err)
withSpanReader(func(r *spanReaderTest) {
tagQuery := r.reader.buildTagQuery("bat.foo", "spo.*")
actual, err := tagQuery.Source()
require.NoError(t, err)

expected := make(map[string]interface{})
json.Unmarshal(inStr, &expected)

assert.EqualValues(t, expected, actual)
})
}

func TestSpanReader_buildTagRegexEscapedQuery(t *testing.T) {
inStr, err := ioutil.ReadFile("fixtures/query_03.json")
require.NoError(t, err)
withSpanReader(func(r *spanReaderTest) {
tagQuery := r.reader.buildTagQuery("bat.foo", "spo\\*")
actual, err := tagQuery.Source()
require.NoError(t, err)

expected := make(map[string]interface{})
json.Unmarshal(inStr, &expected)

assert.EqualValues(t, expected, actual)
})
}

func TestSpanReader_GetEmptyIndex(t *testing.T) {
withSpanReader(func(r *spanReaderTest) {
mockSearchService(r).
Expand Down
32 changes: 32 additions & 0 deletions plugin/storage/integration/fixtures/queries.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,5 +376,37 @@
"NumTraces": 1000
},
"ExpectedFixtures": ["multiple1_trace", "multiple2_trace", "multiple3_trace"]
},
{
"Caption": "Tag regex + Operation name + max Duration",
"Query": {
"ServiceName": "query23-service",
"OperationName": "query23-operation",
"Tags": {
"sameplacetag1":"random\\*"
},
"StartTimeMin": "2017-01-26T15:46:31.639875Z",
"StartTimeMax": "2017-01-26T17:46:31.639875Z",
"DurationMin": 0,
"DurationMax": 1000,
"NumTraces": 1000
},
"ExpectedFixtures": ["tags_regex_trace"]
},
{
"Caption": "Tag regex + Operation name + max Duration - Multiple traces",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pavolloffay - Also, in the integration test, the "Tag Name + Operation Name" query seems to match the tags_regex_trace.json as well, even though they search on a different ServiceName and tag value.

@annanay25 do you mean this one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the one above, "Tag regex + Operation name + max Duration"

It is supposed to match with just the tags_regex_trace but matches with both tags_regex_trace and tags_opname_trace .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one also looks wrong as it uses different service name https://github.com/jaegertracing/jaeger/blob/master/plugin/storage/integration/fixtures/traces/tags_opname_trace.json

Could you please debug it and or open an issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you fix the issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to mangle the traceID further -
0955efa#diff-1824d3ce6ce534210f34269d2370e966

"Query": {
"ServiceName": "query23-service",
"OperationName": "",
"Tags": {
"sameplacetag1":"same*"
},
"StartTimeMin": "2017-01-26T15:46:31.639875Z",
"StartTimeMax": "2017-01-26T17:46:31.639875Z",
"DurationMin": 0,
"DurationMax": 1000,
"NumTraces": 1000
},
"ExpectedFixtures": ["tags_opname_trace", "tags_regex_trace"]
}
]
33 changes: 33 additions & 0 deletions plugin/storage/integration/fixtures/traces/tags_regex_trace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"spans": [
{
"traceId": "AAAAAAAAAAAAAAAAAAAAEh==",
"spanId": "AAAAAAAAAAU=",
"operationName": "query23-operation",
"references": [],
"startTime": "2017-01-26T16:46:31.639875Z",
"duration": "1000ns",
"tags": [
{
"key": "sameplacetag1",
"vType": "STRING",
"vStr": "random*"
}
],
"process": {
"serviceName": "query23-service",
"tags": []
},
"logs": [
{
"timestamp": "2017-01-26T16:46:31.639875Z",
"fields": []
},
{
"timestamp": "2017-01-26T16:46:31.639875Z",
"fields": []
}
]
}
]
}