feat: limit recent queries - #5682
Conversation
Signed-off-by: Joe Elliott <number101010@gmail.com>
Co-authored-by: Joe Elliott <joe.elliott@grafana.com>
Co-authored-by: Joe Elliott <joe.elliott@grafana.com>
default to the query_backend_after
|
@joe-elliott I was able to make it work without the extra config |
joe-elliott
left a comment
There was a problem hiding this comment.
PR looking good close to merging. Can we go ahead and make the config change now? Also needs a changelog.
| return nil, fmt.Errorf("QueryBackendAfter (%v) must be greater than query end cutoff (%v)", cfg.Search.Sharder.QueryBackendAfter, cfg.QueryEndCutoff) | ||
| } | ||
| if cfg.QueryEndCutoff > cfg.Metrics.Sharder.QueryBackendAfter { | ||
| return nil, fmt.Errorf("QueryBackendAfter (%v) must be greater than query end cutoff (%v)", cfg.Metrics.Sharder.QueryBackendAfter, cfg.QueryEndCutoff) |
There was a problem hiding this comment.
same check 2x? remove the second one?
There was a problem hiding this comment.
It´s not really duplicated since the QueryBackendAfter can be different for search and metrics. Nevertheless we already discussed moving this property up. I will remove the second one
There was a problem hiding this comment.
oh, good call. i didn't notice. i'm good with the double check
joe-elliott
left a comment
There was a problem hiding this comment.
one cleanup request, but looks good otherwise
* add adjustRangeWare Signed-off-by: Joe Elliott <number101010@gmail.com> * improve code and added more tests * fixes in the tests * remove strict validation for now * move the logic to the frontend * fix integration tets * add values explicitly * fix query range tests * fix unit tests * fix more tests * fix more tests * disable for tags * revert last commit * do not apply when the start and end are missing for now * try to fix more tests * fix more tests * fix more tests * fix more tests * bring back empty start end handling * fix more tests * fix multitenant tests * fix https test * fix api tests * fix deployment tests * simplify tests * fix query range test * fix another test * remove commented code * disable test * fix search propagates * fix search shard test * fix another test * last one? * test querybackend after * Update modules/livestore/config.go Co-authored-by: Joe Elliott <joe.elliott@grafana.com> * Update modules/frontend/frontend.go Co-authored-by: Joe Elliott <joe.elliott@grafana.com> * fmt * Remove the new default start query parameter and default to the query_backend_after * remove precission since its not used * cleanup test configs * move config one level up * changelog * remove validation * defaulted to 0 * manifest * add more cutoff --------- Signed-off-by: Joe Elliott <number101010@gmail.com> Co-authored-by: Joe Elliott <number101010@gmail.com> Co-authored-by: Joe Elliott <joe.elliott@grafana.com>
* add adjustRangeWare Signed-off-by: Joe Elliott <number101010@gmail.com> * improve code and added more tests * fixes in the tests * remove strict validation for now * move the logic to the frontend * fix integration tets * add values explicitly * fix query range tests * fix unit tests * fix more tests * fix more tests * disable for tags * revert last commit * do not apply when the start and end are missing for now * try to fix more tests * fix more tests * fix more tests * fix more tests * bring back empty start end handling * fix more tests * fix multitenant tests * fix https test * fix api tests * fix deployment tests * simplify tests * fix query range test * fix another test * remove commented code * disable test * fix search propagates * fix search shard test * fix another test * last one? * test querybackend after * Update modules/livestore/config.go Co-authored-by: Joe Elliott <joe.elliott@grafana.com> * Update modules/frontend/frontend.go Co-authored-by: Joe Elliott <joe.elliott@grafana.com> * fmt * Remove the new default start query parameter and default to the query_backend_after * remove precission since its not used * cleanup test configs * move config one level up * changelog * remove validation * defaulted to 0 * manifest * add more cutoff --------- Signed-off-by: Joe Elliott <number101010@gmail.com> Co-authored-by: Joe Elliott <number101010@gmail.com> Co-authored-by: Joe Elliott <joe.elliott@grafana.com>
What this PR does:
This PR addresses an issue where queries using recent timestamps (especially "now") can return inaccurate or inconsistent results due to laggy replicas and incomplete data ingestion.
A new middleware operates transparently between the API layer and the queriers, ensuring that external interfaces remain unchanged while internal request processing becomes more robust and consistent.
This change ensures that Tempo queries return consistent, accurate results by avoiding the "dangerous zone" of very recent data that may be incomplete across replicas, while standardizing how time ranges are handled throughout the query pipeline.
Problem
When search and metrics queries use very recent end times (like
time.Now()), they can hit incomplete data because:This leads to unreliable query results.
Solution
Introduces configurable time for clamping the end range:
query_end_cutoff,: Prevents queries from using end times too close to "now" (defaults to 30s)Key Behavioral Changes
All requests now include explicit start/end parameters: Previously, requests without time ranges would be forwarded to queriers as-is. Now, the frontend middleware ensures every request to queriers includes clamped
startandendparameters."since" parameter handling: The search API's
sinceparameter (e.g.,since=1h) is now processed by the frontend and converted to explicitstartandendparameters before forwarding to queriersGRPC requests with empty start/end: GRPC requests that previously had default/empty start and end times are now resolved to explicit timestamp values during the clamping process, ensuring consistent behavior across all query types.
Implementation Details
NewAdjustStartEndWareapplies clamping to all incoming requests before they reach querierssince) are converted to absolute timestampsTest Updates
Updated integration tests to account for the new clamping behavior:
Breaking Changes
None. This change is fully backward compatible:
since) - the processing is internalNot a single line of business logic has changed
Checklist
CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]