diff --git a/README.md b/README.md index 464a18bda..987386529 100644 --- a/README.md +++ b/README.md @@ -2326,7 +2326,7 @@ Pass `-help` to VictoriaMetrics in order to see the list of supported command-li -search.graphiteStorageStep duration The interval between datapoints stored in the database. It is used at Graphite Render API handler for normalizing the interval between datapoints in case it isn't normalized. It can be overridden by sending 'storage_step' query arg to /render API or by sending the desired interval via 'Storage-Step' http header during querying /render API. This flag is available only in VictoriaMetrics enterprise. See https://docs.victoriametrics.com/enterprise.html (default 10s) -search.latencyOffset duration - The time when data points become visible in query results after the collection. Too small value can result in incomplete last points for query results (default 30s) + The time when data points become visible in query results after the collection. It can be overridden on per-query basis via latency_offset arg. Too small value can result in incomplete last points for query results (default 30s) -search.logSlowQueryDuration duration Log queries with execution time exceeding this value. Zero disables slow query logging (default 5s) -search.maxConcurrentRequests int diff --git a/app/vmselect/prometheus/prometheus.go b/app/vmselect/prometheus/prometheus.go index 77c7e2991..857f12a25 100644 --- a/app/vmselect/prometheus/prometheus.go +++ b/app/vmselect/prometheus/prometheus.go @@ -30,6 +30,7 @@ import ( var ( latencyOffset = flag.Duration("search.latencyOffset", time.Second*30, "The time when data points become visible in query results after the collection. "+ + "It can be overridden on per-query basis via latency_offset arg. "+ "Too small value can result in incomplete last points for query results") maxQueryLen = flagutil.NewBytes("search.maxQueryLen", 16*1024, "The maximum search query length in bytes") maxLookback = flag.Duration("search.maxLookback", 0, "Synonym to -search.lookback-delta from Prometheus. "+ @@ -735,7 +736,7 @@ func QueryHandler(qt *querytracer.Tracer, startTime time.Time, w http.ResponseWr return nil } - queryOffset := getLatencyOffsetMilliseconds() + queryOffset := getLatencyOffsetMilliseconds(r) if !searchutils.GetBool(r, "nocache") && ct-start < queryOffset && start-ct < queryOffset { // Adjust start time only if `nocache` arg isn't set. // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/241 @@ -860,7 +861,7 @@ func queryRangeHandler(qt *querytracer.Tracer, startTime time.Time, w http.Respo return err } if step < maxStepForPointsAdjustment.Milliseconds() { - queryOffset := getLatencyOffsetMilliseconds() + queryOffset := getLatencyOffsetMilliseconds(r) if ct-queryOffset < end { result = adjustLastPoints(result, ct-queryOffset, ct+step) } @@ -1000,12 +1001,16 @@ func getRoundDigits(r *http.Request) int { return n } -func getLatencyOffsetMilliseconds() int64 { +func getLatencyOffsetMilliseconds(r *http.Request) int64 { d := latencyOffset.Milliseconds() if d <= 1000 { d = 1000 } - return d + lo, err := searchutils.GetDuration(r, "latency_offset", d) + if err != nil { + return d + } + return lo } // QueryStatsHandler returns query stats at `/api/v1/status/top_queries` diff --git a/app/vmselect/prometheus/prometheus_test.go b/app/vmselect/prometheus/prometheus_test.go index 70d2b06f2..ae08ce31d 100644 --- a/app/vmselect/prometheus/prometheus_test.go +++ b/app/vmselect/prometheus/prometheus_test.go @@ -2,8 +2,10 @@ package prometheus import ( "math" + "net/http" "reflect" "testing" + "time" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/netstorage" ) @@ -195,3 +197,17 @@ func TestAdjustLastPoints(t *testing.T) { }, }) } + +func TestGetLatencyOffsetMilliseconds(t *testing.T) { + f := func(got, exp int64) { + if got != exp { + t.Fatalf("expected offset %d; got %d", exp, got) + } + } + + r, _ := http.NewRequest(http.MethodGet, "http://localhost", nil) + f(getLatencyOffsetMilliseconds(r), latencyOffset.Milliseconds()) + + r, _ = http.NewRequest(http.MethodGet, "http://localhost?latency_offset=10s", nil) + f(getLatencyOffsetMilliseconds(r), 10*time.Second.Milliseconds()) +} diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index f5f5e399b..88867a57a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -15,8 +15,9 @@ The following tip changes can be tested by building VictoriaMetrics components f ## tip -* BUGFIX: allow specifying values bigger than 2GiB to the following command-line flag values on 32-bit architectures (`386` and `arm`): `-storage.minFreeDiskSpaceBytes` and `-remoteWrite.maxDiskUsagePerURL`. Previously values bigger than 2GiB were incorrectly truncated on these architectures. +* FEATURE: `vmselect`: support overriding of `-search.latencyOffset` value via URL param `latency_offset`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3481). +* BUGFIX: allow specifying values bigger than 2GiB to the following command-line flag values on 32-bit architectures (`386` and `arm`): `-storage.minFreeDiskSpaceBytes` and `-remoteWrite.maxDiskUsagePerURL`. Previously values bigger than 2GiB were incorrectly truncated on these architectures. ## [v1.85.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.85.1) diff --git a/docs/Cluster-VictoriaMetrics.md b/docs/Cluster-VictoriaMetrics.md index ce5724c2c..802614672 100644 --- a/docs/Cluster-VictoriaMetrics.md +++ b/docs/Cluster-VictoriaMetrics.md @@ -1036,7 +1036,7 @@ Below is the output for `/path/to/vmselect -help`: -search.graphiteStorageStep duration The interval between datapoints stored in the database. It is used at Graphite Render API handler for normalizing the interval between datapoints in case it isn't normalized. It can be overridden by sending 'storage_step' query arg to /render API or by sending the desired interval via 'Storage-Step' http header during querying /render API. This flag is available only in VictoriaMetrics enterprise. See https://docs.victoriametrics.com/enterprise.html (default 10s) -search.latencyOffset duration - The time when data points become visible in query results after the collection. Too small value can result in incomplete last points for query results (default 30s) + The time when data points become visible in query results after the collection. It can be overridden on per-query basis via latency_offset arg. Too small value can result in incomplete last points for query results (default 30s) -search.logSlowQueryDuration duration Log queries with execution time exceeding this value. Zero disables slow query logging (default 5s) -search.maxConcurrentRequests int diff --git a/docs/README.md b/docs/README.md index 697139fad..5a62ab9c8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2327,7 +2327,7 @@ Pass `-help` to VictoriaMetrics in order to see the list of supported command-li -search.graphiteStorageStep duration The interval between datapoints stored in the database. It is used at Graphite Render API handler for normalizing the interval between datapoints in case it isn't normalized. It can be overridden by sending 'storage_step' query arg to /render API or by sending the desired interval via 'Storage-Step' http header during querying /render API. This flag is available only in VictoriaMetrics enterprise. See https://docs.victoriametrics.com/enterprise.html (default 10s) -search.latencyOffset duration - The time when data points become visible in query results after the collection. Too small value can result in incomplete last points for query results (default 30s) + The time when data points become visible in query results after the collection. It can be overridden on per-query basis via latency_offset arg. Too small value can result in incomplete last points for query results (default 30s) -search.logSlowQueryDuration duration Log queries with execution time exceeding this value. Zero disables slow query logging (default 5s) -search.maxConcurrentRequests int diff --git a/docs/Single-server-VictoriaMetrics.md b/docs/Single-server-VictoriaMetrics.md index 6643cef71..dcb73dac7 100644 --- a/docs/Single-server-VictoriaMetrics.md +++ b/docs/Single-server-VictoriaMetrics.md @@ -2330,7 +2330,7 @@ Pass `-help` to VictoriaMetrics in order to see the list of supported command-li -search.graphiteStorageStep duration The interval between datapoints stored in the database. It is used at Graphite Render API handler for normalizing the interval between datapoints in case it isn't normalized. It can be overridden by sending 'storage_step' query arg to /render API or by sending the desired interval via 'Storage-Step' http header during querying /render API. This flag is available only in VictoriaMetrics enterprise. See https://docs.victoriametrics.com/enterprise.html (default 10s) -search.latencyOffset duration - The time when data points become visible in query results after the collection. Too small value can result in incomplete last points for query results (default 30s) + The time when data points become visible in query results after the collection. It can be overridden on per-query basis via latency_offset arg. Too small value can result in incomplete last points for query results (default 30s) -search.logSlowQueryDuration duration Log queries with execution time exceeding this value. Zero disables slow query logging (default 5s) -search.maxConcurrentRequests int