This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 170
Fix broken pushdown queries #1098
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,13 +163,63 @@ func buildSingleMetricSamplesQuery(metadata *evalMetadata) (string, []interface{ | |
orderByClause = "ORDER BY series_id, time" | ||
} | ||
} | ||
|
||
// On query time ranges in Prometheus: | ||
// | ||
// When we receive a range query the [`start`, `end`] range specifies the | ||
// timespan that we are expected to deliver results for. Similarly, when we | ||
// receive an instant query, the `time` parameter specifies the instant | ||
// that we are expected to deliver a result for. | ||
// | ||
// Depending on the query, we may need to look further back in time than | ||
// the `start` to deliver results from `start` onwards. For instance, a | ||
// range query such as `rate(metric_one[5m])` in the range `(T1, T2)` will | ||
// deliver results between T1 and T2, but it has a 5-minute range on | ||
// `metric_one`. In order to deliver a result for time T1, we need to get | ||
// `metric_one`'s values at (T1 - 5m) and T1. Similarly, an instant query | ||
// for `metric_one` at timestamp T3 requires looking back the lookback time | ||
// (the default is 5 minutes) to find the most recent samples. | ||
// We call this point in time `scan_start`: the point in time at which we | ||
// need to start scanning the underlying data to calculate the result. This | ||
// could look as follows: | ||
// | ||
// scan_start start end | ||
// |-----------|--------------------| | ||
// | ||
// How do the following time ranges relate to scan_start, start, and end: | ||
// - metadata.timeFilter | ||
// - metadata.selectHints.{Start, End} | ||
// | ||
// The timeFilter's time range is determined by `findMinMaxTime` on the | ||
// expression being evaluated, and is the widest span of _all_ | ||
// subexpressions (effectively [min(scan_start), end]). | ||
// This means that, for instance, if the following range selector and | ||
// instant selector are combined: rate(metric_one[1m]) / metric_one, the | ||
// timeFilter.start is T1 - 5m (assuming default lookback time of 5m). | ||
// Note: This is problematic because for metric_one[1m] we actually want to | ||
// query over [T1 - 1m, end], not [T1 - 5m, end]. | ||
// | ||
// The selectHints' time range is calculated by `getTimeRangesForSelector`, | ||
// which determines the correct `scan_start` for the current expression. | ||
|
||
filter := metadata.timeFilter | ||
sh := metadata.selectHints | ||
var start, end string | ||
// selectHints are non-nil when the query was initiated through the `query` | ||
// or `query_range` endpoints. They are nil when the query was initiated | ||
// through the `read` (remote read) endpoint. | ||
if sh != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Since this only apply when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
start, end = toRFC3339Nano(sh.Start), toRFC3339Nano(sh.End) | ||
} else { | ||
start, end = metadata.timeFilter.start, metadata.timeFilter.end | ||
} | ||
|
||
finalSQL := fmt.Sprintf(template, | ||
pgx.Identifier{filter.schema, filter.metric}.Sanitize(), | ||
pgx.Identifier{schema.PromDataSeries, filter.seriesTable}.Sanitize(), | ||
strings.Join(cases, " AND "), | ||
filter.start, | ||
filter.end, | ||
start, | ||
end, | ||
strings.Join(selectorClauses, ", "), | ||
strings.Join(selectors, ", "), | ||
orderByClause, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
range queries do not have lookbacks. The range is as stated and the only thing that matters is the bucket width.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍