Skip to content

Commit

Permalink
feat: querier supports show enum tags by language
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaochaoren1 committed Nov 26, 2024
1 parent eeb3d10 commit 37c8ae8
Show file tree
Hide file tree
Showing 21 changed files with 412 additions and 276 deletions.
13 changes: 8 additions & 5 deletions server/controller/db/mysql/migrator/schema/rawsql/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2154,12 +2154,13 @@ CREATE TABLE IF NOT EXISTS mail_server (
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
TRUNCATE TABLE mail_server;


CREATE TABLE IF NOT EXISTS ch_string_enum (
tag_name VARCHAR(256) NOT NULL ,
value VARCHAR(256) NOT NULL,
name VARCHAR(256) ,
description VARCHAR(256) ,
name_zh VARCHAR(256) ,
name_en VARCHAR(256) ,
description_zh VARCHAR(256) ,
description_en VARCHAR(256) ,
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (tag_name,value)
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
Expand All @@ -2168,8 +2169,10 @@ TRUNCATE TABLE ch_string_enum;
CREATE TABLE IF NOT EXISTS ch_int_enum (
tag_name VARCHAR(256) NOT NULL,
value INTEGER DEFAULT 0,
name VARCHAR(256) ,
description VARCHAR(256) ,
name_zh VARCHAR(256) ,
name_en VARCHAR(256) ,
description_zh VARCHAR(256) ,
description_en VARCHAR(256) ,
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (tag_name,value)
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
DROP TABLE IF EXISTS ch_string_enum;
DROP TABLE IF EXISTS ch_int_enum;

CREATE TABLE IF NOT EXISTS ch_string_enum (
tag_name VARCHAR(256) NOT NULL ,
value VARCHAR(256) NOT NULL,
name_zh VARCHAR(256) ,
name_en VARCHAR(256) ,
description_zh VARCHAR(256) ,
description_en VARCHAR(256) ,
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (tag_name,value)
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS ch_int_enum (
tag_name VARCHAR(256) NOT NULL,
value INTEGER DEFAULT 0,
name_zh VARCHAR(256) ,
name_en VARCHAR(256) ,
description_zh VARCHAR(256) ,
description_en VARCHAR(256) ,
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (tag_name,value)
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

-- update db_version to latest, remeber update DB_VERSION_EXPECT in migrate/init.go
UPDATE db_version SET version='6.6.1.17';
-- modify end

2 changes: 1 addition & 1 deletion server/controller/db/mysql/migrator/schema/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package schema

const (
DB_VERSION_TABLE = "db_version"
DB_VERSION_EXPECTED = "6.6.1.16"
DB_VERSION_EXPECTED = "6.6.1.17"
)

const (
Expand Down
24 changes: 14 additions & 10 deletions server/controller/db/mysql/model/ch_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,19 +329,23 @@ type ChPodServiceK8sLabels struct {
}

type ChStringEnum struct {
TagName string `gorm:"primaryKey;column:tag_name;type:varchar(256);default:null" json:"TAG_NAME"`
Value string `gorm:"primaryKey;column:value;type:varchar(256);default:null" json:"VALUE"`
Name string `gorm:"column:name;type:varchar(256);default:null" json:"NAME"`
Description string `gorm:"column:description;type:varchar(256);default:null" json:"DESCRIPTION"`
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime:now,type:timestamp" json:"UPDATED_AT"`
TagName string `gorm:"primaryKey;column:tag_name;type:varchar(256);default:null" json:"TAG_NAME"`
Value string `gorm:"primaryKey;column:value;type:varchar(256);default:null" json:"VALUE"`
NameZH string `gorm:"column:name_zh;type:varchar(256);default:null" json:"NAME_ZH"`
NameEN string `gorm:"column:name_en;type:varchar(256);default:null" json:"NAME_EN"`
DescriptionZH string `gorm:"column:description_zh;type:varchar(256);default:null" json:"DESCRIPTION_ZH"`
DescriptionEN string `gorm:"column:description_en;type:varchar(256);default:null" json:"DESCRIPTION_EN"`
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime:now,type:timestamp" json:"UPDATED_AT"`
}

type ChIntEnum struct {
TagName string `gorm:"primaryKey;column:tag_name;type:varchar(256);default:null" json:"TAG_NAME"`
Value int `gorm:"primaryKey;column:value;type:int;default:0" json:"VALUE"`
Name string `gorm:"column:name;type:varchar(256);default:null" json:"NAME"`
Description string `gorm:"column:description;type:varchar(256);default:null" json:"DESCRIPTION"`
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime:now,type:timestamp" json:"UPDATED_AT"`
TagName string `gorm:"primaryKey;column:tag_name;type:varchar(256);default:null" json:"TAG_NAME"`
Value int `gorm:"primaryKey;column:value;type:int;default:0" json:"VALUE"`
NameZH string `gorm:"column:name_zh;type:varchar(256);default:null" json:"NAME_ZH"`
NameEN string `gorm:"column:name_en;type:varchar(256);default:null" json:"NAME_EN"`
DescriptionZH string `gorm:"column:description_zh;type:varchar(256);default:null" json:"DESCRIPTION_ZH"`
DescriptionEN string `gorm:"column:description_en;type:varchar(256);default:null" json:"DESCRIPTION_EN"`
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime:now,type:timestamp" json:"UPDATED_AT"`
}

type ChNodeType struct {
Expand Down
43 changes: 23 additions & 20 deletions server/controller/tagrecorder/ch_int_enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
package tagrecorder

import (
"strconv"
"strings"

"github.com/deepflowio/deepflow/server/controller/db/mysql"
mysqlmodel "github.com/deepflowio/deepflow/server/controller/db/mysql/model"
"github.com/deepflowio/deepflow/server/querier/config"
"github.com/deepflowio/deepflow/server/querier/engine/clickhouse/tag"
)

Expand Down Expand Up @@ -51,28 +47,29 @@ func (e *ChIntEnum) generateNewData(dbClient *mysql.DB) (map[IntEnumTagKey]mysql
}

for name, tagValues := range respMap {
tagName := strings.TrimSuffix(name, "."+config.Cfg.Language)
for _, valueAndName := range tagValues {
tagValue := valueAndName.([]interface{})[0]
tagDisplayName := valueAndName.([]interface{})[1]
tagDescription := valueAndName.([]interface{})[2]
tagValueInt, err := strconv.Atoi(tagValue.(string))
if err == nil {
tagDisplayNameZH := valueAndName.([]interface{})[1]
tagDisplayNameEN := valueAndName.([]interface{})[2]
tagDescriptionZH := valueAndName.([]interface{})[3]
tagDescriptionEN := valueAndName.([]interface{})[4]
tagValueInt, ok := tagValue.(int)
if ok {
key := IntEnumTagKey{
TagName: tagName,
TagName: name,
TagValue: tagValueInt,
}
keyToItem[key] = mysqlmodel.ChIntEnum{
TagName: tagName,
Value: tagValueInt,
Name: tagDisplayName.(string),
Description: tagDescription.(string),
TagName: name,
Value: tagValueInt,
NameZH: tagDisplayNameZH.(string),
NameEN: tagDisplayNameEN.(string),
DescriptionZH: tagDescriptionZH.(string),
DescriptionEN: tagDescriptionEN.(string),
}
}

}
}

return keyToItem, true
}

Expand All @@ -88,11 +85,17 @@ func (e *ChIntEnum) generateUpdateInfo(oldItem, newItem mysqlmodel.ChIntEnum) (m
if oldItem.Value != newItem.Value {
updateInfo["value"] = newItem.Value
}
if oldItem.Name != newItem.Name {
updateInfo["name"] = newItem.Name
if oldItem.NameZH != newItem.NameZH {
updateInfo["name_zh"] = newItem.NameZH
}
if oldItem.NameEN != newItem.NameEN {
updateInfo["name_en"] = newItem.NameEN
}
if oldItem.DescriptionZH != newItem.DescriptionZH {
updateInfo["description_zh"] = newItem.DescriptionZH
}
if oldItem.Description != newItem.Description {
updateInfo["description"] = newItem.Description
if oldItem.DescriptionEN != newItem.DescriptionEN {
updateInfo["description_en"] = newItem.DescriptionEN
}
if len(updateInfo) > 0 {
return updateInfo, true
Expand Down
37 changes: 21 additions & 16 deletions server/controller/tagrecorder/ch_string_enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
package tagrecorder

import (
"strings"

"github.com/deepflowio/deepflow/server/controller/db/mysql"
mysqlmodel "github.com/deepflowio/deepflow/server/controller/db/mysql/model"
"github.com/deepflowio/deepflow/server/querier/config"
"github.com/deepflowio/deepflow/server/querier/engine/clickhouse/tag"
)

Expand Down Expand Up @@ -50,24 +47,26 @@ func (e *ChStringEnum) generateNewData(dbClient *mysql.DB) (map[StringEnumTagKey
}

for name, tagValues := range respMap {
tagName := strings.TrimSuffix(name, "."+config.Cfg.Language)
for _, valueAndName := range tagValues {
tagValue := valueAndName.([]interface{})[0]
tagDisplayName := valueAndName.([]interface{})[1]
tagDescription := valueAndName.([]interface{})[2]
tagDisplayNameZH := valueAndName.([]interface{})[1]
tagDisplayNameEN := valueAndName.([]interface{})[2]
tagDescriptionZH := valueAndName.([]interface{})[3]
tagDescriptionEN := valueAndName.([]interface{})[4]
key := StringEnumTagKey{
TagName: tagName,
TagName: name,
TagValue: tagValue.(string),
}
keyToItem[key] = mysqlmodel.ChStringEnum{
TagName: tagName,
Value: tagValue.(string),
Name: tagDisplayName.(string),
Description: tagDescription.(string),
TagName: name,
Value: tagValue.(string),
NameZH: tagDisplayNameZH.(string),
NameEN: tagDisplayNameEN.(string),
DescriptionZH: tagDescriptionZH.(string),
DescriptionEN: tagDescriptionEN.(string),
}
}
}

return keyToItem, true
}

Expand All @@ -83,11 +82,17 @@ func (e *ChStringEnum) generateUpdateInfo(oldItem, newItem mysqlmodel.ChStringEn
if oldItem.Value != newItem.Value {
updateInfo["value"] = newItem.Value
}
if oldItem.Name != newItem.Name {
updateInfo["name"] = newItem.Name
if oldItem.NameZH != newItem.NameZH {
updateInfo["name_zh"] = newItem.NameZH
}
if oldItem.NameEN != newItem.NameEN {
updateInfo["name_en"] = newItem.NameEN
}
if oldItem.DescriptionZH != newItem.DescriptionZH {
updateInfo["description_zh"] = newItem.DescriptionZH
}
if oldItem.Description != newItem.Description {
updateInfo["description"] = newItem.Description
if oldItem.DescriptionEN != newItem.DescriptionEN {
updateInfo["description_en"] = newItem.DescriptionEN
}
if len(updateInfo) > 0 {
return updateInfo, true
Expand Down
42 changes: 23 additions & 19 deletions server/controller/tagrecorder/check/ch_int_enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
package tagrecorder

import (
"strconv"
"strings"

mysqlmodel "github.com/deepflowio/deepflow/server/controller/db/mysql/model"
"github.com/deepflowio/deepflow/server/querier/config"
"github.com/deepflowio/deepflow/server/querier/engine/clickhouse/tag"
)

Expand Down Expand Up @@ -50,25 +46,27 @@ func (e *ChIntEnum) generateNewData() (map[IntEnumTagKey]mysqlmodel.ChIntEnum, b
}

for name, tagValues := range respMap {
tagName := strings.TrimSuffix(name, "."+config.Cfg.Language)
for _, valueAndName := range tagValues {
tagValue := valueAndName.([]interface{})[0]
tagDisplayName := valueAndName.([]interface{})[1]
tagDescription := valueAndName.([]interface{})[2]
tagValueInt, err := strconv.Atoi(tagValue.(string))
if err == nil {
tagDisplayNameZH := valueAndName.([]interface{})[1]
tagDisplayNameEN := valueAndName.([]interface{})[2]
tagDescriptionZH := valueAndName.([]interface{})[3]
tagDescriptionEN := valueAndName.([]interface{})[4]
tagValueInt, ok := tagValue.(int)
if ok {
key := IntEnumTagKey{
TagName: tagName,
TagName: name,
TagValue: tagValueInt,
}
keyToItem[key] = mysqlmodel.ChIntEnum{
TagName: tagName,
Value: tagValueInt,
Name: tagDisplayName.(string),
Description: tagDescription.(string),
TagName: name,
Value: tagValueInt,
NameZH: tagDisplayNameZH.(string),
NameEN: tagDisplayNameEN.(string),
DescriptionZH: tagDescriptionZH.(string),
DescriptionEN: tagDescriptionEN.(string),
}
}

}
}

Expand All @@ -87,11 +85,17 @@ func (e *ChIntEnum) generateUpdateInfo(oldItem, newItem mysqlmodel.ChIntEnum) (m
if oldItem.Value != newItem.Value {
updateInfo["value"] = newItem.Value
}
if oldItem.Name != newItem.Name {
updateInfo["name"] = newItem.Name
if oldItem.NameZH != newItem.NameZH {
updateInfo["name_zh"] = newItem.NameZH
}
if oldItem.NameEN != newItem.NameEN {
updateInfo["name_en"] = newItem.NameEN
}
if oldItem.DescriptionZH != newItem.DescriptionZH {
updateInfo["description_zh"] = newItem.DescriptionZH
}
if oldItem.Description != newItem.Description {
updateInfo["description"] = newItem.Description
if oldItem.DescriptionEN != newItem.DescriptionEN {
updateInfo["description_en"] = newItem.DescriptionEN
}
if len(updateInfo) > 0 {
return updateInfo, true
Expand Down
37 changes: 21 additions & 16 deletions server/controller/tagrecorder/check/ch_string_enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
package tagrecorder

import (
"strings"

mysqlmodel "github.com/deepflowio/deepflow/server/controller/db/mysql/model"
"github.com/deepflowio/deepflow/server/querier/config"
"github.com/deepflowio/deepflow/server/querier/engine/clickhouse/tag"
)

Expand Down Expand Up @@ -49,24 +46,26 @@ func (e *ChStringEnum) generateNewData() (map[StringEnumTagKey]mysqlmodel.ChStri
}

for name, tagValues := range respMap {
tagName := strings.TrimSuffix(name, "."+config.Cfg.Language)
for _, valueAndName := range tagValues {
tagValue := valueAndName.([]interface{})[0]
tagDisplayName := valueAndName.([]interface{})[1]
tagDescription := valueAndName.([]interface{})[2]
tagDisplayNameZH := valueAndName.([]interface{})[1]
tagDisplayNameEN := valueAndName.([]interface{})[2]
tagDescriptionZH := valueAndName.([]interface{})[3]
tagDescriptionEN := valueAndName.([]interface{})[4]
key := StringEnumTagKey{
TagName: tagName,
TagName: name,
TagValue: tagValue.(string),
}
keyToItem[key] = mysqlmodel.ChStringEnum{
TagName: tagName,
Value: tagValue.(string),
Name: tagDisplayName.(string),
Description: tagDescription.(string),
TagName: name,
Value: tagValue.(string),
NameZH: tagDisplayNameZH.(string),
NameEN: tagDisplayNameEN.(string),
DescriptionZH: tagDescriptionZH.(string),
DescriptionEN: tagDescriptionEN.(string),
}
}
}

return keyToItem, true
}

Expand All @@ -82,11 +81,17 @@ func (e *ChStringEnum) generateUpdateInfo(oldItem, newItem mysqlmodel.ChStringEn
if oldItem.Value != newItem.Value {
updateInfo["value"] = newItem.Value
}
if oldItem.Name != newItem.Name {
updateInfo["name"] = newItem.Name
if oldItem.NameZH != newItem.NameZH {
updateInfo["name_zh"] = newItem.NameZH
}
if oldItem.NameEN != newItem.NameEN {
updateInfo["name_en"] = newItem.NameEN
}
if oldItem.DescriptionZH != newItem.DescriptionZH {
updateInfo["description_zh"] = newItem.DescriptionZH
}
if oldItem.Description != newItem.Description {
updateInfo["description"] = newItem.Description
if oldItem.DescriptionEN != newItem.DescriptionEN {
updateInfo["description_en"] = newItem.DescriptionEN
}
if len(updateInfo) > 0 {
return updateInfo, true
Expand Down
Loading

0 comments on commit 37c8ae8

Please sign in to comment.