Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loki: Fix metric time splitting to split starting with the start time #80085

Merged
merged 3 commits into from
Jan 8, 2024

Conversation

svennergr
Copy link
Contributor

What is this feature?

With Grafana's query splitting in Loki we previously expanded the timerange in such a way, that it might lead to querying more data than needed. E.g. a query with a 1d step and 1d range over any specific duration would always lead to include an additional day.

This PR fixes the adjustment of the end time range, and the calculation of metric splits. With this change, the smallest split will always be near the end time, i.e. it will also be the part that will be queried first. However, only with this we can ensure that we are not going out of bounds of the given duration.

Special notes for your reviewer:

I added two panels to the query splitting gdev dashboard that should showcase the issue:

Without the change:
image

With the change:
image

@svennergr svennergr requested review from a team as code owners January 5, 2024 14:43
@svennergr svennergr requested review from axelavargas and ivanortegaalba and removed request for a team January 5, 2024 14:43
@grafana-delivery-bot grafana-delivery-bot bot added this to the 10.3.x milestone Jan 5, 2024
Copy link
Contributor

@matyax matyax left a comment

Choose a reason for hiding this comment

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

This looks great to me. I currently see no reason to not make this change.

// to include the 08.02.2022, which we don't want. So we have to start from
// the start, always ending at the last step before the actual end, or the total end.
for (let chunkStartTime = alignedStartTime; chunkStartTime < endTime; chunkStartTime += alignedDuration) {
const chunkEndTime = Math.min(chunkStartTime + alignedDuration - step, endTime);
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes total sense.

@svennergr svennergr merged commit d1b0e90 into main Jan 8, 2024
14 checks passed
@svennergr svennergr deleted the svennergr/fix-splitting-duration-end branch January 8, 2024 12:26
@ifrost ifrost modified the milestones: 10.3.x, 10.4.x Jan 12, 2024
zserge pushed a commit that referenced this pull request Jan 22, 2024
…#80085)

* Loki: Fix metric time splitting to split starting with the start time

* add test case to gdev-dashboard

* fix splitting test
s0lesurviv0r pushed a commit to s0lesurviv0r/grafana that referenced this pull request Feb 3, 2024
…grafana#80085)

* Loki: Fix metric time splitting to split starting with the start time

* add test case to gdev-dashboard

* fix splitting test
@aangelisc aangelisc modified the milestones: 10.4.x, 10.4.0 Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants