From 44a9bf0befcd9e0e0cd6f95e9b9c8e6427a166e5 Mon Sep 17 00:00:00 2001 From: masaimu Date: Thu, 28 Dec 2023 18:23:05 +0800 Subject: [PATCH] feat: period of time (#771) --- .../common/dao/entity/MonitorInstance.java | 2 ++ ...25__231228_ADD_monitor_instance_COLUMN.sql | 9 +++++++ .../home/web/controller/QueryFacadeImpl.java | 24 +++++++++++++++---- 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 server/extension/extension-common-flyway/src/main/resources/db/migration/V25__231228_ADD_monitor_instance_COLUMN.sql diff --git a/server/common/common-dao/src/main/java/io/holoinsight/server/common/dao/entity/MonitorInstance.java b/server/common/common-dao/src/main/java/io/holoinsight/server/common/dao/entity/MonitorInstance.java index 47edbfbad..2401baee3 100644 --- a/server/common/common-dao/src/main/java/io/holoinsight/server/common/dao/entity/MonitorInstance.java +++ b/server/common/common-dao/src/main/java/io/holoinsight/server/common/dao/entity/MonitorInstance.java @@ -34,6 +34,8 @@ public class MonitorInstance { */ private String instance; + private String instanceName; + /** * 实例类型 */ diff --git a/server/extension/extension-common-flyway/src/main/resources/db/migration/V25__231228_ADD_monitor_instance_COLUMN.sql b/server/extension/extension-common-flyway/src/main/resources/db/migration/V25__231228_ADD_monitor_instance_COLUMN.sql new file mode 100644 index 000000000..ecd1cb1c3 --- /dev/null +++ b/server/extension/extension-common-flyway/src/main/resources/db/migration/V25__231228_ADD_monitor_instance_COLUMN.sql @@ -0,0 +1,9 @@ +/* + * Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0. + */ + +-- ---------------------------- +-- Table structure for agg_task_v1 +-- ---------------------------- +ALTER TABLE `monitor_instance` + ADD COLUMN `instance_name` varchar(255) NULL DEFAULT NULL comment '实例名称' AFTER `instance`; diff --git a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/QueryFacadeImpl.java b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/QueryFacadeImpl.java index 0771c6c6c..cb87a5791 100644 --- a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/QueryFacadeImpl.java +++ b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/QueryFacadeImpl.java @@ -605,10 +605,8 @@ protected void parseQl(QueryDataSource d, MetricInfo metricInfo) { StringBuilder select = new StringBuilder("select "); List gbList = parseGroupby(d, tags, timestampName); List selects = new ArrayList<>(); - String downsample = "PT1M"; - if (StringUtils.equalsIgnoreCase(d.getDownsample(), "1h")) { - downsample = "PT1H"; - } + String downsample = getPeriodOfTime(d.getDownsample()); + selects.add("time_bucket(`" + timestampName + "`, '" + downsample + "', 'yyyy-MM-dd HH:mm:ss', '+0800') AS `timestamp`"); for (String gb : gbList) { @@ -644,6 +642,24 @@ protected void parseQl(QueryDataSource d, MetricInfo metricInfo) { d.setQl(select.toString()); } + private String getPeriodOfTime(String downsample) { + if (StringUtils.isBlank(downsample)) { + return "PT1M"; + } + switch (downsample) { + case "1m": + return "PT1M"; + case "5m": + return "PT5M"; + case "30m": + return "PT30M"; + case "1h": + return "PT1H"; + default: + return "PT1M"; + } + } + private List parseGroupby(QueryDataSource d, Set tags, String timestampName) { List gbList = new ArrayList<>(); if (!CollectionUtils.isEmpty(d.groupBy)) {