This is an automated email from the ASF dual-hosted git repository. hanahmily pushed a commit to branch entity_match in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git
commit a5de178f008c76b904b3edde33b2f56947bae22b Author: Gao Hongtao <hanahm...@gmail.com> AuthorDate: Fri Sep 20 06:26:11 2024 +0000 Support matching entity tags Signed-off-by: Gao Hongtao <hanahm...@gmail.com> --- pkg/query/logical/parser.go | 2 +- .../index_rule_bindings/endpoint_traffic.json | 16 +++++ .../testdata/index_rules/endpoint_name.json | 13 ++++ .../testdata/measures/endpoint_traffic.json | 28 ++++++++ test/cases/init.go | 1 + test/cases/measure/data/input/entity_match.yaml | 41 ++++++++++++ .../measure/data/testdata/endpoint_traffic.json | 74 ++++++++++++++++++++++ test/cases/measure/data/want/entity_match.yaml | 40 ++++++++++++ test/cases/measure/measure.go | 1 + 9 files changed, 215 insertions(+), 1 deletion(-) diff --git a/pkg/query/logical/parser.go b/pkg/query/logical/parser.go index 68f8ad47..b4769e8c 100644 --- a/pkg/query/logical/parser.go +++ b/pkg/query/logical/parser.go @@ -28,7 +28,7 @@ import ( func ParseExprOrEntity(entityDict map[string]int, entity []*modelv1.TagValue, cond *modelv1.Condition) (LiteralExpr, [][]*modelv1.TagValue, error) { entityIdx, ok := entityDict[cond.Name] if ok && cond.Op != modelv1.Condition_BINARY_OP_EQ && cond.Op != modelv1.Condition_BINARY_OP_IN { - return nil, nil, errors.WithMessagef(ErrUnsupportedConditionOp, "tag belongs to the entity only supports EQ or IN operation in condition(%v)", cond) + ok = false } switch v := cond.Value.Value.(type) { case *modelv1.TagValue_Str: diff --git a/pkg/test/measure/testdata/index_rule_bindings/endpoint_traffic.json b/pkg/test/measure/testdata/index_rule_bindings/endpoint_traffic.json new file mode 100644 index 00000000..2633d4a5 --- /dev/null +++ b/pkg/test/measure/testdata/index_rule_bindings/endpoint_traffic.json @@ -0,0 +1,16 @@ +{ + "metadata": { + "name": "endpoint_traffic", + "group": "sw_metric" + }, + "rules": [ + "endpoint_name" + ], + "subject": { + "catalog": "CATALOG_MEASURE", + "name": "endpoint_traffic" + }, + "begin_at": "2021-04-15T01:30:15.01Z", + "expire_at": "2121-04-15T01:30:15.01Z", + "updated_at": "2021-04-15T01:30:15.01Z" +} \ No newline at end of file diff --git a/pkg/test/measure/testdata/index_rules/endpoint_name.json b/pkg/test/measure/testdata/index_rules/endpoint_name.json new file mode 100644 index 00000000..10738558 --- /dev/null +++ b/pkg/test/measure/testdata/index_rules/endpoint_name.json @@ -0,0 +1,13 @@ +{ + "metadata": { + "id": 5, + "name": "endpoint_name", + "group": "sw_metric" + }, + "tags": [ + "endpoint_name" + ], + "type": "TYPE_INVERTED", + "analyzer": "ANALYZER_SIMPLE", + "updated_at": "2021-04-15T01:30:15.01Z" +} \ No newline at end of file diff --git a/pkg/test/measure/testdata/measures/endpoint_traffic.json b/pkg/test/measure/testdata/measures/endpoint_traffic.json new file mode 100644 index 00000000..2c240557 --- /dev/null +++ b/pkg/test/measure/testdata/measures/endpoint_traffic.json @@ -0,0 +1,28 @@ +{ + "metadata": { + "name": "endpoint_traffic", + "group": "sw_metric" + }, + "tag_families": [ + { + "name": "default", + "tags": [ + { + "name": "service_id", + "type": "TAG_TYPE_STRING" + }, + { + "name": "endpoint_name", + "type": "TAG_TYPE_STRING" + } + ] + } + ], + "entity": { + "tag_names": [ + "service_id", + "endpoint_name" + ] + }, + "updated_at": "2024-04-15T01:30:15.01Z" +} \ No newline at end of file diff --git a/test/cases/init.go b/test/cases/init.go index 7341a96d..7f32b753 100644 --- a/test/cases/init.go +++ b/test/cases/init.go @@ -54,5 +54,6 @@ func Initialize(addr string, now time.Time) { casesmeasuredata.Write(conn, "service_latency_minute", "sw_metric", "service_latency_minute_data.json", now, interval) casesmeasuredata.Write(conn, "service_instance_latency_minute", "sw_metric", "service_instance_latency_minute_data.json", now, interval) casesmeasuredata.Write(conn, "service_instance_latency_minute", "sw_metric", "service_instance_latency_minute_data1.json", now.Add(1*time.Minute), interval) + casesmeasuredata.Write(conn, "endpoint_traffic", "sw_metric", "endpoint_traffic.json", now, interval) casesmeasuredata.Write(conn, "duplicated", "exception", "duplicated.json", now, 0) } diff --git a/test/cases/measure/data/input/entity_match.yaml b/test/cases/measure/data/input/entity_match.yaml new file mode 100644 index 00000000..28c14edc --- /dev/null +++ b/test/cases/measure/data/input/entity_match.yaml @@ -0,0 +1,41 @@ +# Licensed to Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Apache Software Foundation (ASF) licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +name: "endpoint_traffic" +groups: ["sw_metric"] +tagProjection: + tagFamilies: + - name: "default" + tags: ["service_id", "endpoint_name"] +criteria: + le: + op: "LOGICAL_OP_AND" + right: + condition: + name: "endpoint_name" + op: "BINARY_OP_MATCH" + value: + str: + value: "endpoint1" + left: + condition: + name: "service_id" + op: "BINARY_OP_EQ" + value: + str: + value: "service_1" + diff --git a/test/cases/measure/data/testdata/endpoint_traffic.json b/test/cases/measure/data/testdata/endpoint_traffic.json new file mode 100644 index 00000000..0a098c72 --- /dev/null +++ b/test/cases/measure/data/testdata/endpoint_traffic.json @@ -0,0 +1,74 @@ +[ + { + "tag_families": [ + { + "tags": [ + { + "str": { + "value": "service_1" + } + }, + { + "str": { + "value": "/api/v1/endpoint1" + } + } + ] + } + ] + }, + { + "tag_families": [ + { + "tags": [ + { + "str": { + "value": "service_1" + } + }, + { + "str": { + "value": "/api/v1/endpoint2" + } + } + ] + } + ] + }, + { + "tag_families": [ + { + "tags": [ + { + "str": { + "value": "service_2" + } + }, + { + "str": { + "value": "/api/v1/endpoint1" + } + } + ] + } + ] + }, + { + "tag_families": [ + { + "tags": [ + { + "str": { + "value": "service_2" + } + }, + { + "str": { + "value": "/api/v1/endpoint2" + } + } + ] + } + ] + } +] \ No newline at end of file diff --git a/test/cases/measure/data/want/entity_match.yaml b/test/cases/measure/data/want/entity_match.yaml new file mode 100644 index 00000000..73ba584e --- /dev/null +++ b/test/cases/measure/data/want/entity_match.yaml @@ -0,0 +1,40 @@ +# Licensed to Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Apache Software Foundation (ASF) licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +dataPoints: +- tagFamilies: + - name: default + tags: + - key: name + value: + str: + value: service_name_1 + - key: short_name + value: + str: + value: service_short_name_1 +- tagFamilies: + - name: default + tags: + - key: name + value: + str: + value: service_name_2 + - key: short_name + value: + str: + value: service_short_name_2 diff --git a/test/cases/measure/measure.go b/test/cases/measure/measure.go index 06b24498..53b6a6c7 100644 --- a/test/cases/measure/measure.go +++ b/test/cases/measure/measure.go @@ -71,4 +71,5 @@ var _ = g.DescribeTable("Scanning Measures", verify, g.Entry("float64 aggregation:min", helpers.Args{Input: "float_agg_min", Duration: 25 * time.Minute, Offset: -20 * time.Minute}), g.Entry("all_latency", helpers.Args{Input: "all_latency", Duration: 25 * time.Minute, Offset: -20 * time.Minute}), g.Entry("duplicated in a part", helpers.Args{Input: "duplicated_part", Duration: 25 * time.Minute, Offset: -20 * time.Minute}), + g.FEntry("match a tag belongs to the entity", helpers.Args{Input: "entity_match", Duration: 25 * time.Minute, Offset: -20 * time.Minute}), )