From e450d20f8a2bff4a7bf09ae5256c6f6e970072ee Mon Sep 17 00:00:00 2001 From: Logic Date: Wed, 28 Feb 2024 11:45:43 +0800 Subject: [PATCH] [fix]Fix and pass the checkstyle error in warehouse module code (#1590) Signed-off-by: tomsun28 Co-authored-by: tomsun28 --- script/checkstyle/checkstyle.xml | 2 +- .../warehouse/config/WarehouseProperties.java | 27 +++++++++++++++++++ .../store/HistoryGrepTimeDbDataStorage.java | 3 ++- .../store/HistoryJpaDatabaseDataStorage.java | 7 +++++ .../HistoryVictoriaMetricsDataStorage.java | 16 +++++++++-- .../store/RealTimeRedisDataStorage.java | 2 ++ 6 files changed, 53 insertions(+), 4 deletions(-) diff --git a/script/checkstyle/checkstyle.xml b/script/checkstyle/checkstyle.xml index bcc783b5694..dae8d09f1d0 100644 --- a/script/checkstyle/checkstyle.xml +++ b/script/checkstyle/checkstyle.xml @@ -22,7 +22,7 @@ - + diff --git a/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/config/WarehouseProperties.java b/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/config/WarehouseProperties.java index 5ff7556fb49..edf0075729a 100644 --- a/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/config/WarehouseProperties.java +++ b/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/config/WarehouseProperties.java @@ -75,6 +75,9 @@ public void setKafka(KafkaProperties kafka) { this.kafka = kafka; } + /** + * kafka配置信息 + */ public static class KafkaProperties { /** * kafka数据入口是否启动 @@ -233,6 +236,9 @@ public void setGreptime(GreptimeProperties greptime) { this.greptime = greptime; } + /** + * 内存存储配置信息 + */ public static class MemoryProperties { /** * 内存数据存储是否启动 @@ -260,6 +266,9 @@ public void setInitSize(Integer initSize) { } } + /** + * JPA配置信息 + */ public static class JpaProperties { /** * use mysql/h2 jpa store metrics history data @@ -301,6 +310,9 @@ public void setMaxHistoryRecordNum(Integer maxHistoryRecordNum) { } } + /** + * Influxdb配置信息 + */ public static class InfluxdbProperties { /** * influxdb数据存储是否启动 @@ -376,6 +388,9 @@ public void setReplication(int replication) { } } + /** + * TdEngine配置信息 + */ public static class TdEngineProperties { /** * Whether the TdEngine data store is enabled @@ -451,6 +466,9 @@ public void setTableStrColumnDefineMaxLength(int tableStrColumnDefineMaxLength) } } + /** + * VictoriaMetrics配置信息 + */ public static class VictoriaMetricsProperties { /** * Whether the VictoriaMetrics data store is enabled @@ -503,6 +521,9 @@ public void setPassword(String password) { } + /** + * Redis配置信息 + */ public static class RedisProperties { /** * redis数据存储是否启动 @@ -566,6 +587,9 @@ public void setPassword(String password) { } } + /** + * IoTDB配置信息 + */ public static class IotDbProperties { /** * Whether the iotDB data store is enabled @@ -698,6 +722,9 @@ public void setExpireTime(String expireTime) { } } + /** + * GrepTimeDB配置信息 + */ public static class GreptimeProperties { /** * Whether the GrepTimeDB data store is enabled diff --git a/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/HistoryGrepTimeDbDataStorage.java b/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/HistoryGrepTimeDbDataStorage.java index 3e680230f0b..2a21c9de4bc 100644 --- a/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/HistoryGrepTimeDbDataStorage.java +++ b/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/HistoryGrepTimeDbDataStorage.java @@ -63,7 +63,8 @@ public class HistoryGrepTimeDbDataStorage extends AbstractHistoryDataStorage { private static final String QUERY_INSTANCE_SQL = "SELECT DISTINCT instance FROM %s WHERE ts >= now() - interval '1' WEEK"; private static final String QUERY_HISTORY_INTERVAL_WITH_INSTANCE_SQL - = "SELECT first, avg ,max, min FROM (SELECT \"%s\" as first FROM %s WHERE monitor_id = %s and ts >= %s and ts < %s ORDER BY ts LIMIT 1) LEFT JOIN (SELECT avg(\"%s\") as avg, min(\"%s\") as min, max(\"%s\") as max FROM %s WHERE ts >= %s and ts < %s) ON 1=1"; + = "SELECT first, avg ,max, min FROM (SELECT \"%s\" as first FROM %s WHERE monitor_id = %s and ts >= %s" + + " and ts < %s ORDER BY ts LIMIT 1) LEFT JOIN (SELECT avg(\"%s\") as avg, min(\"%s\") as min, max(\"%s\") as max FROM %s WHERE ts >= %s and ts < %s) ON 1=1"; private static final String TABLE_NOT_EXIST = "not exist"; private static final String DATABASE_NOT_EXIST = "not exist"; private GreptimeDB greptimeDb; diff --git a/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java b/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java index 5071cbb0443..6b2d4a42094 100644 --- a/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java +++ b/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java @@ -162,6 +162,9 @@ void saveData(CollectRep.MetricsData metricsData) { .int32(null); break; } + default: + historyBuilder.metricType(CommonConstants.TYPE_NUMBER); + break; } } else { switch (fieldType) { @@ -182,6 +185,10 @@ void saveData(CollectRep.MetricsData metricsData) { .int32(Integer.parseInt(columnValue)); break; } + default: + historyBuilder.metricType(CommonConstants.TYPE_NUMBER) + .dou(Double.parseDouble(columnValue)); + break; } if (field.getLabel()) { diff --git a/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/HistoryVictoriaMetricsDataStorage.java b/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/HistoryVictoriaMetricsDataStorage.java index f70026d04e1..4fcd30463f1 100644 --- a/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/HistoryVictoriaMetricsDataStorage.java +++ b/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/HistoryVictoriaMetricsDataStorage.java @@ -446,7 +446,10 @@ public Map> getHistoryIntervalMetricData(Long monitorId, Str } return instanceValuesMap; } - + + /** + * victoria metrics content + */ @Data @Builder @AllArgsConstructor @@ -470,6 +473,9 @@ public static final class VictoriaMetricsContent { private Long[] timestamps; } + /** + * victoria metrics query content + */ @Data @Builder @AllArgsConstructor @@ -479,7 +485,10 @@ public static final class VictoriaMetricsQueryContent { private String status; private ContentData data; - + + /** + * content data + */ @Data @AllArgsConstructor @NoArgsConstructor @@ -489,6 +498,9 @@ public static final class ContentData { private List result; + /** + * content + */ @Data @AllArgsConstructor @NoArgsConstructor diff --git a/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/RealTimeRedisDataStorage.java b/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/RealTimeRedisDataStorage.java index 3b8190177ea..57fa103f71e 100644 --- a/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/RealTimeRedisDataStorage.java +++ b/warehouse/src/main/java/org/dromara/hertzbeat/warehouse/store/RealTimeRedisDataStorage.java @@ -56,9 +56,11 @@ public RealTimeRedisDataStorage(WarehouseProperties properties) { this.serverAvailable = initRedisClient(properties); this.db = getRedisSelectDb(properties); } + private Integer getRedisSelectDb(WarehouseProperties properties){ return properties.getStore().getRedis().getDb(); } + @Override public CollectRep.MetricsData getCurrentMetricsData(@NonNull Long monitorId, @NonNull String metric) { RedisCommands commands = connection.sync();