Skip to content

Commit

Permalink
fix: add language field to process
Browse files Browse the repository at this point in the history
  • Loading branch information
roryye committed Jul 11, 2024
1 parent 7e4311c commit 860a107
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions message/controller.proto
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ message GenesisSyncProcess {
optional string start_time = 10;
optional uint32 netns_id = 11;
optional string container_id = 12;
optional string language = 13;
}

message GenesisSyncData{
Expand Down
1 change: 1 addition & 0 deletions message/trident.proto
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ message ProcessInfo {
optional uint32 netns_id = 7 [default = 0];
optional string container_id = 8 [default = ""];
repeated Tag os_app_tags = 11;
optional string language = 12;
}

message GenesisProcessData {
Expand Down
1 change: 1 addition & 0 deletions server/controller/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ func (c *Cloud) appendResourceProcess(resource model.Resource) model.Resource {
ProcessName: processName,
CommandLine: sProcess.CMDLine,
UserName: sProcess.User,
Language: sProcess.Language,
ContainerID: sProcess.ContainerID,
StartTime: sProcess.StartTime,
OSAPPTags: sProcess.OSAPPTags,
Expand Down
1 change: 1 addition & 0 deletions server/controller/cloud/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ type Process struct {
ProcessName string `json:"process_name" binding:"required"`
CommandLine string `json:"command_line"`
UserName string `json:"user_name"`
Language string `json:"language"`
StartTime time.Time `json:"start_time" binding:"required"`
OSAPPTags string `json:"os_app_tags"`
NetnsID uint32 `json:"netns_id"`
Expand Down
36 changes: 36 additions & 0 deletions server/controller/db/mysql/migration/rawsql/issu/6.6.1.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
DROP PROCEDURE IF EXISTS AddColumnAndSetIfNotExists;

CREATE PROCEDURE AddColumnAndSetIfNotExists(
IN tableName VARCHAR(255),
IN colName VARCHAR(255),
IN colType VARCHAR(255),
IN defaultVal VARCHAR(255),
IN afterCol VARCHAR(255)
)
BEGIN
DECLARE col_count INT;

SELECT COUNT(*)
INTO col_count
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = tableName
AND COLUMN_NAME = colName;

-- if the column does not exist, add the column
IF col_count = 0 THEN
SET @sql = CONCAT('ALTER TABLE ', tableName, ' ADD COLUMN ', colName, ' ', colType, ' DEFAULT ', defaultVal, ' AFTER ', afterCol);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END;

CALL AddColumnAndSetIfNotExists('process', 'language', 'VARCHAR(256)', '', 'user_name');
CALL AddColumnAndSetIfNotExists('genesis_process', 'language', 'VARCHAR(256)', '', 'user');

DROP PROCEDURE AddColumnAndSetIfNotExists;

-- whether default db or not, update db_version to latest, remember update DB_VERSION_EXPECT in migrate/init.go
UPDATE db_version SET version='6.6.1.1';
-- modify end
1 change: 1 addition & 0 deletions server/controller/db/mysql/platform_rsc_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type Process struct {
ProcessName string `gorm:"column:process_name;type:varchar(256);default:''" json:"PROCESS_NAME" mapstructure:"PROCESS_NAME"`
CommandLine string `gorm:"column:command_line;type:text" json:"COMMAND_LINE" mapstructure:"COMMAND_LINE"`
UserName string `gorm:"column:user_name;type:varchar(256);default:''" json:"USER_NAME" mapstructure:"USER_NAME"`
Language string `gorm:"column:language;type:varchar(256);default:''" json:"LANGUAGE" mapstructure:"LANGUAGE"`
StartTime time.Time `gorm:"autoCreateTime;column:start_time;type:datetime" json:"START_TIME" mapstructure:"START_TIME"`
OSAPPTags string `gorm:"column:os_app_tags;type:text" json:"OS_APP_TAGS" mapstructure:"OS_APP_TAGS"`
ContainerID string `gorm:"column:container_id;type:char(64);default:''" json:"CONTAINER_ID" mapstructure:"CONTAINER_ID"`
Expand Down
1 change: 1 addition & 0 deletions server/controller/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ func (g *Genesis) GetGenesisSyncResponse(orgID int) (GenesisSyncDataResponse, er
CMDLine: p.GetCmdLine(),
ContainerID: p.GetContainerId(),
User: p.GetUser(),
Language: p.GetLanguage(),
OSAPPTags: p.GetOsAppTags(),
NodeIP: p.GetNodeIp(),
StartTime: pStartTime,
Expand Down
1 change: 1 addition & 0 deletions server/controller/genesis/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ func (g *SynchronizerServer) GenesisSharingSync(ctx context.Context, request *co
ProcessName: &pData.ProcessName,
CmdLine: &pData.CMDLine,
User: &pData.User,
Language: &pData.Language,
ContainerId: &pData.ContainerID,
OsAppTags: &pData.OSAPPTags,
NodeIp: &pData.NodeIP,
Expand Down
1 change: 1 addition & 0 deletions server/controller/genesis/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ func (v *GenesisSyncRpcUpdater) ParseProcessInfo(info VIFRPCMessage, vtapID uint
ProcessName: p.GetProcessName(),
CMDLine: p.GetCmdline(),
User: p.GetUser(),
Language: p.GetLanguage(),
ContainerID: p.GetContainerId(),
VtapID: vtapID,
OSAPPTags: osAppTagString,
Expand Down
1 change: 1 addition & 0 deletions server/controller/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ type GenesisProcess struct {
CMDLine string `gorm:"column:cmd_line;type:text;default:null" json:"CMD_LINE"`
ContainerID string `gorm:"column:container_id;type:char(64);default:''" json:"CONTAINER_ID"`
User string `gorm:"column:user;type:varchar(256);default:null" json:"USER"`
Language string `gorm:"column:language;type:varchar(256);default:null" json:"LANGUAGE"`
OSAPPTags string `gorm:"column:os_app_tags;type:text;default:null" json:"OS_APP_TAGS"`
NodeIP string `gorm:"primaryKey;column:node_ip;type:char(48)" json:"NODE_IP"`
StartTime time.Time `gorm:"column:start_time;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"START_TIME"`
Expand Down
6 changes: 6 additions & 0 deletions server/controller/recorder/cache/diffbase/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func (b *DataSet) AddProcess(dbItem *mysql.Process, seq int) {
ContainerID: dbItem.ContainerID,
DeviceType: dbItem.DeviceType,
DeviceID: dbItem.DeviceID,
User: dbItem.UserName,
Language: dbItem.Language,
}
b.GetLogFunc()(addDiffBase(ctrlrcommon.RESOURCE_TYPE_PROCESS_EN, b.Process[dbItem.Lcuuid]))
}
Expand All @@ -50,6 +52,8 @@ type Process struct {
ContainerID string `json:"container_id"`
DeviceType int `json:"device_type"`
DeviceID int `json:"device_id"`
User string `json:"user"`
Language string `json:"language"`
}

func (p *Process) Update(cloudItem *cloudmodel.Process, toolDataSet *tool.DataSet) {
Expand All @@ -61,5 +65,7 @@ func (p *Process) Update(cloudItem *cloudmodel.Process, toolDataSet *tool.DataSe
p.DeviceType = deviceType
p.DeviceID = deviceID
}
p.User = cloudItem.UserName
p.Language = cloudItem.Language
log.Info(updateDiffBase(ctrlrcommon.RESOURCE_TYPE_PROCESS_EN, p))
}
7 changes: 7 additions & 0 deletions server/controller/recorder/updater/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func (p *Process) generateDBItemToAdd(cloudItem *cloudmodel.Process) (*mysql.Pro
ProcessName: cloudItem.ProcessName,
CommandLine: cloudItem.CommandLine,
UserName: cloudItem.UserName,
Language: cloudItem.Language,
ContainerID: cloudItem.ContainerID,
OSAPPTags: cloudItem.OSAPPTags,
Domain: p.metadata.Domain.Lcuuid,
Expand Down Expand Up @@ -152,6 +153,12 @@ func (p *Process) generateUpdateInfo(diffBase *diffbase.Process, cloudItem *clou
mapInfo["devicetype"] = deviceType
mapInfo["deviceid"] = deviceID
}
if diffBase.User != cloudItem.UserName {
mapInfo["user_name"] = cloudItem.UserName
}
if diffBase.Language != cloudItem.Language {
mapInfo["language"] = cloudItem.Language
}

return structInfo, mapInfo, len(mapInfo) > 0
}

0 comments on commit 860a107

Please sign in to comment.