Skip to content

Commit f0e0b61

Browse files
committed
fix: tagrecoder corrects the value of gprocess
1 parent bd1a844 commit f0e0b61

File tree

22 files changed

+109
-2033
lines changed

22 files changed

+109
-2033
lines changed

server/controller/controller/master.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"github.com/deepflowio/deepflow/server/controller/prometheus"
3535
"github.com/deepflowio/deepflow/server/controller/recorder"
3636
"github.com/deepflowio/deepflow/server/controller/tagrecorder"
37-
tagrecordercheck "github.com/deepflowio/deepflow/server/controller/tagrecorder/check"
3837
)
3938

4039
func IsMasterRegion(cfg *config.ControllerConfig) bool {
@@ -101,8 +100,6 @@ func checkAndStartMasterFunctions(
101100
domainChecker := resoureservice.NewDomainCheck(ctx)
102101
prometheus := prometheus.GetSingleton()
103102
tagRecorder := tagrecorder.GetSingleton()
104-
tagrecordercheck.GetSingleton().Init(ctx, *cfg)
105-
tr := tagrecordercheck.GetSingleton()
106103
deletedORGChecker := service.GetDeletedORGChecker(ctx, cfg.FPermit)
107104

108105
httpService := http.GetSingleton()

server/controller/db/metadb/migrator/schema/const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ const (
2020
RAW_SQL_ROOT_DIR = "/etc/metadb/schema/rawsql"
2121

2222
DB_VERSION_TABLE = "db_version"
23-
DB_VERSION_EXPECTED = "7.0.1.23"
23+
DB_VERSION_EXPECTED = "7.0.1.24"
2424
)

server/controller/db/metadb/migrator/schema/rawsql/mysql/init.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,19 +2332,19 @@ CREATE TABLE IF NOT EXISTS ch_pod_ns_cloud_tags (
23322332
TRUNCATE TABLE ch_pod_ns_cloud_tags;
23332333

23342334
CREATE TABLE IF NOT EXISTS ch_os_app_tag (
2335-
`pid` INTEGER NOT NULL,
2335+
`id` INTEGER NOT NULL,
23362336
`key` VARCHAR(256) NOT NULL COLLATE utf8_bin,
23372337
`value` VARCHAR(256),
23382338
`team_id` INTEGER,
23392339
`domain_id` INTEGER,
23402340
`sub_domain_id` INTEGER,
23412341
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
2342-
PRIMARY KEY (`pid`, `key`)
2342+
PRIMARY KEY (`id`, `key`)
23432343
)ENGINE=innodb DEFAULT CHARSET=utf8;
23442344
TRUNCATE TABLE ch_os_app_tag;
23452345

23462346
CREATE TABLE IF NOT EXISTS ch_os_app_tags (
2347-
`pid` INTEGER NOT NULL PRIMARY KEY,
2347+
`id` INTEGER NOT NULL PRIMARY KEY,
23482348
`os_app_tags` TEXT,
23492349
`team_id` INTEGER,
23502350
`domain_id` INTEGER,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
DROP TABLE IF EXISTS ch_os_app_tag;
2+
DROP TABLE IF EXISTS ch_os_app_tags;
3+
4+
CREATE TABLE IF NOT EXISTS ch_os_app_tag (
5+
`id` INTEGER NOT NULL,
6+
`key` VARCHAR(256) NOT NULL COLLATE utf8_bin,
7+
`value` VARCHAR(256),
8+
`team_id` INTEGER,
9+
`domain_id` INTEGER,
10+
`sub_domain_id` INTEGER,
11+
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
12+
PRIMARY KEY (`id`, `key`)
13+
)ENGINE=innodb DEFAULT CHARSET=utf8;
14+
15+
CREATE TABLE IF NOT EXISTS ch_os_app_tags (
16+
`id` INTEGER NOT NULL PRIMARY KEY,
17+
`os_app_tags` TEXT,
18+
`team_id` INTEGER,
19+
`domain_id` INTEGER,
20+
`sub_domain_id` INTEGER,
21+
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
22+
)ENGINE=innodb DEFAULT CHARSET=utf8;
23+
24+
UPDATE db_version SET version='7.0.1.24';

server/controller/db/metadb/model/ch_model.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ func (ChPodNSCloudTags) TableName() string {
436436
}
437437

438438
type ChOSAppTag struct {
439+
ChIDBase `gorm:"embedded"`
439440
ChUpdatedAtBase `gorm:"embedded"`
440-
PID int `gorm:"primaryKey;column:pid;type:int;not null" json:"PID"`
441441
Key string `gorm:"primaryKey;column:key;type:varchar(256);default:null" json:"KEY"`
442442
Value string `gorm:"column:value;type:varchar(256);default:null" json:"VALUE"`
443443
TeamID int `gorm:"column:team_id;type:int;not null" json:"TEAM_ID"`
@@ -449,13 +449,9 @@ func (ChOSAppTag) TableName() string {
449449
return "ch_os_app_tag"
450450
}
451451

452-
func (c ChOSAppTag) GetID() int {
453-
return c.PID
454-
}
455-
456452
type ChOSAppTags struct {
453+
ChIDBase `gorm:"embedded"`
457454
ChUpdatedAtBase `gorm:"embedded"`
458-
PID int `gorm:"primaryKey;column:pid;type:int;not null" json:"PID"`
459455
OSAPPTags string `gorm:"column:os_app_tags;type:text;default:null" json:"OS_APP_TAGS"`
460456
TeamID int `gorm:"column:team_id;type:int;not null" json:"TEAM_ID"`
461457
DomainID int `gorm:"column:domain_id;type:int;not null" json:"DOMAIN_ID"`
@@ -466,10 +462,6 @@ func (ChOSAppTags) TableName() string {
466462
return "ch_os_app_tags"
467463
}
468464

469-
func (c ChOSAppTags) GetID() int {
470-
return c.PID
471-
}
472-
473465
type ChGProcess struct {
474466
ChIDBase `gorm:"embedded"`
475467
ChUpdatedAtBase `gorm:"embedded"`

server/controller/tagrecorder/ch_device.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package tagrecorder
1818

1919
import (
20+
"slices"
21+
2022
"gorm.io/gorm/clause"
2123

2224
"github.com/deepflowio/deepflow/server/controller/common"
@@ -26,10 +28,6 @@ import (
2628
"github.com/deepflowio/deepflow/server/controller/recorder/pubsub/message"
2729
)
2830

29-
const (
30-
syncTriggerKeyDeviceID = "deviceid"
31-
)
32-
3331
type ChVMDevice struct {
3432
SubscriberComponent[
3533
*message.VMAdd,
@@ -1206,6 +1204,7 @@ func NewChProcessDevice(resourceTypeToIconID map[IconKey]int) *ChProcessDevice {
12061204
resourceTypeToIconID,
12071205
}
12081206
mng.subscriberDG = mng
1207+
mng.hookers[hookerDeletePage] = mng
12091208
return mng
12101209
}
12111210

@@ -1218,12 +1217,12 @@ func (c *ChProcessDevice) sourceToTarget(md *message.Metadata, source *metadbmod
12181217
if source.DeletedAt.Valid {
12191218
sourceName += " (deleted)"
12201219
}
1221-
1220+
gid := int(source.GID)
12221221
keys = append(keys, DeviceKey{DeviceType: CH_DEVICE_TYPE_GPROCESS,
1223-
DeviceID: source.ID})
1222+
DeviceID: gid})
12241223
targets = append(targets, metadbmodel.ChDevice{
12251224
DeviceType: CH_DEVICE_TYPE_GPROCESS,
1226-
DeviceID: source.ID,
1225+
DeviceID: gid,
12271226
Name: sourceName,
12281227
IconID: iconID,
12291228
TeamID: md.TeamID,
@@ -1236,15 +1235,15 @@ func (c *ChProcessDevice) sourceToTarget(md *message.Metadata, source *metadbmod
12361235
// onResourceUpdated implements SubscriberDataGenerator
12371236
func (c *ChProcessDevice) onResourceUpdated(sourceID int, fieldsUpdate *message.ProcessFieldsUpdate, db *metadb.DB) {
12381237
updateInfo := make(map[string]interface{})
1239-
1238+
gid := int(fieldsUpdate.GID.GetNew())
12401239
if fieldsUpdate.Name.IsDifferent() {
12411240
updateInfo["name"] = fieldsUpdate.Name.GetNew()
12421241
}
12431242
if len(updateInfo) > 0 {
12441243
var chItem metadbmodel.ChDevice
1245-
db.Where("deviceid = ? and devicetype = ?", sourceID, CH_DEVICE_TYPE_GPROCESS).First(&chItem)
1244+
db.Where("deviceid = ? and devicetype = ?", gid, CH_DEVICE_TYPE_GPROCESS).First(&chItem)
12461245
c.SubscriberComponent.dbOperator.update(chItem, updateInfo, DeviceKey{DeviceType: CH_DEVICE_TYPE_GPROCESS,
1247-
DeviceID: sourceID}, db)
1246+
DeviceID: gid}, db)
12481247
}
12491248
}
12501249

@@ -1257,6 +1256,17 @@ func (c *ChProcessDevice) softDeletedTargetsUpdated(targets []metadbmodel.ChDevi
12571256
}).Create(&targets)
12581257
}
12591258

1259+
func (c *ChProcessDevice) beforeDeletePage(dbData []*metadbmodel.Process, msg *message.ProcessDelete) []*metadbmodel.Process {
1260+
gids := msg.GetAddition().(*message.ProcessDeleteAddition).DeletedGIDs
1261+
newDatas := []*metadbmodel.Process{}
1262+
for _, item := range dbData {
1263+
if slices.Contains(gids, item.GID) {
1264+
newDatas = append(newDatas, item)
1265+
}
1266+
}
1267+
return newDatas
1268+
}
1269+
12601270
type ChCustomServiceDevice struct {
12611271
SubscriberComponent[
12621272
*message.CustomServiceAdd,

server/controller/tagrecorder/ch_os_app_tag.go

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ import (
2323
"github.com/deepflowio/deepflow/server/controller/recorder/pubsub/message"
2424
)
2525

26-
const (
27-
syncTriggerKeyPID = "pid"
28-
)
29-
3026
type ChOSAppTag struct {
3127
SubscriberComponent[
3228
*message.ProcessAdd,
@@ -37,7 +33,7 @@ type ChOSAppTag struct {
3733
message.ProcessDelete,
3834
metadbmodel.Process,
3935
metadbmodel.ChOSAppTag,
40-
OSAPPTagKey,
36+
IDKeyKey,
4137
]
4238
}
4339

@@ -52,7 +48,7 @@ func NewChOSAppTag() *ChOSAppTag {
5248
message.ProcessDelete,
5349
metadbmodel.Process,
5450
metadbmodel.ChOSAppTag,
55-
OSAPPTagKey,
51+
IDKeyKey,
5652
](
5753
common.RESOURCE_TYPE_PROCESS_EN, RESOURCE_TYPE_CH_OS_APP_TAG,
5854
),
@@ -63,37 +59,37 @@ func NewChOSAppTag() *ChOSAppTag {
6359

6460
// onResourceUpdated implements SubscriberDataGenerator
6561
func (c *ChOSAppTag) onResourceUpdated(sourceID int, fieldsUpdate *message.ProcessFieldsUpdate, db *metadb.DB) {
66-
keysToAdd := make([]OSAPPTagKey, 0)
62+
keysToAdd := make([]IDKeyKey, 0)
6763
targetsToAdd := make([]metadbmodel.ChOSAppTag, 0)
68-
keysToDelete := make([]OSAPPTagKey, 0)
64+
keysToDelete := make([]IDKeyKey, 0)
6965
targetsToDelete := make([]metadbmodel.ChOSAppTag, 0)
70-
66+
gid := int(fieldsUpdate.GID.GetNew())
7167
if fieldsUpdate.OSAPPTags.IsDifferent() {
7268
_, new := common.StrToJsonAndMap(fieldsUpdate.OSAPPTags.GetNew())
7369
_, old := common.StrToJsonAndMap(fieldsUpdate.OSAPPTags.GetOld())
7470

7571
for k, v := range new {
7672
oldV, ok := old[k]
77-
targetKey := c.newTargetKey(sourceID, k)
73+
targetKey := NewIDKeyKey(gid, k)
7874
if !ok {
7975
keysToAdd = append(keysToAdd, targetKey)
8076
targetsToAdd = append(targetsToAdd, metadbmodel.ChOSAppTag{
81-
PID: sourceID,
82-
Key: k,
83-
Value: v,
77+
ChIDBase: metadbmodel.ChIDBase{ID: gid},
78+
Key: k,
79+
Value: v,
8480
})
8581
continue
8682
}
8783
updateInfo := make(map[string]interface{})
8884
if oldV != v {
8985
var chItem metadbmodel.ChOSAppTag
90-
db.Where("pid = ? and `key` = ?", sourceID, k).First(&chItem) // TODO common
91-
if chItem.PID == 0 {
86+
db.Where("id = ? and `key` = ?", gid, k).First(&chItem) // TODO common
87+
if chItem.ID == 0 {
9288
keysToAdd = append(keysToAdd, targetKey)
9389
targetsToAdd = append(targetsToAdd, metadbmodel.ChOSAppTag{
94-
PID: sourceID,
95-
Key: k,
96-
Value: v,
90+
ChIDBase: metadbmodel.ChIDBase{ID: gid},
91+
Key: k,
92+
Value: v,
9793
})
9894
continue
9995
}
@@ -103,10 +99,10 @@ func (c *ChOSAppTag) onResourceUpdated(sourceID int, fieldsUpdate *message.Proce
10399
}
104100
for k := range old {
105101
if _, ok := new[k]; !ok {
106-
keysToDelete = append(keysToDelete, c.newTargetKey(sourceID, k))
102+
keysToDelete = append(keysToDelete, NewIDKeyKey(gid, k))
107103
targetsToDelete = append(targetsToDelete, metadbmodel.ChOSAppTag{
108-
PID: sourceID,
109-
Key: k,
104+
ChIDBase: metadbmodel.ChIDBase{ID: gid},
105+
Key: k,
110106
})
111107
}
112108
}
@@ -120,13 +116,13 @@ func (c *ChOSAppTag) onResourceUpdated(sourceID int, fieldsUpdate *message.Proce
120116
}
121117

122118
// onResourceUpdated implements SubscriberDataGenerator
123-
func (c *ChOSAppTag) sourceToTarget(md *message.Metadata, source *metadbmodel.Process) (keys []OSAPPTagKey, targets []metadbmodel.ChOSAppTag) {
119+
func (c *ChOSAppTag) sourceToTarget(md *message.Metadata, source *metadbmodel.Process) (keys []IDKeyKey, targets []metadbmodel.ChOSAppTag) {
124120
_, osAppTagsMap := common.StrToJsonAndMap(source.OSAPPTags)
125-
121+
gid := int(source.GID)
126122
for k, v := range osAppTagsMap {
127-
keys = append(keys, c.newTargetKey(source.ID, k))
123+
keys = append(keys, NewIDKeyKey(gid, k))
128124
targets = append(targets, metadbmodel.ChOSAppTag{
129-
PID: source.ID,
125+
ChIDBase: metadbmodel.ChIDBase{ID: gid},
130126
Key: k,
131127
Value: v,
132128
TeamID: md.TeamID,
@@ -137,10 +133,6 @@ func (c *ChOSAppTag) sourceToTarget(md *message.Metadata, source *metadbmodel.Pr
137133
return
138134
}
139135

140-
func (c *ChOSAppTag) newTargetKey(sourceID int, key string) OSAPPTagKey {
141-
return OSAPPTagKey{PID: sourceID, Key: key}
142-
}
143-
144136
// softDeletedTargetsUpdated implements SubscriberDataGenerator
145137
func (c *ChOSAppTag) softDeletedTargetsUpdated(targets []metadbmodel.ChOSAppTag, db *metadb.DB) {
146138

server/controller/tagrecorder/ch_os_app_tags.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package tagrecorder
1818

1919
import (
20+
"slices"
21+
2022
"github.com/deepflowio/deepflow/server/controller/common"
2123
"github.com/deepflowio/deepflow/server/controller/db/metadb"
2224
metadbmodel "github.com/deepflowio/deepflow/server/controller/db/metadb/model"
@@ -33,7 +35,7 @@ type ChOSAppTags struct {
3335
message.ProcessDelete,
3436
metadbmodel.Process,
3537
metadbmodel.ChOSAppTags,
36-
OSAPPTagsKey,
38+
IDKey,
3739
]
3840
}
3941

@@ -48,12 +50,13 @@ func NewChOSAppTags() *ChOSAppTags {
4850
message.ProcessDelete,
4951
metadbmodel.Process,
5052
metadbmodel.ChOSAppTags,
51-
OSAPPTagsKey,
53+
IDKey,
5254
](
5355
common.RESOURCE_TYPE_PROCESS_EN, RESOURCE_TYPE_CH_OS_APP_TAGS,
5456
),
5557
}
5658
mng.subscriberDG = mng
59+
mng.hookers[hookerDeletePage] = mng
5760
return mng
5861
}
5962

@@ -67,14 +70,15 @@ func (c *ChOSAppTags) onResourceUpdated(sourceID int, fieldsUpdate *message.Proc
6770
updateInfo["os_app_tags"] = osAppTags
6871
}
6972
}
70-
targetKey := OSAPPTagsKey{PID: sourceID}
73+
gid := int(fieldsUpdate.GID.GetNew())
74+
targetKey := IDKey{ID: gid}
7175
if len(updateInfo) > 0 {
7276
var chItem metadbmodel.ChOSAppTags
73-
db.Where("pid = ?", sourceID).First(&chItem)
74-
if chItem.PID == 0 {
77+
db.Where("id = ?", gid).First(&chItem)
78+
if chItem.ID == 0 {
7579
c.SubscriberComponent.dbOperator.add(
76-
[]OSAPPTagsKey{targetKey},
77-
[]metadbmodel.ChOSAppTags{{PID: sourceID, OSAPPTags: updateInfo["os_app_tags"].(string)}},
80+
[]IDKey{targetKey},
81+
[]metadbmodel.ChOSAppTags{{ChIDBase: metadbmodel.ChIDBase{ID: gid}, OSAPPTags: updateInfo["os_app_tags"].(string)}},
7882
db,
7983
)
8084
}
@@ -83,13 +87,14 @@ func (c *ChOSAppTags) onResourceUpdated(sourceID int, fieldsUpdate *message.Proc
8387
}
8488

8589
// onResourceUpdated implements SubscriberDataGenerator
86-
func (c *ChOSAppTags) sourceToTarget(md *message.Metadata, source *metadbmodel.Process) (keys []OSAPPTagsKey, targets []metadbmodel.ChOSAppTags) {
90+
func (c *ChOSAppTags) sourceToTarget(md *message.Metadata, source *metadbmodel.Process) (keys []IDKey, targets []metadbmodel.ChOSAppTags) {
8791
if source.OSAPPTags == "" {
8892
return
8993
}
94+
gid := int(source.GID)
9095
osAppTags, _ := common.StrToJsonAndMap(source.OSAPPTags)
91-
return []OSAPPTagsKey{{PID: source.ID}}, []metadbmodel.ChOSAppTags{{
92-
PID: source.ID,
96+
return []IDKey{{ID: gid}}, []metadbmodel.ChOSAppTags{{
97+
ChIDBase: metadbmodel.ChIDBase{ID: gid},
9398
OSAPPTags: osAppTags,
9499
TeamID: md.TeamID,
95100
DomainID: md.DomainID,
@@ -101,3 +106,14 @@ func (c *ChOSAppTags) sourceToTarget(md *message.Metadata, source *metadbmodel.P
101106
func (c *ChOSAppTags) softDeletedTargetsUpdated(targets []metadbmodel.ChOSAppTags, db *metadb.DB) {
102107

103108
}
109+
110+
func (c *ChOSAppTags) beforeDeletePage(dbData []*metadbmodel.Process, msg *message.ProcessDelete) []*metadbmodel.Process {
111+
gids := msg.GetAddition().(*message.ProcessDeleteAddition).DeletedGIDs
112+
newDatas := []*metadbmodel.Process{}
113+
for _, item := range dbData {
114+
if slices.Contains(gids, item.GID) {
115+
newDatas = append(newDatas, item)
116+
}
117+
}
118+
return newDatas
119+
}

0 commit comments

Comments
 (0)