From 4f526cc81677bf3e897571ca7adacd6b05f1d044 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 22 Jul 2020 16:26:16 +0300 Subject: [PATCH] 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 --- app/vmselect/prometheus/prometheus.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/vmselect/prometheus/prometheus.go b/app/vmselect/prometheus/prometheus.go index e19b6166a..e34ea5668 100644 --- a/app/vmselect/prometheus/prometheus.go +++ b/app/vmselect/prometheus/prometheus.go @@ -891,14 +891,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 } @@ -933,11 +933,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 {