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

align metric queries by step and other queries by split interval #5181

Merged
merged 4 commits into from
Jan 19, 2022

Conversation

sandeepsukhani
Copy link
Contributor

What this PR does / why we need it:
It changes the way query splits are built based on the query type:

  1. Metric queries: Start/End time in query splits would be aligned by step in query.
  2. All other queries: Start/End time in query splits would be aligned by the split interval.

Note: Start of the first query and end time of the last query is kept the same as the original query.

This change is being done for two reasons:

  1. The step alignment code(when enabled) rounds down both Start and end time which could modify it too much if the steps are too large.
  2. Metadata queries perform well when aligned by 24h(split interval). Testing this internally reduced 3x the number of index queries and improved query performance by 2x for long-range /label calls.

While there is no visible impact on the results cache hit rate, I think we should also change the step alignment code to round down the start time and round up the end time, which would anyways only align the start time of the first query and end time of the last query.
image

Checklist

  • Tests updated

@sandeepsukhani sandeepsukhani requested a review from a team as a code owner January 19, 2022 10:39
Comment on lines +266 to +270
if !newEnd.Before(end) {
newEnd = end
} else if endTimeInclusive {
newEnd = newEnd.Add(-time.Millisecond)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quite understand this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the end time is inclusive, we do not want the current query's end time to be the same as the start time of the next query. The only queries that have both start and end time inclusive are metadata queries, and without this change, we would still end up querying the same data as the next query.
I will add a comment to make it clear.

@@ -298,6 +318,9 @@ func splitMetricByTime(r queryrangebase.Request, interval time.Duration) []query
EndTs: end,
})
}

// change the start time to original time
reqs[0] = reqs[0].WithStartEnd(lokiReq.GetStart(), reqs[0].GetEnd())
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a check if len(reqs) != 0

@cyriltovena
Copy link
Contributor

Should we deprecate the StepAlign middleware ?

Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

LGTM

@sandeepsukhani
Copy link
Contributor Author

Should we deprecate the StepAlign middleware ?

While there is not much value in keeping it, I was thinking about changing it to round down the start time and round up the end time to make all the queries cacheable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants