Skip to content

Commit

Permalink
feat: renames table columns to support postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhengYa-0110 authored and SongZhen0704 committed Dec 19, 2024
1 parent f1b5a01 commit 3388cc7
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 77 deletions.
2 changes: 1 addition & 1 deletion server/controller/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ func (c *Cloud) appendResourceProcess(resource model.Resource) model.Resource {
NetnsID: sProcess.NetnsID,
ProcessName: processName,
CommandLine: sProcess.CMDLine,
UserName: sProcess.User,
UserName: sProcess.UserName,
ContainerID: sProcess.ContainerID,
StartTime: sProcess.StartTime,
OSAPPTags: sProcess.OSAPPTags,
Expand Down
52 changes: 26 additions & 26 deletions server/controller/db/mysql/migrator/schema/rawsql/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CREATE TABLE IF NOT EXISTS plugin (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(256) NOT NULL,
type INTEGER NOT NULL COMMENT '1: wasm 2: so 3: lua',
user INTEGER NOT NULL DEFAULT 1 COMMENT '1: agent 2: server',
user_name INTEGER NOT NULL DEFAULT 1 COMMENT '1: agent 2: server',
image LONGBLOB NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
Expand Down Expand Up @@ -1447,7 +1447,7 @@ CREATE TABLE IF NOT EXISTS report_policy (
`data_level` enum('1s','1m') NOT NULL DEFAULT '1m',
report_format TINYINT(1) DEFAULT 1 COMMENT 'Type of format (1-html)',
report_type TINYINT(1) DEFAULT 1 COMMENT 'Type of reports (0-daily; 1-weekly; 2-monthly)',
`interval` enum('1d','1h') NOT NULL DEFAULT '1h',
`interval_time` enum('1d','1h') NOT NULL DEFAULT '1h',
state TINYINT(1) DEFAULT 1 COMMENT '0-disable; 1-enable',
push_type TINYINT(1) DEFAULT 1 COMMENT '1-email',
push_email TEXT COMMENT 'separated by ,',
Expand Down Expand Up @@ -1714,7 +1714,7 @@ CREATE TABLE IF NOT EXISTS genesis_process (
name TEXT,
process_name TEXT,
cmd_line TEXT,
user VARCHAR(256) DEFAULT '',
user_name VARCHAR(256) DEFAULT '',
container_id CHAR(64) DEFAULT '',
os_app_tags TEXT COMMENT 'separated by ,',
node_ip CHAR(48) DEFAULT '',
Expand Down Expand Up @@ -2083,7 +2083,7 @@ CREATE TABLE IF NOT EXISTS data_source (
data_table_collection CHAR(64),
state INTEGER DEFAULT 1 COMMENT '0: Exception 1: Normal',
base_data_source_id INTEGER,
`interval` INTEGER NOT NULL COMMENT 'uint: s',
`interval_time` INTEGER NOT NULL COMMENT 'uint: s',
retention_time INTEGER NOT NULL COMMENT 'uint: hour',
summable_metrics_operator CHAR(64),
unsummable_metrics_operator CHAR(64),
Expand All @@ -2093,67 +2093,67 @@ CREATE TABLE IF NOT EXISTS data_source (
TRUNCATE TABLE data_source;

set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, `interval`, retention_time, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, lcuuid)
VALUES (1, '网络-指标(秒级)', 'flow_metrics.network*', 1, 1*24, @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, base_data_source_id, `interval`, retention_time, summable_metrics_operator, unsummable_metrics_operator, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, base_data_source_id, `interval_time`, retention_time, summable_metrics_operator, unsummable_metrics_operator, lcuuid)
VALUES (2, '网络-指标(分钟级)', 'flow_metrics.network*', 1, 60, 7*24, 'Sum', 'Avg', @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, `interval`, retention_time, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, lcuuid)
VALUES (6, '网络-流日志', 'flow_log.l4_flow_log', 0, 3*24, @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, `interval`, retention_time, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, lcuuid)
VALUES (7, '应用-指标(秒级)', 'flow_metrics.application*', 1, 1*24, @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, base_data_source_id, `interval`, retention_time, summable_metrics_operator, unsummable_metrics_operator, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, base_data_source_id, `interval_time`, retention_time, summable_metrics_operator, unsummable_metrics_operator, lcuuid)
VALUES (8, '应用-指标(分钟级)', 'flow_metrics.application*', 7, 60, 7*24, 'Sum', 'Avg', @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, `interval`, retention_time, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, lcuuid)
VALUES (9, '应用-调用日志', 'flow_log.l7_flow_log', 0, 3*24, @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, `interval`, retention_time, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, lcuuid)
VALUES (10, '网络-TCP 时序数据', 'flow_log.l4_packet', 0, 3*24, @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, `interval`, retention_time, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, lcuuid)
VALUES (11, '网络-PCAP 数据', 'flow_log.l7_packet', 0, 3*24, @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, `interval`, retention_time, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, lcuuid)
VALUES (12, '租户侧监控数据', 'deepflow_tenant.*', 0, 7*24, @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, `interval`, retention_time, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, lcuuid)
VALUES (13, '外部指标数据', 'ext_metrics.*', 0, 7*24, @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, `interval`, retention_time, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, lcuuid)
VALUES (14, 'Prometheus 数据', 'prometheus.*', 0, 7*24, @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, `interval`, retention_time, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, lcuuid)
VALUES (15, '事件-资源变更事件', 'event.event', 0, 30*24, @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, `interval`, retention_time, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, lcuuid)
VALUES (16, '事件-IO 事件', 'event.perf_event', 0, 7*24, @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, `interval`, retention_time, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, lcuuid)
VALUES (17, '事件-告警事件', 'event.alert_event', 0, 30*24, @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, `interval`, retention_time, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, lcuuid)
VALUES (18, '应用-性能剖析', 'profile.in_process', 0, 3*24, @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, `interval`, retention_time, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, lcuuid)
VALUES (19, '网络-网络策略', 'flow_metrics.traffic_policy', 60, 3*24, @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, `interval`, retention_time, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, `interval_time`, retention_time, lcuuid)
VALUES (20, '日志-日志数据', 'application_log.log', 1, 30*24, @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, base_data_source_id, `interval`, retention_time, summable_metrics_operator, unsummable_metrics_operator, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, base_data_source_id, `interval_time`, retention_time, summable_metrics_operator, unsummable_metrics_operator, lcuuid)
VALUES (21, '网络-指标(小时级)', 'flow_metrics.network*', 2, 3600, 30*24, 'Sum', 'Avg', @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, base_data_source_id, `interval`, retention_time, summable_metrics_operator, unsummable_metrics_operator, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, base_data_source_id, `interval_time`, retention_time, summable_metrics_operator, unsummable_metrics_operator, lcuuid)
VALUES (22, '网络-指标(天级)', 'flow_metrics.network*', 21, 86400, 30*24, 'Sum', 'Avg', @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, base_data_source_id, `interval`, retention_time, summable_metrics_operator, unsummable_metrics_operator, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, base_data_source_id, `interval_time`, retention_time, summable_metrics_operator, unsummable_metrics_operator, lcuuid)
VALUES (23, '应用-指标(小时级)', 'flow_metrics.application*', 8, 3600, 30*24, 'Sum', 'Avg', @lcuuid);
set @lcuuid = (select uuid());
INSERT INTO data_source (id, display_name, data_table_collection, base_data_source_id, `interval`, retention_time, summable_metrics_operator, unsummable_metrics_operator, lcuuid)
INSERT INTO data_source (id, display_name, data_table_collection, base_data_source_id, `interval_time`, retention_time, summable_metrics_operator, unsummable_metrics_operator, lcuuid)
VALUES (24, '应用-指标(天级)', 'flow_metrics.application*', 23, 86400, 30*24, 'Sum', 'Avg', @lcuuid);

CREATE TABLE IF NOT EXISTS voucher (
Expand Down Expand Up @@ -2195,7 +2195,7 @@ CREATE TABLE IF NOT EXISTS mail_server (
status int NOT NULL ,
host TEXT NOT NULL,
port int Not NULL,
user TEXT NOT NULL,
user_name TEXT NOT NULL,
password TEXT NOT NULL,
security TEXT Not NULL,
ntlm_enabled int,
Expand Down
39 changes: 39 additions & 0 deletions server/controller/db/mysql/migrator/schema/rawsql/issu/7.0.1.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- for /db/mysql/migration/script/upgrade_vtap_group_config.go
DROP PROCEDURE IF EXISTS RenameColumnIfExists;

CREATE PROCEDURE RenameColumnIfExists(
IN tableName VARCHAR(255),
IN oldColName VARCHAR(255),
IN newColName VARCHAR(255),
IN colType VARCHAR(255)
)
BEGIN
DECLARE index_count INT;

-- check if old column exists
SELECT COUNT(*)
INTO index_count
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = tableName
AND column_name = newColName;

-- if new column not exists, rename column
IF index_count = 0 THEN
SET @sql = CONCAT('ALTER TABLE ', tableName, ' CHANGE ', oldColName, ' ', newColName, ' ', colType);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END;

CALL RenameColumnIfExists('mail_server', 'user', 'user_name', 'TEXT NOT NULL');
CALL RenameColumnIfExists('plugin', 'user', 'user_name', "INTEGER NOT NULL DEFAULT 1 COMMENT '1: agent 2: server'");
CALL RenameColumnIfExists('genesis_process', 'user', 'user_name', "VARCHAR(256) DEFAULT ''");
CALL RenameColumnIfExists('data_source', "`interval`", 'interval_time', "INTEGER NOT NULL COMMENT 'uint: s'");
CALL RenameColumnIfExists('report_policy', '`interval`', 'interval_time', "enum('1d','1h') NOT NULL DEFAULT '1h'");

DROP PROCEDURE RenameColumnIfExists;


UPDATE db_version SET version='7.0.1.0';
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.19"
DB_VERSION_EXPECTED = "7.0.1.0"
)

const (
Expand Down
8 changes: 4 additions & 4 deletions server/controller/db/mysql/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ type DataSource struct {
DataTableCollection string `gorm:"column:data_table_collection;type:char(64);default:''" json:"DATA_TABLE_COLLECTION"`
State int `gorm:"column:state;type:int;default:1" json:"STATE"`
BaseDataSourceID int `gorm:"column:base_data_source_id;type:int" json:"BASE_DATA_SOURCE_ID"`
Interval int `gorm:"column:interval;type:int" json:"INTERVAL"`
IntervalTime int `gorm:"column:interval_time;type:int" json:"INTERVAL"`
RetentionTime int `gorm:"column:retention_time;type:int" json:"RETENTION_TIME"` // unit: hour
SummableMetricsOperator string `gorm:"column:summable_metrics_operator;type:char(64)" json:"SUMMABLE_METRICS_OPERATOR"`
UnSummableMetricsOperator string `gorm:"column:unsummable_metrics_operator;type:char(64)" json:"UNSUMMABLE_METRICS_OPERATOR"`
Expand Down Expand Up @@ -489,8 +489,8 @@ func (VTapRepo) TableName() string {
type Plugin struct {
ID int `gorm:"primaryKey;column:id;type:int;not null" json:"ID"`
Name string `gorm:"column:name;type:varchar(256);not null" json:"NAME"`
Type int `gorm:"column:type;type:int" json:"TYPE"` // 1: wasm 2: so 3: lua
User int `gorm:"column:user;type:int;default:1" json:"USER"` // 1: agent 2: server
Type int `gorm:"column:type;type:int" json:"TYPE"` // 1: wasm 2: so 3: lua
UserName int `gorm:"column:user_name;type:int;default:1" json:"USER"` // 1: agent 2: server
Image compressedBytes `gorm:"column:image;type:logblob;not null" json:"IMAGE"`
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;not null;default:CURRENT_TIMESTAMP" json:"CREATED_AT"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;not null;default:CURRENT_TIMESTAMP" json:"UPDATED_AT"`
Expand All @@ -505,7 +505,7 @@ type MailServer struct {
Status int `gorm:"column:status;type:int;not null" json:"STATUS"`
Host string `gorm:"column:host;type:text;not null" json:"HOST"`
Port int `gorm:"column:port;type:int;not null" json:"PORT"`
User string `gorm:"column:user;type:text;not null" json:"USER"`
UserName string `gorm:"column:user_name;type:text;not null" json:"USER"`
Password string `gorm:"column:password;type:text;not null" json:"PASSWORD"`
Security string `gorm:"column:security;type:text;not null" json:"SECURITY"`
NtlmEnabled int `gorm:"column:ntlm_enabled;type:int" json:"NTLM_ENABLED"`
Expand Down
2 changes: 1 addition & 1 deletion server/controller/genesis/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ func (g *SynchronizerServer) GenesisSharingSync(ctx context.Context, request *co
Name: &pData.Name,
ProcessName: &pData.ProcessName,
CmdLine: &pData.CMDLine,
User: &pData.User,
User: &pData.UserName,
ContainerId: &pData.ContainerID,
OsAppTags: &pData.OSAPPTags,
NodeIp: &pData.NodeIP,
Expand Down
2 changes: 1 addition & 1 deletion server/controller/genesis/store/sync/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func (g *GenesisSync) GetGenesisSyncResponse(orgID int) (common.GenesisSyncDataR
ProcessName: p.GetProcessName(),
CMDLine: p.GetCmdLine(),
ContainerID: p.GetContainerId(),
User: p.GetUser(),
UserName: p.GetUser(),
OSAPPTags: p.GetOsAppTags(),
NodeIP: p.GetNodeIp(),
StartTime: pStartTime,
Expand Down
2 changes: 1 addition & 1 deletion server/controller/genesis/updater/agent_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func (v *GenesisSyncRpcUpdater) ParseAgentProcessInfo(orgID int, vtapID uint32,
Name: p.GetName(),
ProcessName: p.GetProcessName(),
CMDLine: p.GetCmdline(),
User: p.GetUser(),
UserName: p.GetUser(),
ContainerID: p.GetContainerId(),
VtapID: vtapID,
NodeIP: v.nodeIP,
Expand Down
2 changes: 1 addition & 1 deletion server/controller/genesis/updater/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func (v *GenesisSyncRpcUpdater) ParseProcessInfo(orgID int, vtapID uint32, messa
Name: p.GetName(),
ProcessName: p.GetProcessName(),
CMDLine: p.GetCmdline(),
User: p.GetUser(),
UserName: p.GetUser(),
ContainerID: p.GetContainerId(),
VtapID: vtapID,
NodeIP: v.nodeIP,
Expand Down
6 changes: 3 additions & 3 deletions server/controller/http/router/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func createPlugin(c *gin.Context) {
return
}
plugin := &mysqlmodel.Plugin{
Name: c.PostForm("NAME"),
Type: t,
User: u,
Name: c.PostForm("NAME"),
Type: t,
UserName: u,
}

// get file
Expand Down
Loading

0 comments on commit 3388cc7

Please sign in to comment.