Skip to content

Handle the case of large step causing single pt extents #3818

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

Conversation

gouthamve
Copy link
Contributor

We noticed that we were ignoring samples if the step is 24h and this
fixes it.

@gouthamve gouthamve requested a review from bboreham February 12, 2021 15:46
@bboreham
Copy link
Contributor

I see that this improves the symptom, however it now does something undesirable: it makes two queries for parts of the range before and after the cached extent, with no gap between them since the extent is of zero width.
Can you special-case this so the cached value is added but only one query is made?

We noticed that we were ignoring samples if the step is 24h and this
fixes it.

Signed-off-by: Goutham Veeramachaneni <[email protected]>
@gouthamve gouthamve force-pushed the handle-large-extents-with-single-value branch from 6385ee7 to 0c19b9d Compare February 12, 2021 16:25
@gouthamve
Copy link
Contributor Author

@bboreham Handled the special case differently, WDYT?

@bboreham
Copy link
Contributor

Still looks like it will do the same 2 queries. Try changing the test so the cached value is at 101.

@bboreham
Copy link
Contributor

Wait how does this even work? Your test is for a zero-length range (Start: 100, End: 100); does that happen in practice?

@gouthamve
Copy link
Contributor Author

It happens when the step is more than 50% of the interval. Or basically large steps. In the case in our production it was 24hr step.

https://play.golang.org/p/rc0pex0NISJ

https://github.com/cortexproject/cortex/blob/master/pkg/querier/queryrange/split_by_interval.go#L63-L86

@bboreham
Copy link
Contributor

OK can you have different handling for req.GetStart() == req.GetEnd() ?

AFAICS for a longer request your change will put back the conditions I was fixing in #3653

@gouthamve
Copy link
Contributor Author

AFAICS for a longer request your change will put back the conditions I was fixing in #3653

Basically when you have req.GetStart() == req.GetEnd(), it is impossible to have the conditions of #3653. When start and end are the same, you basically have a single step in that range. If there is a hit, we pick that extent (no other extent can exist). We basically can never have many small requests.

@bboreham
Copy link
Contributor

OK but this PR changes it for all requests.

@bboreham
Copy link
Contributor

Ah, no it doesn't!

Sorry, I did not understand the comment at all, and didn't spot how the test had changed.

Still think it would be clearer to special-case req.GetStart() == req.GetEnd() outside of the loop.

@pull-request-size pull-request-size bot added size/M and removed size/S labels Feb 15, 2021
Signed-off-by: Goutham Veeramachaneni <[email protected]>
@gouthamve gouthamve force-pushed the handle-large-extents-with-single-value branch from 61085c6 to 8de3184 Compare February 15, 2021 12:47
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

The fix LGTM. I left a couple of non-blocking comments.

@gouthamve gouthamve closed this Feb 15, 2021
@gouthamve gouthamve reopened this Feb 15, 2021
Signed-off-by: Goutham Veeramachaneni <[email protected]>
@bboreham
Copy link
Contributor

[sorry, posted this in the wrong place yesterday]

Wouldn't it look better if you add something like this at the top and don't change the loop?

  // special-case situation created by step bigger than range
  if req.GetStart() == req.GetEnd() {
    // do we have a cached extent that matches this zero-length request?
    if len(extents) == 1 && extents[0].Start == req.GetStart() && extents[0].End == req.GetEnd() {
      res, err := extent.toResponse()
      cachedResponses = append(cachedResponses, res)
    } else {
      // cache didn't match this request; pass it through to querier
      requests = append(requests, req)
    }
    return requests, cachedResponses, nil
  }

@gouthamve
Copy link
Contributor Author

gouthamve commented Feb 16, 2021

But that would mean queries with the same start and end time created directly by users will never be cached. Might not be an issue though.

@bboreham
Copy link
Contributor

I'm not seeing that. All I meant was to pull the special case out of the loop so we don't have to stare really hard at the loop to see what it means.

@bboreham
Copy link
Contributor

Oh, you mean if we have a zero-length request and a non-zero-length cache entry (but still over 5 minutes) that covers it, then we won't look at that. Fair point.

I think this helps to prove that this routine is too complicated to get right.

@gouthamve gouthamve merged commit e10ccda into cortexproject:master Feb 16, 2021
khaines pushed a commit to khaines/cortex that referenced this pull request Feb 16, 2021
…t#3818)

* Handle the case of large step causing single pt extents

We noticed that we were ignoring samples if the step is 24h and this
fixes it.

Signed-off-by: Goutham Veeramachaneni <[email protected]>

* Handle the case of start == end better

Signed-off-by: Goutham Veeramachaneni <[email protected]>

* Address feedback

Signed-off-by: Goutham Veeramachaneni <[email protected]>
(cherry picked from commit e10ccda)
khaines added a commit that referenced this pull request Feb 17, 2021
* Handle the case of large step causing single pt extents

We noticed that we were ignoring samples if the step is 24h and this
fixes it.

Signed-off-by: Goutham Veeramachaneni <[email protected]>

* Handle the case of start == end better

Signed-off-by: Goutham Veeramachaneni <[email protected]>

* Address feedback

Signed-off-by: Goutham Veeramachaneni <[email protected]>
(cherry picked from commit e10ccda)

Co-authored-by: Goutham Veeramachaneni <[email protected]>
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.

3 participants