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

awslogs: Record log line insert order for sorting #24814

Merged
merged 2 commits into from Aug 12, 2016

Conversation

samuelkarp
Copy link
Member

Fixes #24775

- What I did
When multiple log lines are emitted with the same timestamp, fall back to insertion order rather than allowing sort.Sort to pick the order.

- How I did it
Insertion order is recorded in a new wrapper struct internal to the logging driver. Less now uses the insertion order when the timestamps are equal.

- How to verify it
Unit tests pass.

- Description for the changelog

Fixed a bug in the awslogs logging driver that could cause log lines to be recorded out-of-order under rare conditions.

@samuelkarp
Copy link
Member Author

Bump. I believe the Jenkins failure is unrelated to my change.

sort.Sort(byTimestamp(events))
cwEvents := getCWEvents(events)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps I don't understand the problem, but wouldn't simply removing the sort.Sort(byTimestamp(events)) solve the problem?

If I read the code correctly, the events are added in the correct order (in collectBatch), so they should arrive here in the correct order.

However, due to sort.Sort(byTimestamp(events)), the events possibly get reordered, and end up in the wrong order (if two events have exactly the same time stamp)

Could you try if simply removing that sort resolves the issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

The PutLogEvents API has this requirement:

The log events in the batch must be in chronological ordered by their timestamp.

The sorting here is to ensure that even on a system that is experiencing some changes in the clock (e.g., skew being corrected by NTP) that the call to PutLogEvents will still succeed.

Copy link
Member

Choose a reason for hiding this comment

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

As just discussed on Slack; I overlooked that the timestamps are not generated in collectBatch, but taken from the msg, so they can arrive in collectBatch in the wrong order.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps rename getCWEvents to something like unwrapEvents, but that's just a nit and may be just me 😄

Signed-off-by: Samuel Karp <skarp@amazon.com>
Fixes moby#24775

Signed-off-by: Samuel Karp <skarp@amazon.com>
@samuelkarp
Copy link
Member Author

@thaJeztah I've changed the name per your suggestion. The Jenkins failure (again) looks unrelated.

@thaJeztah thaJeztah added this to the 1.13.0 milestone Aug 3, 2016
@crosbymichael
Copy link
Contributor

LGTM

1 similar comment
@cpuguy83
Copy link
Member

LGTM

@cpuguy83 cpuguy83 merged commit c6e3818 into moby:master Aug 12, 2016
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.

Logs sometimes out of order with awslogs log driver
5 participants