From 4073bb3303ec21d5b606eadb769fd05651d89add Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 16 Jan 2024 18:58:29 +0200 Subject: [PATCH] lib/httputils: handle step=undefined query arg as an empty value This is needed for Grafana, which may send step=undefined when working with alerting rules and instant queries. --- lib/httputils/duration.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/httputils/duration.go b/lib/httputils/duration.go index 89d31feb5..4fdd05c4a 100644 --- a/lib/httputils/duration.go +++ b/lib/httputils/duration.go @@ -14,6 +14,10 @@ func GetDuration(r *http.Request, argKey string, defaultValue int64) (int64, err if len(argValue) == 0 { return defaultValue, nil } + if argValue == "undefined" { + // This hack is needed for Grafana, which may send undefined value + return defaultValue, nil + } secs, err := strconv.ParseFloat(argValue, 64) if err != nil { // Try parsing string format