Skip to content

Commit 6e99ab7

Browse files
authored
Fix querying the index on a entity tag (#579)
* Fix querying the index on a entity tag Signed-off-by: Gao Hongtao <[email protected]> * Remove e2e
1 parent 3658400 commit 6e99ab7

37 files changed

+142
-504
lines changed

.github/workflows/e2e.storage.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ jobs:
4343
config: test/e2e-v2/cases/storage/banyandb/e2e.yaml
4444
- name: Trace Profiling BanyanDB
4545
config: test/e2e-v2/cases/profiling/trace/banyandb/e2e.yaml
46-
- name: eBPF Profiling BanyanDB
47-
config: test/e2e-v2/cases/profiling/ebpf/oncpu/banyandb/e2e.yaml
4846
- name: Event BanyanDB
4947
config: test/e2e-v2/cases/event/banyandb/e2e.yaml
5048
- name: BanyanDB Cluster Mode

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ target
5454
# mock files
5555
*mock.go
5656
*mock_test.go
57+
gomock_reflect*
5758

5859
# snky cache
5960
.dccache

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Release Notes.
4141
### Chores
4242

4343
- Fix metrics system typo.
44+
- Bump up OAP in CI to 6d262cce62e156bd197177abb3640ea65bb2d38e.
4445

4546
### CVEs
4647

api/proto/banyandb/measure/v1/rpc.proto

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,10 @@ service MeasureService {
3838
}
3939

4040
rpc Write(stream WriteRequest) returns (stream WriteResponse);
41-
rpc TopN(TopNRequest) returns (TopNResponse);
41+
rpc TopN(TopNRequest) returns (TopNResponse) {
42+
option (google.api.http) = {
43+
post: "/v1/measure/topn"
44+
body: "*"
45+
};
46+
}
4247
}

banyand/measure/measure.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@ type option struct {
5151

5252
type measure struct {
5353
databaseSupplier schema.Supplier
54+
indexTagMap map[string]struct{}
5455
l *logger.Logger
5556
schema *databasev1.Measure
5657
processorManager *topNProcessorManager
58+
fieldIndexLocation partition.FieldIndexLocation
5759
name string
5860
group string
59-
indexRules []*databasev1.IndexRule
6061
indexRuleLocators partition.IndexRuleLocator
61-
fieldIndexLocation partition.FieldIndexLocation
62+
indexRules []*databasev1.IndexRule
6263
topNAggregations []*databasev1.TopNAggregation
6364
interval time.Duration
6465
shardNum uint32
@@ -104,7 +105,12 @@ func (s *measure) parseSpec() (err error) {
104105
s.interval, err = timestamp.ParseDuration(s.schema.Interval)
105106
}
106107
s.indexRuleLocators, s.fieldIndexLocation = partition.ParseIndexRuleLocators(s.schema.GetEntity(), s.schema.GetTagFamilies(), s.indexRules, s.schema.IndexMode)
107-
108+
s.indexTagMap = make(map[string]struct{})
109+
for j := range s.indexRules {
110+
for k := range s.indexRules[j].Tags {
111+
s.indexTagMap[s.indexRules[j].Tags[k]] = struct{}{}
112+
}
113+
}
108114
return err
109115
}
110116

banyand/measure/write.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ func (w *writeCallback) appendEntityTagsToIndexFields(fields []index.Field, stm
284284
f.NoSort = true
285285
fields = append(fields, f)
286286
for i := range stm.schema.Entity.TagNames {
287+
if _, exists := stm.indexTagMap[stm.schema.Entity.TagNames[i]]; exists {
288+
continue
289+
}
287290
tagName := stm.schema.Entity.TagNames[i]
288291
var t *databasev1.TagSpec
289292
for j := range stm.schema.TagFamilies {

pkg/index/inverted/query.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ func buildIndexModeCriteria(criteria *modelv1.Criteria, schema logical.Schema, e
197197
if err != nil {
198198
return nil, err
199199
}
200-
if _, ok := entityDict[cond.Name]; ok {
201-
fk := index.FieldKey{TagName: index.IndexModeEntityTagPrefix + cond.Name}
202-
return parseConditionToQuery(cond, nil, expr, fk.Marshal())
203-
}
204200
if ok, indexRule := schema.IndexDefined(cond.Name); ok {
205201
fk := index.FieldKey{IndexRuleID: indexRule.Metadata.Id}
206202
return parseConditionToQuery(cond, indexRule, expr, fk.Marshal())
207203
}
204+
if _, ok := entityDict[cond.Name]; ok {
205+
fk := index.FieldKey{TagName: index.IndexModeEntityTagPrefix + cond.Name}
206+
return parseConditionToQuery(cond, nil, expr, fk.Marshal())
207+
}
208208
return nil, errors.Wrapf(logical.ErrUnsupportedConditionOp, "mandatory index rule conf:%s", cond)
209209
case *modelv1.Criteria_Le:
210210
le := criteria.GetLe()
@@ -301,6 +301,9 @@ func parseConditionToQuery(cond *modelv1.Condition, indexRule *databasev1.IndexR
301301
node := newTermNode(str, indexRule)
302302
return &queryNode{query, node}, nil
303303
case modelv1.Condition_BINARY_OP_MATCH:
304+
if indexRule == nil {
305+
return nil, errors.WithMessagef(logical.ErrUnsupportedConditionOp, "index rule is mandatory for match operation: %s", cond)
306+
}
304307
bb := expr.Bytes()
305308
if len(bb) != 1 {
306309
return nil, errors.WithMessagef(logical.ErrUnsupportedConditionOp, "don't support multiple or null value: %s", cond)

test/docker/base-compose.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ services:
6767
- 5005
6868
environment:
6969
SW_STORAGE_BANYANDB_TARGETS: banyandb:17912
70-
SW_CONFIG_ETCD_PERIOD: 1
71-
SW_CONFIG_ETCD_ENDPOINTS: http://etcd:2379
72-
SW_CLUSTER_ETCD_ENDPOINTS: http://etcd:2379
7370
healthcheck:
7471
test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/11800"]
7572
interval: 5s
@@ -98,6 +95,7 @@ services:
9895
SW_AGENT_INSTANCE_NAME: provider1
9996
SW_AGENT_COLLECTOR_GET_PROFILE_TASK_INTERVAL: 1
10097
SW_AGENT_COLLECTOR_GET_AGENT_DYNAMIC_CONFIG_INTERVAL: 1
98+
SW_METER_ACTIVE: 'false'
10199
healthcheck:
102100
test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/9090"]
103101
interval: 5s
@@ -120,6 +118,7 @@ services:
120118
SW_AGENT_INSTANCE_NAME: consumer1
121119
SW_AGENT_COLLECTOR_GET_PROFILE_TASK_INTERVAL: 1
122120
SW_AGENT_COLLECTOR_GET_AGENT_DYNAMIC_CONFIG_INTERVAL: 1
121+
SW_METER_ACTIVE: 'false'
123122
healthcheck:
124123
test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/9092"]
125124
interval: 5s

test/e2e-v2/cases/cluster/storage-cases.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,19 @@ cases:
160160
| yq e '.traces[0].traceids[0]' - \
161161
)
162162
expected: ../storage/expected/trace-users-detail.yml
163+
# topN-OP-service Global
164+
- query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression="top_n(service_sla,3,des)/100"
165+
expected: ../storage/expected/topN-OP-service.yml
166+
# topN-OP-service Global with attrs
167+
- query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression="top_n(service_sla,3,des,attr0='GENERAL')/100"
168+
expected: ../storage/expected/topN-OP-service.yml
169+
- query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression="top_n(service_sla,3,des,attr0!='Not_GENERAL')/100"
170+
expected: ../storage/expected/topN-OP-service.yml
171+
# topN-OP-endpoint Global
172+
- query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression="top_n(endpoint_sla,3,des)/100"
173+
expected: ../storage/expected/topN-OP-endpoint.yml
174+
# topN-OP-endpoint Global with attrs
175+
- query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression="top_n(endpoint_sla,3,des,attr0='GENERAL')/100"
176+
expected: ../storage/expected/topN-OP-endpoint.yml
177+
- query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics exec --expression="top_n(endpoint_sla,3,des,attr0!='Not_GENERAL')/100"
178+
expected: ../storage/expected/topN-OP-endpoint.yml

test/e2e-v2/cases/profiling/ebpf/oncpu/Dockerfile.sqrt

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/e2e-v2/cases/profiling/ebpf/oncpu/banyandb/docker-compose.yml

Lines changed: 0 additions & 58 deletions
This file was deleted.

test/e2e-v2/cases/profiling/ebpf/oncpu/banyandb/e2e.yaml

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/e2e-v2/cases/profiling/ebpf/oncpu/docker-compose.yml

Lines changed: 0 additions & 62 deletions
This file was deleted.

test/e2e-v2/cases/profiling/ebpf/oncpu/expected/process-estimate-scale.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)