-
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(promtail): Handle docker logs when a log is split in multiple frames #12374
Conversation
c64c5f0
to
2ff1e6d
Compare
2ff1e6d
to
f3cc6bd
Compare
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.
I can do a more in depth review later, but I think it would also be a good idea to include copies (modified where needed) of the tests from the docker codes stdcopy_test.go
Thanks for the comments - I have responded to those review comments and will make adjustments (separate tests corresponding to stdcopy_test, removal of changelog entry) sometime this week. |
f3cc6bd
to
6053593
Compare
Requested tests were added and the manually added changelog entry was removed. |
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 progress, I think we can merge soon
// We don't output trailing newlines | ||
payload = strings.TrimSuffix(payload, "\n") | ||
payload = strings.TrimSuffix(payload, "\r") |
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.
should we be removing these?
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.
I moved this into the process
function which now has a TrimRight
call for these. The reason is that process
keeps track of the length of the buffer, to see if it's over the new limit we set, but this length should exclude the trailing newline (because we don't output the newline). And I thought it was just easier to take away the trailing newline earlier in the process for this purpose (otherwise we'd have to keep track of the buffer length in a more complicated manner than just calling payloadAcc.Len()
).
@jonaslb as a promtail user, do you have any thoughts on the best place to document the behaviour between |
Yeah, now that I've integrated I don't think it needs to be explicitly said that the target also respects the limit, because the data flowing from a target to the client (where lines are truncated/discarded according to the setting) is not user observable anyway. So the main thing to document, I think, is the default limit due to memory and then noting that it can be changed with I have pushed a commit with a proposal for how it could be documented. |
Just one more minor change to the docs and then we can merge imo |
f38eff5
to
1e588c9
Compare
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.
great 👍 thanks for your patience @jonaslb
What this PR does / why we need it:
Docker splits log lines into 16 kiB frames if a line is longer than that.
When requesting timestamps, every frame is prefixed with the timestamp.
Previously, Promtail would concatenate the frames naively, and only strip the timestamp at the start of a line, and not at the start of every frame.
The result is that logs which were larger than 16 kiB would get corrupted, especially an issue in the case of structured logs that would be parsed downstream somewhere.
This PR changes the docker logs handling to be based around frames in channels instead of just writing into an
io.Write
.Which issue(s) this PR fixes:
Special notes for your reviewer:
github.com/docker/docker/pkg/stdcopy
has been put intopkg/framedstdcopy
and marked as apache2. This is because the bug is (arguably) also present in e.g. the docker CLI, and possibly also in many other places, and I think it is most appropriate then to keep the license for that the same as stdcopy already is.io.Write
). I don't think it's an issue, but maybe there are strong opinions about it?I put a soft limit on the buffering size when combining frames of 16Mi. Maybe there are opinions about that too?Changed to followmax_line_size
setting or a max of 256k following review commentsChecklist
CONTRIBUTING.md
guide (required)CHANGELOG.md
updatedadd-to-release-notes
labeldocs/sources/setup/upgrade/_index.md
production/helm/loki/Chart.yaml
and updateproduction/helm/loki/CHANGELOG.md
andproduction/helm/loki/README.md
. Example PRdeprecated-config.yaml
anddeleted-config.yaml
files respectively in thetools/deprecated-config-checker
directory. Example PR