app/vmselect/prometheus: allow passing relative time to start, end and time args of /api/v1/* queries

This commit is contained in:
Aliaksandr Valialkin 2020-03-29 21:56:37 +03:00
parent cb8696699a
commit c6cbc0bd19

View File

@ -923,8 +923,16 @@ func getTime(r *http.Request, argKey string, defaultValue int64) (int64, error)
case prometheusMaxTimeFormatted: case prometheusMaxTimeFormatted:
return maxTimeMsecs, nil return maxTimeMsecs, nil
} }
// Try parsing duration relative to the current time
d, err1 := time.ParseDuration(argValue)
if err1 != nil {
return 0, fmt.Errorf("cannot parse %q=%q: %s", argKey, argValue, err) return 0, fmt.Errorf("cannot parse %q=%q: %s", argKey, argValue, err)
} }
if d > 0 {
d = -d
}
t = time.Now().Add(d)
}
secs = float64(t.UnixNano()) / 1e9 secs = float64(t.UnixNano()) / 1e9
} }
msecs := int64(secs * 1e3) msecs := int64(secs * 1e3)