Skip to content

Commit

Permalink
feat: period of time (#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
masaimu authored Dec 28, 2023
1 parent 7907b71 commit 44a9bf0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class MonitorInstance {
*/
private String instance;

private String instanceName;

/**
* 实例类型
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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`;
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,8 @@ protected void parseQl(QueryDataSource d, MetricInfo metricInfo) {
StringBuilder select = new StringBuilder("select ");
List<String> gbList = parseGroupby(d, tags, timestampName);
List<String> 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) {
Expand Down Expand Up @@ -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<String> parseGroupby(QueryDataSource d, Set<String> tags, String timestampName) {
List<String> gbList = new ArrayList<>();
if (!CollectionUtils.isEmpty(d.groupBy)) {
Expand Down

0 comments on commit 44a9bf0

Please sign in to comment.