Skip to content

Commit

Permalink
feat: add metric data_source
Browse files Browse the repository at this point in the history
  • Loading branch information
SongZhen0704 committed Nov 13, 2024
1 parent 5d953ba commit a4967b8
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
14 changes: 13 additions & 1 deletion server/controller/db/mysql/migrator/schema/rawsql/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
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.14"
DB_VERSION_EXPECTED = "6.6.1.15"
)

const (
Expand Down
6 changes: 3 additions & 3 deletions server/controller/http/service/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a4967b8

Please sign in to comment.