-
Notifications
You must be signed in to change notification settings - Fork 115
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
Logs from different streams can arrive out of order #401
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,16 +62,23 @@ def rfc3339_timestamp(time) | |
|
||
def deduplicate(logs) | ||
deduped = [] | ||
check_for_duplicate = true | ||
|
||
logs.each do |line| | ||
timestamp, msg = split_timestamped_line(line) | ||
next if check_for_duplicate && likely_duplicate?(timestamp) | ||
check_for_duplicate = false # logs are ordered, so once we've seen a new one, assume all subsequent logs are new | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. womp womp lol There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😆 |
||
parsed_lines = logs.map { |line| split_timestamped_line(line) } | ||
sorted_lines = parsed_lines.sort do |a, b| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about something like sort do |(t1, _), (t2, _)| then you can avoid the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'ld probably go so far as to call the |
||
if a[0].nil? || b[0].nil? | ||
0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. Not sure I'm following this logic. if a[0].nil?
-1
elsif b[0].nil?
+1
else
a[0] <=> b[0]
end or maybe something like (a[0] || 0) <=> (b[0] || 0) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My thought was that considering them equal was equivalent to leaving them alone, but that's completely wrong. It totally messes up the sort. Since the actual known case where the timestamp is missing is one where that defective line is the first, I think the second suggestion (assuming no timestamp means earliest) is a good approach. |
||
else | ||
a[0] <=> b[0] | ||
end | ||
end | ||
|
||
sorted_lines.each do |line| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorted_lines.each do |timestamp, msg| saves you the next two lines |
||
timestamp = line[0] | ||
msg = line[1] | ||
next if likely_duplicate?(timestamp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Exactly. We fetch logs (and then process them here) repeatedly, and since the API does not support subsecond granularity, we inevitably sometimes get the same log lines in more than one batch. |
||
@last_timestamp = timestamp if timestamp | ||
deduped << msg | ||
end | ||
|
||
deduped | ||
end | ||
|
||
|
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.
maybe this deserves a new name now?
sort_and_deduplicate
?sort_and_uniq
?