Skip to content

Commit 47ea587

Browse files
committed
feat: querier auto_instance supports pod_group
1 parent e9fa03a commit 47ea587

6 files changed

Lines changed: 57 additions & 36 deletions

File tree

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
# Value , DisplayName , Description
2-
0 , Internet IP ,
3-
1 , 云主机 ,
4-
5 , 路由器 ,
5-
6 , 宿主机 ,
6-
9 , DHCP 网关 ,
7-
10 , 容器 POD ,
8-
11 , 容器服务 ,
9-
12 , Redis ,
10-
13 , RDS ,
11-
14 , 容器节点 ,
12-
15 , 负载均衡器 ,
13-
16 , NAT 网关 ,
14-
120 , 进程 ,
15-
255 , IP ,
1+
# Value , DisplayName , Description
2+
0 , Internet IP ,
3+
1 , 云主机 ,
4+
5 , 路由器 ,
5+
6 , 宿主机 ,
6+
9 , DHCP 网关 ,
7+
10 , 容器 POD ,
8+
11 , 容器服务 ,
9+
12 , Redis ,
10+
13 , RDS ,
11+
14 , 容器节点 ,
12+
15 , 负载均衡器 ,
13+
16 , NAT 网关 ,
14+
101 , 工作负载 ,
15+
120 , 进程 ,
16+
130 , Deployment ,
17+
131 , StatefulSet ,
18+
132 , ReplicationController ,
19+
133 , DaemonSet ,
20+
134 , ReplicaSetController ,
21+
135 , CloneSet ,
22+
255 , IP ,
Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
# Value , DisplayName , Description
2-
0 , Internet IP ,
3-
1 , Cloud Host ,
4-
5 , Router ,
5-
6 , VM Hypervisor ,
6-
9 , DHCP Gateway ,
7-
10 , K8s POD ,
8-
11 , K8s Service ,
9-
12 , Redis ,
10-
13 , RDS ,
11-
14 , K8s Node ,
12-
15 , Load Balancer ,
13-
16 , NAT Gateway ,
14-
120 , Process ,
15-
255 , IP ,
1+
# Value , DisplayName , Description
2+
0 , Internet IP ,
3+
1 , Cloud Host ,
4+
5 , Router ,
5+
6 , VM Hypervisor ,
6+
9 , DHCP Gateway ,
7+
10 , K8s POD ,
8+
11 , K8s Service ,
9+
12 , Redis ,
10+
13 , RDS ,
11+
14 , K8s Node ,
12+
15 , Load Balancer ,
13+
16 , NAT Gateway ,
14+
101 , K8s Workload ,
15+
120 , Process ,
16+
130 , Deployment ,
17+
131 , StatefulSet ,
18+
132 , ReplicationController ,
19+
133 , DaemonSet ,
20+
134 , ReplicaSetController ,
21+
135 , CloneSet ,
22+
255 , IP ,

server/querier/engine/clickhouse/clickhouse_test.go

Lines changed: 3 additions & 3 deletions
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 resource_gl0_0,ip_0 from l7_flow_log where ip_0='1.1.1.1' and resource_gl0_0='abc' and resource_gl0_0 regexp 'abc' and resource_gl0_id_0=2 group by resource_gl0_0,ip_0",
142-
output: []string{"SELECT if(auto_instance_type_0 in (0,255),if(is_ipv4=1, IPv4NumToString(ip4_0), IPv6NumToString(ip6_0)),dictGet('flow_tag.device_map', 'name', (toUInt64(auto_instance_type_0),toUInt64(auto_instance_id_0)))) AS `resource_gl0_0`, if(is_ipv4=1, IPv4NumToString(ip4_0), IPv6NumToString(ip6_0)) AS `ip_0`, auto_instance_type_0 AS `resource_gl0_type_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 devicetype not in (101,102)))) 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 devicetype not in (101,102)))) AND (if(auto_instance_type_0 in (0,255),subnet_id_0 = 2,auto_instance_id_0 = 2)) GROUP BY if(auto_instance_type_0 in (0,255),if(is_ipv4=1, IPv4NumToString(ip4_0), IPv6NumToString(ip6_0)),dictGet('flow_tag.device_map', 'name', (toUInt64(auto_instance_type_0),toUInt64(auto_instance_id_0)))) AS `resource_gl0_0`, `resource_gl0_type_0`, if(is_ipv4=1, IPv4NumToString(ip4_0), IPv6NumToString(ip6_0)) AS `ip_0` LIMIT 10000"},
142+
output: []string{"SELECT if(auto_instance_type_0 in (0,255),if(is_ipv4=1, IPv4NumToString(ip4_0), IPv6NumToString(ip6_0)),dictGet('flow_tag.device_map', 'name', (toUInt64(auto_instance_type_0),toUInt64(auto_instance_id_0)))) AS `resource_gl0_0`, if(is_ipv4=1, IPv4NumToString(ip4_0), IPv6NumToString(ip6_0)) AS `ip_0`, auto_instance_type_0 AS `resource_gl0_type_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 devicetype not in (102)))) 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 devicetype not in (102)))) AND (if(auto_instance_type_0 in (0,255),subnet_id_0 = 2,auto_instance_id_0 = 2)) GROUP BY if(auto_instance_type_0 in (0,255),if(is_ipv4=1, IPv4NumToString(ip4_0), IPv6NumToString(ip6_0)),dictGet('flow_tag.device_map', 'name', (toUInt64(auto_instance_type_0),toUInt64(auto_instance_id_0)))) AS `resource_gl0_0`, `resource_gl0_type_0`, if(is_ipv4=1, IPv4NumToString(ip4_0), IPv6NumToString(ip6_0)) AS `ip_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))) GROUP BY dictGet('flow_tag.device_map', 'name', (toUInt64(11),toUInt64(service_id_0))) AS `pod_service_0` LIMIT 10000"},
@@ -449,11 +449,11 @@ var (
449449
}, {
450450
name: "exist_trans_support_tag_0",
451451
input: "SELECT pod from l4_flow_log WHERE exist(pod_0) AND exist(host_1) AND exist(vpc_0) AND exist(auto_instance_1) AND exist(auto_service_0) LIMIT 1",
452-
output: []string{"SELECT dictGet('flow_tag.pod_map', 'name', (toUInt64(pod_id))) AS `pod` FROM flow_log.`l4_flow_log` WHERE (pod_id_0!=0) AND (host_id_1!=0) AND (l3_epc_id_0!=-2) AND (auto_instance_type_1 not in (101,102)) AND (auto_service_type_0 not in (10)) LIMIT 1"},
452+
output: []string{"SELECT dictGet('flow_tag.pod_map', 'name', (toUInt64(pod_id))) AS `pod` FROM flow_log.`l4_flow_log` WHERE (pod_id_0!=0) AND (host_id_1!=0) AND (l3_epc_id_0!=-2) AND (auto_instance_type_1 not in (102)) AND (auto_service_type_0 not in (10)) LIMIT 1"},
453453
}, {
454454
name: "exist_trans_support_tag_1",
455455
input: "SELECT pod from vtap_app_port WHERE exist(resource_gl0) AND exist(resource_gl1) LIMIT 1",
456-
output: []string{"SELECT dictGet('flow_tag.pod_map', 'name', (toUInt64(pod_id))) AS `pod` FROM flow_metrics.`application` WHERE (auto_instance_type not in (101,102)) AND (auto_service_type not in (10)) LIMIT 1"},
456+
output: []string{"SELECT dictGet('flow_tag.pod_map', 'name', (toUInt64(pod_id))) AS `pod` FROM flow_metrics.`application` WHERE (auto_instance_type not in (102)) AND (auto_service_type not in (10)) LIMIT 1"},
457457
db: "flow_metrics",
458458
}, {
459459
name: "l2_vpc_filter_trans",

server/querier/engine/clickhouse/filter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TransWhereTagFunction(db, table string, name string, args []string) (filter
131131
filter = strings.Join([]string{"epc_id", suffix, "!=0"}, "")
132132
} else if common.IsValueInSliceString(resourceNoID, tag.TAG_RESOURCE_TYPE_AUTO) {
133133
if common.IsValueInSliceString(resourceNoID, []string{"resource_gl0", "auto_instance"}) {
134-
filter = strings.Join([]string{"auto_instance_type", suffix, " not in (101,102)"}, "")
134+
filter = strings.Join([]string{"auto_instance_type", suffix, " not in (102)"}, "")
135135
} else {
136136
filter = strings.Join([]string{"auto_service_type", suffix, " not in (10)"}, "")
137137
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ var AutoMap = map[string]int{
7070
}
7171

7272
var AutoPodMap = map[string]int{
73-
"pod": VIF_DEVICE_TYPE_POD,
73+
"pod": VIF_DEVICE_TYPE_POD,
74+
"pod_group": VIF_DEVICE_TYPE_POD_GROUP,
75+
"deployment": VIF_DEVICE_TYPE_POD_GROUP_DEPLOYMENT,
76+
"stateful_set": VIF_DEVICE_TYPE_POD_GROUP_STATEFULSET,
77+
"replication_controller": VIF_DEVICE_TYPE_POD_GROUP_RC,
78+
"daemon_set": VIF_DEVICE_TYPE_POD_GROUP_DAEMON_SET,
79+
"replica_set_controller": VIF_DEVICE_TYPE_POD_GROUP_REPLICASET_CONTROLLER,
80+
"clone_set": VIF_DEVICE_TYPE_POD_GROUP_CLONESET,
7481
}
7582

7683
var AutoPodGroupMap = map[string]int{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ func GenerateTagResoureMap() map[string]map[string]*Tag {
401401
iconIDStrSuffix := fmt.Sprintf("multiIf(%s=%d,%s,%s=%d,%s,%s)", tagAutoTypeSuffix, VIF_DEVICE_TYPE_INTERNET, internetIconDictGet, tagAutoTypeSuffix, VIF_DEVICE_TYPE_IP, ipIconDictGet, autoIconDictGet)
402402
deviceTypeFilter := ""
403403
if strings.HasPrefix(autoNameSuffix, "resource_gl0") || strings.HasPrefix(autoNameSuffix, "auto_instance") {
404-
deviceTypeFilter = "devicetype not in (101,102)"
404+
deviceTypeFilter = "devicetype not in (102)"
405405
} else {
406406
deviceTypeFilter = "devicetype not in (10)"
407407
}

0 commit comments

Comments
 (0)