Skip to content

Commit b86c11d

Browse files
xiaochaoren1ZhengYa-0110
authored andcommitted
fix: optimize tagrecorder update
1 parent 7cab121 commit b86c11d

30 files changed

Lines changed: 19 additions & 941 deletions

server/controller/db/metadb/migrator/schema/rawsql/mysql/issu/7.1.0.3.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ BEGIN
66

77
SELECT COUNT(*) INTO existing_display_name
88
FROM data_source
9-
WHERE id = 25;
9+
WHERE display_name = '应用-性能剖析指标';
1010

1111
IF existing_display_name = 0 THEN
1212
START TRANSACTION;
1313
set @lcuuid = (select uuid());
14-
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, summable_metrics_operator, unsummable_metrics_operator, lcuuid)
15-
VALUES (25, '应用-性能剖析指标', 'profile.in_process_metrics', 1, 3*24, 'Sum', 'Avg', @lcuuid);
14+
INSERT INTO data_source (display_name, data_table_collection, `interval_time`, retention_time, summable_metrics_operator, unsummable_metrics_operator, lcuuid)
15+
VALUES ('应用-性能剖析指标', 'profile.in_process_metrics', 1, 3*24, 'Sum', 'Avg', @lcuuid);
1616
COMMIT;
1717
END IF;
1818

server/controller/tagrecorder/ch_az.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,6 @@ func NewChAZ(domainLcuuidToIconID map[string]int, resourceTypeToIconID map[IconK
6666

6767
// onResourceUpdated implements SubscriberDataGenerator
6868
func (a *ChAZ) onResourceUpdated(md *message.Metadata, updateMessage *message.UpdatedAZ) {
69-
db := md.GetDB()
70-
fieldsUpdate := updateMessage.GetFields().(*message.UpdatedAZFields)
71-
newSource := updateMessage.GetNewMetadbItem().(*metadbmodel.AZ)
72-
sourceID := newSource.ID
73-
updateInfo := make(map[string]interface{})
74-
if fieldsUpdate.Name.IsDifferent() {
75-
updateInfo["name"] = fieldsUpdate.Name.GetNew()
76-
}
77-
a.updateOrSync(db, IDKey{ID: sourceID}, updateInfo)
7869
}
7970

8071
// onResourceUpdated implements SubscriberDataGenerator

server/controller/tagrecorder/ch_chost.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -84,30 +84,6 @@ func (c *ChChost) sourceToTarget(md *message.Metadata, source *metadbmodel.VM) (
8484

8585
// onResourceUpdated implements SubscriberDataGenerator
8686
func (c *ChChost) onResourceUpdated(md *message.Metadata, updateMessage *message.UpdatedVM) {
87-
db := md.GetDB()
88-
fieldsUpdate := updateMessage.GetFields().(*message.UpdatedVMFields)
89-
newSource := updateMessage.GetNewMetadbItem().(*metadbmodel.VM)
90-
sourceID := newSource.ID
91-
updateInfo := make(map[string]interface{})
92-
if fieldsUpdate.Name.IsDifferent() {
93-
updateInfo["name"] = fieldsUpdate.Name.GetNew()
94-
}
95-
if fieldsUpdate.VPCID.IsDifferent() {
96-
updateInfo["l3_epc_id"] = fieldsUpdate.VPCID.GetNew()
97-
}
98-
if fieldsUpdate.HostID.IsDifferent() {
99-
updateInfo["host_id"] = fieldsUpdate.HostID.GetNew()
100-
}
101-
if fieldsUpdate.Hostname.IsDifferent() {
102-
updateInfo["hostname"] = fieldsUpdate.Hostname.GetNew()
103-
}
104-
if fieldsUpdate.IP.IsDifferent() {
105-
updateInfo["ip"] = fieldsUpdate.IP.GetNew()
106-
}
107-
if fieldsUpdate.NetworkID.IsDifferent() {
108-
updateInfo["subnet_id"] = fieldsUpdate.NetworkID.GetNew()
109-
}
110-
c.updateOrSync(db, IDKey{ID: sourceID}, updateInfo)
11187
}
11288

11389
// softDeletedTargetsUpdated implements SubscriberDataGenerator

server/controller/tagrecorder/ch_chost_cloud_tag.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ func (c *ChChostCloudTag) onResourceUpdated(md *message.Metadata, updateMessage
6565
sourceID := newSource.ID
6666
new := map[string]string{}
6767
old := map[string]string{}
68-
updateInfo := make(map[string]interface{})
69-
keysToAdd := make([]IDKeyKey, 0)
70-
targetsToAdd := make([]metadbmodel.ChChostCloudTag, 0)
7168
keysToDelete := make([]IDKeyKey, 0)
7269
targetsToDelete := make([]metadbmodel.ChChostCloudTag, 0)
7370

@@ -104,39 +101,6 @@ func (c *ChChostCloudTag) onResourceUpdated(md *message.Metadata, updateMessage
104101
}
105102
}
106103

107-
for k, v := range new {
108-
oldV, ok := old[k]
109-
targetKey := NewIDKeyKey(sourceID, k)
110-
if !ok {
111-
keysToAdd = append(keysToAdd, targetKey)
112-
targetsToAdd = append(targetsToAdd, metadbmodel.ChChostCloudTag{
113-
ChIDBase: metadbmodel.ChIDBase{ID: sourceID},
114-
Key: k,
115-
Value: v,
116-
TeamID: md.GetTeamID(),
117-
DomainID: md.GetDomainID(),
118-
})
119-
continue
120-
}
121-
122-
if oldV != v {
123-
var chItem metadbmodel.ChChostCloudTag
124-
db.Where("id = ? and `key` = ?", sourceID, k).First(&chItem) // TODO common
125-
if chItem.ID == 0 {
126-
keysToAdd = append(keysToAdd, targetKey)
127-
targetsToAdd = append(targetsToAdd, metadbmodel.ChChostCloudTag{
128-
ChIDBase: metadbmodel.ChIDBase{ID: sourceID},
129-
Key: k,
130-
Value: v,
131-
TeamID: md.GetTeamID(),
132-
DomainID: md.GetDomainID(),
133-
})
134-
continue
135-
}
136-
updateInfo["value"] = v
137-
}
138-
c.updateOrSync(db, targetKey, updateInfo)
139-
}
140104
for k := range old {
141105
if _, ok := new[k]; !ok {
142106
keysToDelete = append(keysToDelete, NewIDKeyKey(sourceID, k))
@@ -147,9 +111,6 @@ func (c *ChChostCloudTag) onResourceUpdated(md *message.Metadata, updateMessage
147111
}
148112
}
149113

150-
if len(keysToAdd) > 0 {
151-
c.SubscriberComponent.dbOperator.add(keysToAdd, targetsToAdd, db)
152-
}
153114
if len(keysToDelete) > 0 {
154115
c.SubscriberComponent.dbOperator.delete(keysToDelete, targetsToDelete, db)
155116
}

server/controller/tagrecorder/ch_chost_cloud_tags.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -62,40 +62,6 @@ func NewChChostCloudTags() *ChChostCloudTags {
6262

6363
// onResourceUpdated implements SubscriberDataGenerator
6464
func (c *ChChostCloudTags) onResourceUpdated(md *message.Metadata, updateMessage *message.UpdatedVM) {
65-
db := md.GetDB()
66-
fieldsUpdate := updateMessage.GetFields().(*message.UpdatedVMFields)
67-
newSource := updateMessage.GetNewMetadbItem().(*metadbmodel.VM)
68-
sourceID := newSource.ID
69-
updateInfo := make(map[string]interface{})
70-
71-
if !fieldsUpdate.LearnedCloudTags.IsDifferent() && !fieldsUpdate.CustomCloudTags.IsDifferent() {
72-
return
73-
}
74-
75-
cloudTagMap := MergeCloudTags(newSource.LearnedCloudTags, newSource.CustomCloudTags)
76-
bytes, err := json.Marshal(cloudTagMap)
77-
if err != nil {
78-
log.Error(err, db.LogPrefixORGID)
79-
return
80-
}
81-
updateInfo["cloud_tags"] = string(bytes)
82-
targetKey := IDKey{ID: sourceID}
83-
var chItem metadbmodel.ChChostCloudTags
84-
db.Where("id = ?", sourceID).Find(&chItem)
85-
if chItem.ID == 0 {
86-
c.SubscriberComponent.dbOperator.add(
87-
[]IDKey{targetKey},
88-
[]metadbmodel.ChChostCloudTags{{
89-
ChIDBase: metadbmodel.ChIDBase{ID: sourceID},
90-
CloudTags: updateInfo["cloud_tags"].(string),
91-
TeamID: md.GetTeamID(),
92-
DomainID: md.GetDomainID(),
93-
}},
94-
db,
95-
)
96-
return
97-
}
98-
c.updateOrSync(db, targetKey, updateInfo)
9965
}
10066

10167
// onResourceUpdated implements SubscriberDataGenerator

0 commit comments

Comments
 (0)