tsdb: sql data sources should handle time ranges before epoch start correctly

This commit is contained in:
Marcus Efraimsson
2018-04-12 18:53:12 +02:00
parent a3874ce2c7
commit f5586b1270
7 changed files with 546 additions and 228 deletions

View File

@@ -83,11 +83,11 @@ func (m *PostgresMacroEngine) evaluateMacro(name string, args []string) (string,
if len(args) == 0 {
return "", fmt.Errorf("missing time column argument for macro %v", name)
}
return fmt.Sprintf("extract(epoch from %s) BETWEEN %d AND %d", args[0], int64(m.TimeRange.GetFromAsMsEpoch()/1000), int64(m.TimeRange.GetToAsMsEpoch()/1000)), nil
return fmt.Sprintf("extract(epoch from %s) BETWEEN %d AND %d", args[0], int64(m.TimeRange.GetFromAsSecondsEpoch()), int64(m.TimeRange.GetToAsSecondsEpoch())), nil
case "__timeFrom":
return fmt.Sprintf("to_timestamp(%d)", int64(m.TimeRange.GetFromAsMsEpoch()/1000)), nil
return fmt.Sprintf("to_timestamp(%d)", int64(m.TimeRange.GetFromAsSecondsEpoch())), nil
case "__timeTo":
return fmt.Sprintf("to_timestamp(%d)", int64(m.TimeRange.GetToAsMsEpoch()/1000)), nil
return fmt.Sprintf("to_timestamp(%d)", int64(m.TimeRange.GetToAsSecondsEpoch())), nil
case "__timeGroup":
if len(args) < 2 {
return "", fmt.Errorf("macro %v needs time column and interval and optional fill value", name)
@@ -114,11 +114,11 @@ func (m *PostgresMacroEngine) evaluateMacro(name string, args []string) (string,
if len(args) == 0 {
return "", fmt.Errorf("missing time column argument for macro %v", name)
}
return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], int64(m.TimeRange.GetFromAsMsEpoch()/1000), args[0], int64(m.TimeRange.GetToAsMsEpoch()/1000)), nil
return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], int64(m.TimeRange.GetFromAsSecondsEpoch()), args[0], int64(m.TimeRange.GetToAsSecondsEpoch())), nil
case "__unixEpochFrom":
return fmt.Sprintf("%d", int64(m.TimeRange.GetFromAsMsEpoch()/1000)), nil
return fmt.Sprintf("%d", int64(m.TimeRange.GetFromAsSecondsEpoch())), nil
case "__unixEpochTo":
return fmt.Sprintf("%d", int64(m.TimeRange.GetToAsMsEpoch()/1000)), nil
return fmt.Sprintf("%d", int64(m.TimeRange.GetToAsSecondsEpoch())), nil
default:
return "", fmt.Errorf("Unknown macro %v", name)
}