Add configurable Max query time range limit#9386
Open
nishantmonu51 wants to merge 2 commits intomainfrom
Open
Conversation
Collaborator
Author
|
@AdityaHegde : can you help review and take t his further ? |
AdityaHegde
requested changes
May 5, 2026
| // An explicit caller-provided QueryLimits.MaxTimeRangeDays takes precedence over the metrics view's | ||
| // max_query_time_range spec property — this matters for the AI tool path which tightens the cap via | ||
| // the rill.ai.max_time_range_days env var. | ||
| func (e *Executor) maxTimeRange(qry *metricsview.Query) (time.Duration, string) { |
Collaborator
There was a problem hiding this comment.
This method feels incorrect. How about taking metricsview.TimeRange and returning error instead of string?
| fmt.Sprintf("time range for query cannot exceed %d days, configured via the rill.ai.max_time_range_days env var", days) | ||
| } | ||
| if e.metricsView != nil && e.metricsView.MaxQueryTimeRange != "" { | ||
| d, err := duration.ParseISO8601(e.metricsView.MaxQueryTimeRange) |
Collaborator
There was a problem hiding this comment.
Lets use rilltime library to resolve the duration.
| // isoDurationToDays approximates an ISO 8601 duration (e.g. "P90D", "P3M") in days, | ||
| // matching the executor's StandardDuration.EstimateNative() heuristic (1 month ≈ 30 days, 1 year ≈ 365 days). | ||
| // Returns NaN if the input cannot be parsed. | ||
| export function isoDurationToDays(isoDuration: string): number { |
Collaborator
There was a problem hiding this comment.
We shouldnt redo what rilltime already does for us. Lets use that instead. Note that this will add an additional query. We can instead return it in MetricsViewTimeRange/MetricsViewTimeRanges if max_query_time_range is defined on metrics view.
With this change most components should take luxon.Interval and use that to calculate caps.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Today a user can ask a metrics view to aggregate data over an arbitrarily wide time range.
For datasets with high cardinality or fine-grained time dimensions this is expensive and can starve the OLAP engine.
This PR introduces a per-metrics-view safety cap: a maximum time span that any single interactive query can cover (e.g., "no query may span more than 90 days").
It is configurable max time range limit on the metrics view.
Checklist: