-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat: Mark truncated log lines with identifier #18262
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
@@ -3720,6 +3720,10 @@ The `limits_config` block configures global and per-tenant limits in Loki. The v | |||
# CLI flag: -distributor.max-line-size-truncate | |||
[max_line_size_truncate: <boolean> | default = false] | |||
|
|||
# Identifier that is added at the end of a truncated log line. | |||
# CLI flag: -distributor.max-line-size-truncate-identifier | |||
[max_line_size_truncate_identifier: <string> | default = ""] |
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.
Alternative naming proposal:
[max_line_size_truncate_identifier: <string> | default = ""] | |
[max_line_size_truncate_suffix: <string> | default = ""] |
💻 Deploy preview deleted. |
This PR adds the possibility to add an identifier as suffix for truncated log lines, such as `[...]` so that truncated log lines are easier to spot and identify when querying them. Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
52cb8d3
to
866e9b5
Compare
var truncatedSamples, truncatedBytes int | ||
for i, e := range stream.Entries { | ||
if maxSize := vContext.maxLineSize; maxSize != 0 && len(e.Line) > maxSize { | ||
stream.Entries[i].Line = e.Line[:maxSize] | ||
truncateTo := maxSize - len(suffix) |
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.
can we add a test? :)
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.
given this is hotpath, should we have the suffix logic in its own branch only when len(suffix) > 0?
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.
ofc!
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.
continue | ||
} | ||
|
||
stream.Entries[i].Line = e.Line[:truncateTo] + suffix |
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 guess this also allocs new slice
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.
Yes, it creates a new string. There are benchmarks in the original truncation PR, which show that there is very little overhead, though.
Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
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
While truncated JSON log lines are usually easy to identify (because the JSON becomes invalid), it is not always the case with other plain text log lines. This PR adds the possibility to add an identifier as suffix for truncated log lines, such as `[...]` so that truncated log lines are easier to spot and identify when querying them. Signed-off-by: Christian Haudum <christian.haudum@gmail.com> (cherry picked from commit 0ee8e76)
What this PR does / why we need it:
While truncated JSON log lines are usually easy to identify (because the JSON becomes invalid), it is not always the case with other plain text log lines.
This PR adds the possibility to add an identifier as suffix for truncated log lines, such as
[...]
so that truncated log lines are easier to spot and identify when querying them.A truncation identifier has almost been implemented with the initial truncation PR (#4051). This implementation is essentially the same.