diff --git a/server/controller/db/mysql/migrator/schema/rawsql/init.sql b/server/controller/db/mysql/migrator/schema/rawsql/init.sql index 57d5fbbab34..49be2464b1b 100644 --- a/server/controller/db/mysql/migrator/schema/rawsql/init.sql +++ b/server/controller/db/mysql/migrator/schema/rawsql/init.sql @@ -2046,7 +2046,7 @@ INSERT INTO data_source (id, display_name, data_table_collection, `interval`, re 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) - VALUES (3, '网络-指标(分钟级)', 'flow_metrics.network*', 1, 60, 7*24, 'Sum', 'Avg', @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) VALUES (6, '网络-流日志', 'flow_log.l4_flow_log', 0, 3*24, @lcuuid); @@ -2092,6 +2092,18 @@ INSERT INTO data_source (id, display_name, data_table_collection, `interval`, re set @lcuuid = (select uuid()); INSERT INTO data_source (id, display_name, data_table_collection, `interval`, 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) + 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) + 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) + 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) + VALUES (24, '应用-指标(天级)', 'flow_metrics.application*', 23, 86400, 30*24, 'Sum', 'Avg', @lcuuid); CREATE TABLE IF NOT EXISTS voucher ( id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, diff --git a/server/controller/db/mysql/migrator/schema/rawsql/issu/6.6.1.15.sql b/server/controller/db/mysql/migrator/schema/rawsql/issu/6.6.1.15.sql new file mode 100644 index 00000000000..6b3a98b9ee7 --- /dev/null +++ b/server/controller/db/mysql/migrator/schema/rawsql/issu/6.6.1.15.sql @@ -0,0 +1,55 @@ +-- modify start, add upgrade sql +DROP PROCEDURE IF EXISTS insert_data_source; + +CREATE PROCEDURE insert_data_source( + IN DisplayName CHAR(64), + IN DataTableCollection CHAR(64), + IN DataInterval INT +) +BEGIN + DECLARE existing_display_name INT DEFAULT 0; + DECLARE existing_base_data_source_id INT DEFAULT 0; + + SELECT COUNT(*) INTO existing_display_name + FROM data_source + WHERE data_table_collection = DataTableCollection + AND `interval` = DataInterval; + + -- check base data_source + -- if not exist, exit current sql + IF DataInterval = 3600 THEN + SELECT id INTO existing_base_data_source_id + FROM data_source + WHERE data_table_collection = DataTableCollection + AND `interval` = 60; + ELSE + SELECT id INTO existing_base_data_source_id + FROM data_source + WHERE data_table_collection = DataTableCollection + AND `interval` = 3600; + END IF; + + IF existing_base_data_source_id = 0 THEN + SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'data_source with interval 3600/86400 not exist'; + END IF; + + IF existing_display_name = 0 THEN + START TRANSACTION; + + SET @lcuuid = (SELECT UUID()); + INSERT INTO data_source (display_name, data_table_collection, base_data_source_id, `interval`, retention_time, summable_metrics_operator, unsummable_metrics_operator, lcuuid) + VALUES (DisplayName, DataTableCollection, existing_base_data_source_id, DataInterval, 30*24, 'Sum', 'Avg', @lcuuid); + + COMMIT; + END IF; + +END; + +CALL insert_data_source('网络-指标(小时级)', 'flow_metrics.network*', 3600); +CALL insert_data_source('网络-指标(天级)', 'flow_metrics.network*', 86400); +CALL insert_data_source('应用-指标(小时级)', 'flow_metrics.application*', 3600); +CALL insert_data_source('应用-指标(天级)', 'flow_metrics.application*', 86400); + +-- update db_version to latest, remeber update DB_VERSION_EXPECT in migrate/init.go +UPDATE db_version SET version='6.6.1.15'; +-- modify end diff --git a/server/controller/db/mysql/migrator/schema/version.go b/server/controller/db/mysql/migrator/schema/version.go index 52670fd607e..4b549a055eb 100644 --- a/server/controller/db/mysql/migrator/schema/version.go +++ b/server/controller/db/mysql/migrator/schema/version.go @@ -18,7 +18,7 @@ package schema const ( DB_VERSION_TABLE = "db_version" - DB_VERSION_EXPECTED = "6.6.1.14" + DB_VERSION_EXPECTED = "6.6.1.15" ) const ( diff --git a/server/controller/http/service/data_source.go b/server/controller/http/service/data_source.go index 342770f47af..82c52c5f240 100644 --- a/server/controller/http/service/data_source.go +++ b/server/controller/http/service/data_source.go @@ -84,9 +84,9 @@ func (d *DataSource) generateIPToController() error { } var DEFAULT_DATA_SOURCE_DISPLAY_NAMES = []string{ - "网络-指标(秒级)", "网络-指标(分钟级)", // flow_metrics.network* - "网络-流日志", // flow_log.l4_flow_log - "应用-指标(秒级)", "应用-指标(分钟级)", // flow_metrics.application* + "网络-指标(秒级)", "网络-指标(分钟级)", "网络-指标(小时级)", "网络-指标(天级)", // flow_metrics.network* + "网络-流日志", // flow_log.l4_flow_log + "应用-指标(秒级)", "应用-指标(分钟级)", "应用-指标(小时级)", "应用-指标(天级)", // flow_metrics.application* "应用-调用日志", // flow_log.l7_flow_log "网络-TCP 时序数据", // flow_log.l4_packet "网络-PCAP 数据", // flow_log.l7_packet