Skip to content

Add configurable Max query time range limit#9386

Open
nishantmonu51 wants to merge 2 commits intomainfrom
Nishant-Bangarwa/dashboard-max-time-range
Open

Add configurable Max query time range limit#9386
nishantmonu51 wants to merge 2 commits intomainfrom
Nishant-Bangarwa/dashboard-max-time-range

Conversation

@nishantmonu51
Copy link
Copy Markdown
Collaborator

@nishantmonu51 nishantmonu51 commented May 5, 2026

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:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

@nishantmonu51 nishantmonu51 requested review from a team as code owners May 5, 2026 12:01
@nishantmonu51 nishantmonu51 requested a review from AdityaHegde May 5, 2026 12:08
@nishantmonu51
Copy link
Copy Markdown
Collaborator Author

@AdityaHegde : can you help review and take t his further ?

// 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) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants