From 07c622633476d61e9ceef646a41e9e3f06fd7fd4 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 21 Sep 2020 21:23:43 +0300 Subject: [PATCH] app/vmselect: use `time` value rounded to seconds if it isnt passed to `/api/v1/query` Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/720 --- app/vmselect/searchutils/searchutils.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/vmselect/searchutils/searchutils.go b/app/vmselect/searchutils/searchutils.go index aa9140fd5a..c24e01c83a 100644 --- a/app/vmselect/searchutils/searchutils.go +++ b/app/vmselect/searchutils/searchutils.go @@ -26,11 +26,19 @@ var ( "see also -search.maxQueryDuration and -search.denyPartialResponse command-line flags") ) +func roundToSeconds(ms int64) int64 { + return ms - ms%1000 +} + // GetTime returns time from the given argKey query arg. -func GetTime(r *http.Request, argKey string, defaultValue int64) (int64, error) { +// +// If argKey is missing in r, then defaultMs rounded to seconds is returned. +// The rounding is needed in order to align query results in Grafana +// executed at different times. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/720 +func GetTime(r *http.Request, argKey string, defaultMs int64) (int64, error) { argValue := r.FormValue(argKey) if len(argValue) == 0 { - return defaultValue, nil + return roundToSeconds(defaultMs), nil } secs, err := strconv.ParseFloat(argValue, 64) if err != nil {