Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tagrecorder] modify app_label_map #4461

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions server/controller/tagrecorder/ch_app_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package tagrecorder

import (
"golang.org/x/exp/slices"

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

Expand Down Expand Up @@ -47,6 +49,7 @@ func (l *ChAPPLabel) generateNewData() (map[PrometheusAPPLabelKey]mysql.ChAPPLab
if !ok {
return nil, false
}
appLabelSlice, ok := l.generateAPPLabelData()

labelNameIDMap, valueNameIDMap, ok := l.generateNameIDData()
if !ok {
Expand All @@ -58,14 +61,17 @@ func (l *ChAPPLabel) generateNewData() (map[PrometheusAPPLabelKey]mysql.ChAPPLab
labelID := prometheusMetricLabel.LabelID
labelNameValueData := metricLabelIDNameValueMap[labelID]
labelName := labelNameValueData["label_name"]
labelNameID := labelNameIDMap[labelName]
labelValue := labelNameValueData["label_value"]
labelValueID := valueNameIDMap[labelValue]
keyToItem[PrometheusAPPLabelKey{LabelNameID: labelNameID, LabelValueID: labelValueID}] = mysql.ChAPPLabel{
LabelNameID: labelNameID,
LabelValue: labelValue,
LabelValueID: labelValueID,
if slices.Contains(appLabelSlice, labelName) {
labelNameID := labelNameIDMap[labelName]
labelValue := labelNameValueData["label_value"]
labelValueID := valueNameIDMap[labelValue]
keyToItem[PrometheusAPPLabelKey{LabelNameID: labelNameID, LabelValueID: labelValueID}] = mysql.ChAPPLabel{
LabelNameID: labelNameID,
LabelValue: labelValue,
LabelValueID: labelValueID,
}
}

}
return keyToItem, true
}
Expand Down Expand Up @@ -101,6 +107,22 @@ func (l *ChAPPLabel) generateLabelIDNameValueData() (map[int]map[string]string,
return metricLabelIDNameValueMap, true
}

func (l *ChAPPLabel) generateAPPLabelData() ([]string, bool) {
appLabelSlice := []string{}
var prometheusAPPMetricAPPLabelLayouts []mysql.ChPrometheusMetricAPPLabelLayout
err := mysql.Db.Unscoped().Select("app_label_name").Group("app_label_name").Find(&prometheusAPPMetricAPPLabelLayouts).Error

if err != nil {
log.Errorf(dbQueryResourceFailed(l.resourceTypeName, err))
return appLabelSlice, false
}

for _, prometheusAPPMetricAPPLabelLayout := range prometheusAPPMetricAPPLabelLayouts {
appLabelSlice = append(appLabelSlice, prometheusAPPMetricAPPLabelLayout.APPLabelName)
}
return appLabelSlice, true
}

func (l *ChAPPLabel) generateNameIDData() (map[string]int, map[string]int, bool) {
labelNameIDMap := make(map[string]int)
valueNameIDMap := make(map[string]int)
Expand Down
Loading