-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
fix: Fix panic on requesting out-of-order Pattern samples #13010
Conversation
pkg/pattern/drain/chunk.go
Outdated
@@ -51,7 +51,7 @@ func (c Chunk) ForRange(start, end, step model.Time) []logproto.PatternSample { | |||
} | |||
first := c.Samples[0].Timestamp | |||
last := c.Samples[len(c.Samples)-1].Timestamp | |||
if start >= end || first >= end || last < start { | |||
if last < first || start >= end || first >= end || last < start { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might not cover all the cases since the in-between samples could be out-of-order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point - I'll add some more test cases
Rewrote this so it will reject out-of-order samples for the Pattern instead of trying to sort this chunk. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
What this PR does / why we need it:
This PR fixes a panic that can occur when samples are out-of-order in the Pattern chunks.
This happens because the calculated slice length can be negative if the timestamp at
hi-1
is less than the timestamp atlo
due to subtractingcurrentStep
(generated from timestamp@lo
) from the timestamp@hi-1
.Implementation Notes
Add
method.Add
- let me know if you prefer this approach.