Skip to content

Commit 469783f

Browse files
xiaochaoren1SongZhen0704
authored andcommitted
feat: querier remove auto ip columns
1 parent ae47abb commit 469783f

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

server/querier/engine/clickhouse/clickhouse_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ var (
139139
output: []string{"WITH toStartOfInterval(time, toIntervalSecond(60)) + toIntervalSecond(arrayJoin([0]) * 60) AS `_toi` SELECT toUnixTimestamp(`_toi`) AS `toi`, divide(plus(SUM(byte_tx+byte_rx), 100), 60) AS `persecond_max_byte_100` FROM flow_log.`l4_flow_log` GROUP BY `toi` LIMIT 1"},
140140
}, {
141141
input: "select auto_instance_0,ip_0 from l7_flow_log where ip_0='1.1.1.1' and auto_instance_0='abc' and auto_instance_0 regexp 'abc' and auto_instance_id_0=2 group by auto_instance_0,ip_0",
142-
output: []string{"WITH if(auto_instance_type_0 IN (0, 255), if(is_ipv4 = 1, ip4_0, NULL), NULL) AS `auto_instance_ip4_0`, if(auto_instance_type_0 IN (0, 255), if(is_ipv4 = 0, ip6_0, NULL), NULL) AS `auto_instance_ip6_0` SELECT if(auto_instance_type_0 in (0,255),if(is_ipv4=1, IPv4NumToString(auto_instance_ip4_0), IPv6NumToString(auto_instance_ip6_0)),dictGet('flow_tag.device_map', 'name', (toUInt64(auto_instance_type_0),toUInt64(auto_instance_id_0)))) AS `auto_instance_0`, auto_instance_ip4_0, auto_instance_ip6_0, auto_instance_type_0, if(is_ipv4=1, IPv4NumToString(ip4_0), IPv6NumToString(ip6_0)) AS `ip_0` FROM flow_log.`l7_flow_log` WHERE (((if(is_ipv4=1, ip4_0 = toIPv4OrNull('1.1.1.1'), ip6_0 = toIPv6OrNull('1.1.1.1'))))) AND (if(auto_instance_type_0 in (0,255),if(is_ipv4=1, IPv4NumToString(ip4_0), IPv6NumToString(ip6_0)) = 'abc',(toUInt64(auto_instance_id_0),toUInt64(auto_instance_type_0)) GLOBAL IN (SELECT deviceid,devicetype FROM flow_tag.device_map WHERE name = 'abc'))) AND (if(auto_instance_type_0 in (0,255),match(if(is_ipv4=1, IPv4NumToString(ip4_0), IPv6NumToString(ip6_0)),'abc'),(toUInt64(auto_instance_id_0),toUInt64(auto_instance_type_0)) GLOBAL IN (SELECT deviceid,devicetype FROM flow_tag.device_map WHERE match(name,'abc')))) AND (if(auto_instance_type_0 in (0,255),subnet_id_0 = 2,auto_instance_id_0 = 2)) GROUP BY `is_ipv4`, `auto_instance_ip4_0`, `auto_instance_ip6_0`, `auto_instance_type_0`, `auto_instance_id_0`, `ip4_0`, `ip6_0` LIMIT 10000"},
142+
output: []string{"WITH if(auto_instance_type_0 IN (0, 255), if(is_ipv4 = 1, ip4_0, NULL), NULL) AS `auto_instance_ip4_0`, if(auto_instance_type_0 IN (0, 255), if(is_ipv4 = 0, ip6_0, NULL), NULL) AS `auto_instance_ip6_0` SELECT if(auto_instance_type_0 in (0,255),if(is_ipv4=1, IPv4NumToString(auto_instance_ip4_0), IPv6NumToString(auto_instance_ip6_0)),dictGet('flow_tag.device_map', 'name', (toUInt64(auto_instance_type_0),toUInt64(auto_instance_id_0)))) AS `auto_instance_0`, auto_instance_type_0, if(is_ipv4=1, IPv4NumToString(ip4_0), IPv6NumToString(ip6_0)) AS `ip_0` FROM flow_log.`l7_flow_log` WHERE (((if(is_ipv4=1, ip4_0 = toIPv4OrNull('1.1.1.1'), ip6_0 = toIPv6OrNull('1.1.1.1'))))) AND (if(auto_instance_type_0 in (0,255),if(is_ipv4=1, IPv4NumToString(ip4_0), IPv6NumToString(ip6_0)) = 'abc',(toUInt64(auto_instance_id_0),toUInt64(auto_instance_type_0)) GLOBAL IN (SELECT deviceid,devicetype FROM flow_tag.device_map WHERE name = 'abc'))) AND (if(auto_instance_type_0 in (0,255),match(if(is_ipv4=1, IPv4NumToString(ip4_0), IPv6NumToString(ip6_0)),'abc'),(toUInt64(auto_instance_id_0),toUInt64(auto_instance_type_0)) GLOBAL IN (SELECT deviceid,devicetype FROM flow_tag.device_map WHERE match(name,'abc')))) AND (if(auto_instance_type_0 in (0,255),subnet_id_0 = 2,auto_instance_id_0 = 2)) GROUP BY `is_ipv4`, `auto_instance_ip4_0`, `auto_instance_ip6_0`, `auto_instance_type_0`, `auto_instance_id_0`, `ip4_0`, `ip6_0` LIMIT 10000"},
143143
}, {
144144
input: "select pod_service_0 from l7_flow_log where pod_service_0 !='xx' group by pod_service_0",
145145
output: []string{"SELECT dictGet('flow_tag.device_map', 'name', (toUInt64(11),toUInt64(service_id_0))) AS `pod_service_0` FROM flow_log.`l7_flow_log` WHERE (not(toUInt64(service_id_0) GLOBAL IN (SELECT deviceid FROM flow_tag.device_map WHERE name = 'xx' AND devicetype=11))) AND (service_id_0!=0) GROUP BY `service_id_0` LIMIT 10000"},

server/querier/engine/clickhouse/view/tag.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,17 @@ func (s *Tags) Append(t Node) {
5050
}
5151

5252
func (s *Tags) WriteTo(buf *bytes.Buffer) {
53-
for i, tag := range s.tags {
54-
tag.WriteTo(buf)
55-
if i < len(s.tags)-1 {
53+
first := true
54+
for _, tag := range s.tags {
55+
node, ok := tag.(*Tag)
56+
if ok && node.NoReturn {
57+
continue
58+
}
59+
if !first {
5660
buf.WriteString(", ")
5761
}
62+
tag.WriteTo(buf)
63+
first = false
5864
}
5965
}
6066

@@ -69,10 +75,11 @@ func (s *Tags) GetWiths() []Node {
6975
}
7076

7177
type Tag struct {
72-
Value string
73-
Alias string
74-
Flag int
75-
Withs []Node
78+
Value string
79+
Alias string
80+
Flag int
81+
Withs []Node
82+
NoReturn bool
7683
NodeBase
7784
}
7885

server/querier/engine/clickhouse/view/view.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ func (v *View) trans() {
209209
} else {
210210
metricTag.Value = node.Value
211211
}
212+
// remove auto ip tag
213+
if strings.HasPrefix(node.Value, "auto_instance_ip") || strings.HasPrefix(node.Value, "auto_service_ip") {
214+
metricTag.NoReturn = true
215+
}
212216
tagsLevelMetrics = append(tagsLevelMetrics, metricTag)
213217
tagsAliasInner = append(tagsAliasInner, metricTag.Value)
214218
} else if node.Flag == NODE_FLAG_METRICS_INNER {
@@ -281,8 +285,19 @@ func (v *View) trans() {
281285
if v.Model.MetricsLevelFlag == MODEL_METRICS_LEVEL_FLAG_UNLAY {
282286
// 计算层不拆层
283287
// 里层tag+外层metric
288+
// remove auto ip tag
289+
newTagsInner := []Node{}
290+
for _, tagInner := range tagsLevelInner {
291+
node, ok := tagInner.(*Tag)
292+
if ok {
293+
if strings.HasPrefix(node.Value, "auto_instance_ip") || strings.HasPrefix(node.Value, "auto_service_ip") {
294+
node.NoReturn = true
295+
}
296+
newTagsInner = append(newTagsInner, tagInner)
297+
}
298+
}
284299
sv := SubView{
285-
Tags: &Tags{tags: append(tagsLevelInner, metricsLevelMetrics...)},
300+
Tags: &Tags{tags: append(newTagsInner, metricsLevelMetrics...)},
286301
Groups: v.Model.Groups,
287302
From: v.Model.From,
288303
Filters: v.Model.Filters,

0 commit comments

Comments
 (0)