You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hx...@apache.org on 2020/05/05 01:31:00 UTC
[incubator-iotdb] 01/02: fix grafana connect does not use correct
time unit
This is an automated email from the ASF dual-hosted git repository.
hxd pushed a commit to branch rel/0.9
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit bea678fd41b3bddbfd6f04906718dd485c2ddd18
Author: xiangdong huang <sa...@gmail.com>
AuthorDate: Sat May 2 22:34:28 2020 +0800
fix grafana connect does not use correct time unit
---
.../UserGuide/7-Ecosystem Integration/1-Grafana.md | 2 +-
.../iotdb/web/grafana/dao/impl/BasicDaoImpl.java | 36 ++++++++++++----------
grafana/src/main/resources/application.properties | 3 +-
3 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/docs/UserGuide/7-Ecosystem Integration/1-Grafana.md b/docs/UserGuide/7-Ecosystem Integration/1-Grafana.md
index 5ad4e9b..2ba605f 100644
--- a/docs/UserGuide/7-Ecosystem Integration/1-Grafana.md
+++ b/docs/UserGuide/7-Ecosystem Integration/1-Grafana.md
@@ -153,7 +153,7 @@ isDownSampling=true
# defaut sampling intervals
interval=1m
# aggregation function to use to downsampling the data
-# COUNT, FIRST_VALUE, LAST_VALUE, MAX_TIME, MAX_VALUE, AVG, MIN_TIME, MIN_VALUE, NOW, SUM
+# COUNT, FIRST, LAST, MAX_TIME, MAX_VALUE, AVG, MIN_TIME, MIN_VALUE, NOW, SUM
function=avg
```
diff --git a/grafana/src/main/java/org/apache/iotdb/web/grafana/dao/impl/BasicDaoImpl.java b/grafana/src/main/java/org/apache/iotdb/web/grafana/dao/impl/BasicDaoImpl.java
index dde404f..c43ca72 100644
--- a/grafana/src/main/java/org/apache/iotdb/web/grafana/dao/impl/BasicDaoImpl.java
+++ b/grafana/src/main/java/org/apache/iotdb/web/grafana/dao/impl/BasicDaoImpl.java
@@ -53,7 +53,10 @@ public class BasicDaoImpl implements BasicDao {
private final JdbcTemplate jdbcTemplate;
- private static long TIMESTAMP_RADIX = 1L;
+ private static long TIMESTAMP_RADIX = -1L;
+
+ @Value("${timestamp_precision}")
+ private String timestampPrecision;
@Value("${isDownSampling}")
private boolean isDownSampling;
@@ -68,19 +71,6 @@ public class BasicDaoImpl implements BasicDao {
@Autowired
public BasicDaoImpl(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
- Properties properties = new Properties();
- String tsPrecision = properties.getProperty("timestamp_precision", "ms");
- switch (tsPrecision) {
- case "us":
- TIMESTAMP_RADIX = 1000;
- break;
- case "ns":
- TIMESTAMP_RADIX = 1000_000;
- break;
- default:
- TIMESTAMP_RADIX = 1;
- }
- logger.info("Use timestamp precision {}", tsPrecision);
}
@Override
@@ -108,6 +98,19 @@ public class BasicDaoImpl implements BasicDao {
*/
@Override
public List<TimeValues> querySeries(String s, Pair<ZonedDateTime, ZonedDateTime> timeRange) {
+ if(TIMESTAMP_RADIX == -1) {
+ switch (timestampPrecision) {
+ case "us":
+ TIMESTAMP_RADIX = 1000;
+ break;
+ case "ns":
+ TIMESTAMP_RADIX = 1000_000;
+ break;
+ default:
+ TIMESTAMP_RADIX = 1;
+ }
+ logger.info("Use timestamp precision {}", timestampPrecision);
+ }
try {
return querySeriesInternal(s, timeRange, function);
} catch (Exception e) {
@@ -140,8 +143,9 @@ public class BasicDaoImpl implements BasicDao {
sql = String.format(
"SELECT " + function
+ "(%s) FROM root.%s WHERE time > %d and time < %d group by (%s, [%d, %d])",
- s.substring(s.lastIndexOf('.') + 1), s.substring(0, s.lastIndexOf('.')), from, to,
- interval, from, to);
+ s.substring(s.lastIndexOf('.') + 1), s.substring(0, s.lastIndexOf('.')),
+ from * TIMESTAMP_RADIX, to * TIMESTAMP_RADIX,
+ interval, from * TIMESTAMP_RADIX, to * TIMESTAMP_RADIX);
columnName = function + "(root." + s + ")";
}
logger.info(sql);
diff --git a/grafana/src/main/resources/application.properties b/grafana/src/main/resources/application.properties
index 9401a32..dfdef16 100644
--- a/grafana/src/main/resources/application.properties
+++ b/grafana/src/main/resources/application.properties
@@ -31,6 +31,7 @@ isDownSampling=true
# defaut sampling intervals
interval=1m
# aggregation function to use to downsampling the data
-# COUNT, FIRST_VALUE, LAST_VALUE, MAX_TIME, MAX_VALUE, AVG, MIN_TIME, MIN_VALUE, NOW, SUM
+# COUNT, FIRST, LAST, MAX_TIME, MAX_VALUE, AVG, MIN_TIME, MIN_VALUE, NOW, SUM
# If it does fail (e.g. due to applying AVG to boolean) it will Fallback to LAST
+# notice that from v0.10 on, this parameter is deprecated
function=AVG
\ No newline at end of file