mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmselect/prometheus: support d
, w
and y
suffixes for durations passed to step
in /api/v1/query_range
like Prometheus does
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/641
This commit is contained in:
parent
bd4299fafe
commit
20d0c41ac5
1 changed files with 4 additions and 4 deletions
|
@ -977,14 +977,14 @@ func getTime(r *http.Request, argKey string, defaultValue int64) (int64, error)
|
|||
return maxTimeMsecs, nil
|
||||
}
|
||||
// Try parsing duration relative to the current time
|
||||
d, err1 := time.ParseDuration(argValue)
|
||||
d, err1 := metricsql.DurationValue(argValue, 0)
|
||||
if err1 != nil {
|
||||
return 0, fmt.Errorf("cannot parse %q=%q: %w", argKey, argValue, err)
|
||||
}
|
||||
if d > 0 {
|
||||
d = -d
|
||||
}
|
||||
t = time.Now().Add(d)
|
||||
t = time.Now().Add(time.Duration(d) * time.Millisecond)
|
||||
}
|
||||
secs = float64(t.UnixNano()) / 1e9
|
||||
}
|
||||
|
@ -1019,11 +1019,11 @@ func getDuration(r *http.Request, argKey string, defaultValue int64) (int64, err
|
|||
secs, err := strconv.ParseFloat(argValue, 64)
|
||||
if err != nil {
|
||||
// Try parsing string format
|
||||
d, err := time.ParseDuration(argValue)
|
||||
d, err := metricsql.DurationValue(argValue, 0)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("cannot parse %q=%q: %w", argKey, argValue, err)
|
||||
}
|
||||
secs = d.Seconds()
|
||||
secs = float64(d) / 1000
|
||||
}
|
||||
msecs := int64(secs * 1e3)
|
||||
if msecs <= 0 || msecs > maxDurationMsecs {
|
||||
|
|
Loading…
Reference in a new issue