-
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
Changes from all commits
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 |
---|---|---|
|
@@ -1110,13 +1110,20 @@ func (d *Distributor) truncateLines(vContext validationContext, stream *logproto | |
return | ||
} | ||
|
||
suffix := vContext.maxLineSizeTruncateIdentifier | ||
|
||
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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if truncateTo <= 0 { | ||
continue | ||
} | ||
|
||
stream.Entries[i].Line = e.Line[:truncateTo] + suffix | ||
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 guess this also allocs new slice 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. Yes, it creates a new string. There are benchmarks in the original truncation PR, which show that there is very little overhead, though. |
||
|
||
truncatedSamples++ | ||
truncatedBytes += len(e.Line) - maxSize | ||
truncatedBytes += len(e.Line) - truncateTo | ||
} | ||
} | ||
|
||
|
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: