提交 bea678fd 编写于 作者: X xiangdong huang 提交者: Xiangdong Huang

fix grafana connect does not use correct time unit

上级 f9606b0a
......@@ -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
```
......
......@@ -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);
......
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册