Skip to content

Commit

Permalink
Add query builder and integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Annanay <[email protected]>
  • Loading branch information
annanay25 committed Feb 3, 2020
1 parent 42b3f86 commit 5232c04
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 0 deletions.
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\\*"
}
}
}
]
}
}
}
}
]
}
}
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",
"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": []
}
]
}
]
}

0 comments on commit 5232c04

Please sign in to comment.