Skip to content

Commit

Permalink
[Tagrecorder] resource_map add team_id/domain_id
Browse files Browse the repository at this point in the history
 - run automation test(querier&*basic) pass
  • Loading branch information
Ericsssss authored and xiaochaoren1 committed Apr 25, 2024
1 parent f75d965 commit f669762
Show file tree
Hide file tree
Showing 30 changed files with 252 additions and 89 deletions.
17 changes: 11 additions & 6 deletions server/controller/tagrecorder/check/ch_az.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package tagrecorder

import (
"github.com/deepflowio/deepflow/server/controller/db/mysql"
"github.com/deepflowio/deepflow/server/controller/tagrecorder"
)

type ChAZ struct {
Expand Down Expand Up @@ -59,15 +60,19 @@ func (a *ChAZ) generateNewData() (map[IDKey]mysql.ChAZ, bool) {
}
if az.DeletedAt.Valid {
keyToItem[IDKey{ID: az.ID}] = mysql.ChAZ{
ID: az.ID,
Name: az.Name + " (deleted)",
IconID: iconID,
ID: az.ID,
Name: az.Name + " (deleted)",
IconID: iconID,
TeamID: tagrecorder.DomainToTeamID[az.Domain],
DomainID: tagrecorder.DomainToDomainID[az.Domain],
}
} else {
keyToItem[IDKey{ID: az.ID}] = mysql.ChAZ{
ID: az.ID,
Name: az.Name,
IconID: iconID,
ID: az.ID,
Name: az.Name,
IconID: iconID,
TeamID: tagrecorder.DomainToTeamID[az.Domain],
DomainID: tagrecorder.DomainToDomainID[az.Domain],
}
}

Expand Down
5 changes: 5 additions & 0 deletions server/controller/tagrecorder/check/ch_chost.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package tagrecorder

import (
"github.com/deepflowio/deepflow/server/controller/db/mysql"
"github.com/deepflowio/deepflow/server/controller/tagrecorder"
)

type ChChost struct {
Expand Down Expand Up @@ -65,6 +66,8 @@ func (p *ChChost) generateNewData() (map[IDKey]mysql.ChChost, bool) {
HostID: ipToHostID[chost.LaunchServer],
Hostname: chost.Hostname,
IP: chost.IP,
TeamID: tagrecorder.DomainToTeamID[chost.Domain],
DomainID: tagrecorder.DomainToDomainID[chost.Domain],
}
} else {
keyToItem[IDKey{ID: chost.ID}] = mysql.ChChost{
Expand All @@ -74,6 +77,8 @@ func (p *ChChost) generateNewData() (map[IDKey]mysql.ChChost, bool) {
HostID: ipToHostID[chost.LaunchServer],
Hostname: chost.Hostname,
IP: chost.IP,
TeamID: tagrecorder.DomainToTeamID[chost.Domain],
DomainID: tagrecorder.DomainToDomainID[chost.Domain],
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions server/controller/tagrecorder/check/ch_chost_cloud_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package tagrecorder

import (
"github.com/deepflowio/deepflow/server/controller/db/mysql"
"github.com/deepflowio/deepflow/server/controller/tagrecorder"
)

type ChChostCloudTag struct {
Expand Down Expand Up @@ -50,9 +51,11 @@ func (c *ChChostCloudTag) generateNewData() (map[CloudTagKey]mysql.ChChostCloudT
Key: k,
}
keyToItem[key] = mysql.ChChostCloudTag{
ID: vm.ID,
Key: k,
Value: v,
ID: vm.ID,
Key: k,
Value: v,
TeamID: tagrecorder.DomainToTeamID[vm.Domain],
DomainID: tagrecorder.DomainToDomainID[vm.Domain],
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions server/controller/tagrecorder/check/ch_chost_cloud_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"

"github.com/deepflowio/deepflow/server/controller/db/mysql"
"github.com/deepflowio/deepflow/server/controller/tagrecorder"
)

type ChChostCloudTags struct {
Expand Down Expand Up @@ -62,6 +63,8 @@ func (c *ChChostCloudTags) generateNewData() (map[CloudTagsKey]mysql.ChChostClou
keyToItem[key] = mysql.ChChostCloudTags{
ID: vm.ID,
CloudTags: string(cloudTagsStr),
TeamID: tagrecorder.DomainToTeamID[vm.Domain],
DomainID: tagrecorder.DomainToDomainID[vm.Domain],
}
}
}
Expand Down
55 changes: 55 additions & 0 deletions server/controller/tagrecorder/check/ch_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/deepflowio/deepflow/server/controller/common"
"github.com/deepflowio/deepflow/server/controller/db/mysql"
"github.com/deepflowio/deepflow/server/controller/db/mysql/query"
"github.com/deepflowio/deepflow/server/controller/tagrecorder"
)

type ChDevice struct {
Expand Down Expand Up @@ -143,6 +144,8 @@ func (d *ChDevice) generateHostData(keyToItem map[DeviceKey]mysql.ChDevice) bool
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_HOST, SubType: host.HType}],
Hostname: host.Hostname,
IP: host.IP,
TeamID: tagrecorder.DomainToTeamID[host.Domain],
DomainID: tagrecorder.DomainToDomainID[host.Domain],
}
} else {
keyToItem[key] = mysql.ChDevice{
Expand All @@ -152,6 +155,8 @@ func (d *ChDevice) generateHostData(keyToItem map[DeviceKey]mysql.ChDevice) bool
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_HOST, SubType: host.HType}],
Hostname: host.Hostname,
IP: host.IP,
TeamID: tagrecorder.DomainToTeamID[host.Domain],
DomainID: tagrecorder.DomainToDomainID[host.Domain],
}
}

Expand Down Expand Up @@ -182,6 +187,8 @@ func (d *ChDevice) generateVMData(keyToItem map[DeviceKey]mysql.ChDevice) bool {
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_VM, SubType: vm.HType}],
Hostname: vm.Hostname,
IP: vm.IP,
TeamID: tagrecorder.DomainToTeamID[vm.Domain],
DomainID: tagrecorder.DomainToDomainID[vm.Domain],
}
} else {
keyToItem[key] = mysql.ChDevice{
Expand All @@ -192,6 +199,8 @@ func (d *ChDevice) generateVMData(keyToItem map[DeviceKey]mysql.ChDevice) bool {
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_VM, SubType: vm.HType}],
Hostname: vm.Hostname,
IP: vm.IP,
TeamID: tagrecorder.DomainToTeamID[vm.Domain],
DomainID: tagrecorder.DomainToDomainID[vm.Domain],
}
}
}
Expand Down Expand Up @@ -220,6 +229,8 @@ func (d *ChDevice) generateVRouterData(keyToItem map[DeviceKey]mysql.ChDevice) b
DeviceID: vrouter.ID,
Name: vrouterName,
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_VGW}],
TeamID: tagrecorder.DomainToTeamID[vrouter.Domain],
DomainID: tagrecorder.DomainToDomainID[vrouter.Domain],
}
}
return true
Expand All @@ -245,13 +256,17 @@ func (d *ChDevice) generateDHCPPortData(keyToItem map[DeviceKey]mysql.ChDevice)
DeviceID: dhcpPort.ID,
Name: dhcpPort.Name + " (deleted)",
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_DHCP_PORT}],
TeamID: tagrecorder.DomainToTeamID[dhcpPort.Domain],
DomainID: tagrecorder.DomainToDomainID[dhcpPort.Domain],
}
} else {
keyToItem[key] = mysql.ChDevice{
DeviceType: common.VIF_DEVICE_TYPE_DHCP_PORT,
DeviceID: dhcpPort.ID,
Name: dhcpPort.Name,
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_DHCP_PORT}],
TeamID: tagrecorder.DomainToTeamID[dhcpPort.Domain],
DomainID: tagrecorder.DomainToDomainID[dhcpPort.Domain],
}
}
}
Expand Down Expand Up @@ -279,6 +294,8 @@ func (d *ChDevice) generateNATGatewayData(keyToItem map[DeviceKey]mysql.ChDevice
Name: natGateway.Name + " (deleted)",
UID: natGateway.UID,
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_NAT_GATEWAY}],
TeamID: tagrecorder.DomainToTeamID[natGateway.Domain],
DomainID: tagrecorder.DomainToDomainID[natGateway.Domain],
}
} else {
keyToItem[key] = mysql.ChDevice{
Expand All @@ -287,6 +304,8 @@ func (d *ChDevice) generateNATGatewayData(keyToItem map[DeviceKey]mysql.ChDevice
Name: natGateway.Name,
UID: natGateway.UID,
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_NAT_GATEWAY}],
TeamID: tagrecorder.DomainToTeamID[natGateway.Domain],
DomainID: tagrecorder.DomainToDomainID[natGateway.Domain],
}
}
}
Expand Down Expand Up @@ -314,6 +333,8 @@ func (d *ChDevice) generateLBData(keyToItem map[DeviceKey]mysql.ChDevice) bool {
Name: lb.Name + " (deleted)",
UID: lb.UID,
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_LB}],
TeamID: tagrecorder.DomainToTeamID[lb.Domain],
DomainID: tagrecorder.DomainToDomainID[lb.Domain],
}
} else {
keyToItem[key] = mysql.ChDevice{
Expand All @@ -322,6 +343,8 @@ func (d *ChDevice) generateLBData(keyToItem map[DeviceKey]mysql.ChDevice) bool {
Name: lb.Name,
UID: lb.UID,
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_LB}],
TeamID: tagrecorder.DomainToTeamID[lb.Domain],
DomainID: tagrecorder.DomainToDomainID[lb.Domain],
}
}
}
Expand Down Expand Up @@ -349,6 +372,8 @@ func (d *ChDevice) generateRDSInstanceData(keyToItem map[DeviceKey]mysql.ChDevic
Name: rdsInstance.Name + " (deleted)",
UID: rdsInstance.UID,
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_RDS}],
TeamID: tagrecorder.DomainToTeamID[rdsInstance.Domain],
DomainID: tagrecorder.DomainToDomainID[rdsInstance.Domain],
}
} else {
keyToItem[key] = mysql.ChDevice{
Expand All @@ -357,6 +382,8 @@ func (d *ChDevice) generateRDSInstanceData(keyToItem map[DeviceKey]mysql.ChDevic
Name: rdsInstance.Name,
UID: rdsInstance.UID,
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_RDS}],
TeamID: tagrecorder.DomainToTeamID[rdsInstance.Domain],
DomainID: tagrecorder.DomainToDomainID[rdsInstance.Domain],
}
}
}
Expand Down Expand Up @@ -384,6 +411,8 @@ func (d *ChDevice) generateRedisInstanceData(keyToItem map[DeviceKey]mysql.ChDev
Name: redisInstance.Name + " (deleted)",
UID: redisInstance.UID,
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_REDIS}],
TeamID: tagrecorder.DomainToTeamID[redisInstance.Domain],
DomainID: tagrecorder.DomainToDomainID[redisInstance.Domain],
}
} else {
keyToItem[key] = mysql.ChDevice{
Expand All @@ -392,6 +421,8 @@ func (d *ChDevice) generateRedisInstanceData(keyToItem map[DeviceKey]mysql.ChDev
Name: redisInstance.Name,
UID: redisInstance.UID,
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_REDIS}],
TeamID: tagrecorder.DomainToTeamID[redisInstance.Domain],
DomainID: tagrecorder.DomainToDomainID[redisInstance.Domain],
}
}
}
Expand All @@ -418,6 +449,8 @@ func (d *ChDevice) generatePodServiceData(keyToItem map[DeviceKey]mysql.ChDevice
DeviceID: podService.ID,
Name: podService.Name + " (deleted)",
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_POD_SERVICE}],
TeamID: tagrecorder.DomainToTeamID[podService.Domain],
DomainID: tagrecorder.DomainToDomainID[podService.Domain],
}

// service
Expand All @@ -430,6 +463,8 @@ func (d *ChDevice) generatePodServiceData(keyToItem map[DeviceKey]mysql.ChDevice
DeviceID: podService.ID,
Name: podService.Name + " (deleted)",
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_POD_SERVICE}],
TeamID: tagrecorder.DomainToTeamID[podService.Domain],
DomainID: tagrecorder.DomainToDomainID[podService.Domain],
}
} else {
// pod_service
Expand All @@ -442,6 +477,8 @@ func (d *ChDevice) generatePodServiceData(keyToItem map[DeviceKey]mysql.ChDevice
DeviceID: podService.ID,
Name: podService.Name,
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_POD_SERVICE}],
TeamID: tagrecorder.DomainToTeamID[podService.Domain],
DomainID: tagrecorder.DomainToDomainID[podService.Domain],
}

// service
Expand All @@ -454,6 +491,8 @@ func (d *ChDevice) generatePodServiceData(keyToItem map[DeviceKey]mysql.ChDevice
DeviceID: podService.ID,
Name: podService.Name,
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_POD_SERVICE}],
TeamID: tagrecorder.DomainToTeamID[podService.Domain],
DomainID: tagrecorder.DomainToDomainID[podService.Domain],
}
}
}
Expand All @@ -479,13 +518,17 @@ func (d *ChDevice) generatePodData(keyToItem map[DeviceKey]mysql.ChDevice) bool
DeviceID: pod.ID,
Name: pod.Name + " (deleted)",
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_POD}],
TeamID: tagrecorder.DomainToTeamID[pod.Domain],
DomainID: tagrecorder.DomainToDomainID[pod.Domain],
}
} else {
keyToItem[key] = mysql.ChDevice{
DeviceType: common.VIF_DEVICE_TYPE_POD,
DeviceID: pod.ID,
Name: pod.Name,
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_POD}],
TeamID: tagrecorder.DomainToTeamID[pod.Domain],
DomainID: tagrecorder.DomainToDomainID[pod.Domain],
}
}
}
Expand All @@ -511,13 +554,17 @@ func (d *ChDevice) generatePodGroupData(keyToItem map[DeviceKey]mysql.ChDevice)
DeviceID: podGroup.ID,
Name: podGroup.Name + " (deleted)",
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_POD_GROUP}],
TeamID: tagrecorder.DomainToTeamID[podGroup.Domain],
DomainID: tagrecorder.DomainToDomainID[podGroup.Domain],
}
} else {
keyToItem[key] = mysql.ChDevice{
DeviceType: RESOURCE_POD_GROUP_TYPE_MAP[podGroup.Type],
DeviceID: podGroup.ID,
Name: podGroup.Name,
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_POD_GROUP}],
TeamID: tagrecorder.DomainToTeamID[podGroup.Domain],
DomainID: tagrecorder.DomainToDomainID[podGroup.Domain],
}
}
}
Expand Down Expand Up @@ -545,6 +592,8 @@ func (d *ChDevice) generatePodNodeData(keyToItem map[DeviceKey]mysql.ChDevice) b
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_POD_NODE}],
Hostname: podNode.Hostname,
IP: podNode.IP,
TeamID: tagrecorder.DomainToTeamID[podNode.Domain],
DomainID: tagrecorder.DomainToDomainID[podNode.Domain],
}
} else {
keyToItem[key] = mysql.ChDevice{
Expand All @@ -554,6 +603,8 @@ func (d *ChDevice) generatePodNodeData(keyToItem map[DeviceKey]mysql.ChDevice) b
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_POD_NODE}],
Hostname: podNode.Hostname,
IP: podNode.IP,
TeamID: tagrecorder.DomainToTeamID[podNode.Domain],
DomainID: tagrecorder.DomainToDomainID[podNode.Domain],
}
}
}
Expand Down Expand Up @@ -602,13 +653,17 @@ func (d *ChDevice) generateProcessData(keyToItem map[DeviceKey]mysql.ChDevice) b
DeviceID: process.ID,
Name: process.Name + " (deleted)",
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_GPROCESS}],
TeamID: tagrecorder.DomainToTeamID[process.Domain],
DomainID: tagrecorder.DomainToDomainID[process.Domain],
}
} else {
keyToItem[key] = mysql.ChDevice{
DeviceType: CH_DEVICE_TYPE_GPROCESS,
DeviceID: process.ID,
Name: process.Name,
IconID: d.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_GPROCESS}],
TeamID: tagrecorder.DomainToTeamID[process.Domain],
DomainID: tagrecorder.DomainToDomainID[process.Domain],
}
}
}
Expand Down
25 changes: 15 additions & 10 deletions server/controller/tagrecorder/check/ch_gprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package tagrecorder
import (
"github.com/deepflowio/deepflow/server/controller/db/mysql"
"github.com/deepflowio/deepflow/server/controller/db/mysql/query"
"github.com/deepflowio/deepflow/server/controller/tagrecorder"
)

type ChGProcess struct {
Expand Down Expand Up @@ -48,19 +49,23 @@ func (p *ChGProcess) generateNewData() (map[IDKey]mysql.ChGProcess, bool) {
for _, process := range processes {
if process.DeletedAt.Valid {
keyToItem[IDKey{ID: process.ID}] = mysql.ChGProcess{
ID: process.ID,
Name: process.Name + " (deleted)",
IconID: p.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_GPROCESS}],
CHostID: process.VMID,
L3EPCID: process.VPCID,
ID: process.ID,
Name: process.Name + " (deleted)",
IconID: p.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_GPROCESS}],
CHostID: process.VMID,
L3EPCID: process.VPCID,
TeamID: tagrecorder.DomainToTeamID[process.Domain],
DomainID: tagrecorder.DomainToDomainID[process.Domain],
}
} else {
keyToItem[IDKey{ID: process.ID}] = mysql.ChGProcess{
ID: process.ID,
Name: process.Name,
IconID: p.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_GPROCESS}],
CHostID: process.VMID,
L3EPCID: process.VPCID,
ID: process.ID,
Name: process.Name,
IconID: p.resourceTypeToIconID[IconKey{NodeType: RESOURCE_TYPE_GPROCESS}],
CHostID: process.VMID,
L3EPCID: process.VPCID,
TeamID: tagrecorder.DomainToTeamID[process.Domain],
DomainID: tagrecorder.DomainToDomainID[process.Domain],
}
}
}
Expand Down
Loading

0 comments on commit f669762

Please sign in to comment.