Skip to content

[APP-450] feat: guard time series queries with minimum and maximum granularity#8493

Merged
briangregoryholmes merged 52 commits intomainfrom
bgh/determine-max-interval-precision
Feb 3, 2026
Merged

[APP-450] feat: guard time series queries with minimum and maximum granularity#8493
briangregoryholmes merged 52 commits intomainfrom
bgh/determine-max-interval-precision

Conversation

@briangregoryholmes
Copy link
Contributor

@briangregoryholmes briangregoryholmes commented Dec 11, 2025

This PR adds a guard around the min/max precision allowed for time series data. It also limits the options provided in the time series aggregation selector on Explore to only those we deem "valid".

The intention of this PR is to adhere to the following heuristic:

  1. Determine the allowed grains for a given interval based on the duration of the interval and the smallest_time_grain property of the metrics view

  2. Allowed grains should result in no more than 1500 buckets and no fewer than 1 bucket (though this bucket may be partial (as in the case of 24h as of latest/h by day). However, if all grains are above the max, allow year granularity. If all grains produce fewer than 1 complete bucket, allow the smallest_time_grain.

  3. If the user has explicitly asked for a certain granularity (i.e., there is a grain parameter in the url) and it is within the allowed grains for the range, render it. If the requested grain is not in the allowable grains, fall back to the range grain (if allowed) or the smallest of the allowed grains.

  4. If there is no explicit granularity requested, we should follow the grain derived from the time string (e.g day for P7D and hour for 7d as of latest/h+1h) if allowed. If not, fall back to the smallest of the allowed grains.


Examples

Time Range: 12M as of latest/d+1d
URL Grain: day
Smallest Time Grain: day

Rendered in days.

Time Range: 36M as of latest/d+1d
URL Grain: day
Smallest Time Grain: day

Rendered in weeks

Time Range: 12h as of latest/h+1h
URL Grain: hour
Smallest Time Grain: day

In this case, while hour is the range granularity and day is normally not allowed, the time series will be aggregated by day despite displaying only a single partial bucket. Because of limitations on Explore, the URL grain will be updated to day.


This logic can be verified on Canvas via the derived grainStore in time-state.ts

On Explore, a number of changes were necessary.

  • Remove selectedTimeRange from the ShallowMergeOneLevelDeepKeys so that URL grain is reflected directly and not merged from other fallback state
  • Update handleExploreInit and handleURLChange to derive this grain state once the time range has been resolved
  • Update onSelectRange function Filters.svelte to also properly derive this before triggering a state change

However, much of this could be simplified if the /time-ranges API returned these allowed grains directly.


Open questions:

Is total number of buckets the correct barometer? Both 30 days in hours and 12 hours in minutes would render 720 buckets. Are these equivalently "taxing" on the database?

What is the appropriate number of buckets to cap at? The API limit is quite high and the practical rendering limit is around 1000 (though can be increased with a rework of the time series component). 731 was somewhat arbitrary, but this was chosen to allow looking at two years worth of days.

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!

@briangregoryholmes briangregoryholmes self-assigned this Dec 11, 2025
@briangregoryholmes briangregoryholmes changed the title feat: guard time series queries with maximum interval precision [APP-450] feat: guard time series queries with maximum interval precision Dec 11, 2025
@briangregoryholmes briangregoryholmes marked this pull request as draft December 11, 2025 23:32
@briangregoryholmes briangregoryholmes marked this pull request as ready for review January 22, 2026 22:37
Copy link
Collaborator

@AdityaHegde AdityaHegde left a comment

Choose a reason for hiding this comment

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

The chart in explores disappears if you switch between large and small time ranges.

  1. Select 15mins, grain will be minute
  2. Select 12months, grain will be day.
  3. Select 15mins again, chart disappears. Comes back when you select a grain.

@briangregoryholmes briangregoryholmes requested review from AdityaHegde and removed request for AdityaHegde January 23, 2026 14:24
Copy link
Collaborator

@AdityaHegde AdityaHegde left a comment

Choose a reason for hiding this comment

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

Just a nit. Otherwise LGTM.

Have done some basic testing, the previous issue I raised doesnt exist anymore. @mindspank @nishantmonu51 Could one of you do some UXQA?

@briangregoryholmes briangregoryholmes merged commit d223131 into main Feb 3, 2026
13 of 14 checks passed
@briangregoryholmes briangregoryholmes deleted the bgh/determine-max-interval-precision branch February 3, 2026 15:35
briangregoryholmes added a commit that referenced this pull request Feb 3, 2026
…anularity (#8493)

* wip

* remove logs

* cleanup

* test fixes

* remove logs

* quality check

* test fix

* remove logs

* test fixes

* tooltip adjustment

* test fixes

* rilltime cleanup

* test updates

* test fix

* test fix

* test fix

* feedback

* comment

* ux feedback

* wip

* initial pass at explore support

* cleanup

* rework allowed grains

* cleanup

* increase limit

* simplify boolean

* remove code duplication

* quality checks

* test fixes

* test fixes

* move function

* reorg

* remove comments

* tests and adjustments

* more tests

* quality checks

* cleanup

* quality check

* cleanup

* reorg function, remove dead code

* import fix

* test fix
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.

7 participants