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

Remove temp file usage for logs #607

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Remove temp file usage for logs #607

wants to merge 2 commits into from

Conversation

seanlinsley
Copy link
Member

@seanlinsley seanlinsley commented Oct 7, 2024

Followup to #597, this removes temp file usage in log code paths, instead keeping the log content in memory.

input/system/rds/logs.go Show resolved Hide resolved
@@ -4328,6 +4328,9 @@ var tests = []testpair{
func TestAnalyzeLogLines(t *testing.T) {
for _, pair := range tests {
l, s := logs.AnalyzeLogLines(pair.logLinesIn)
for idx := range l {
l[idx].Content = ""
Copy link
Member Author

Choose a reason for hiding this comment

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

Multiple tests now do this to avoid needing to copy-paste the log content into the expected output struct. I could do that if desired, it would just be tedious.

fmt.Printf("%s\n", logFileContents[logLine.ByteStart:logLine.ByteEnd])
fmt.Printf(" Level: %s\n", logLine.LogLevel)
fmt.Printf(" Content: %#v\n", logFileContents[logLine.ByteContentStart:logLine.ByteEnd])
fmt.Printf(" %s: %s", logLine.LogLevel, logLine.Content)
Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't tried running the debug command yet. Someone might have a preference on the output format.

One downside to this PR is we can no longer debug the entire log content including the unparsed log prefix.

@@ -332,24 +329,16 @@ func postprocessAndSendLogs(ctx context.Context, server *state.Server, globalCol

for idx := range transientLogState.LogFiles {
logFile := &transientLogState.LogFiles[idx]
logFile.ByteSize = int64(logFile.LogLines[len(logFile.LogLines)-1].ByteEnd)
Copy link
Member Author

Choose a reason for hiding this comment

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

Since we no longer have the original string at this point in the code, looking at the last log line's ByteEnd is the only way to know the file size. Maybe this should be moved to an earlier processing stage?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh and in terms of this code's soundness, I vaguely remember that on production we do receive log files that don't contain any log lines, so this would panic. Should we really be submitting empty snapshots?

@seanlinsley seanlinsley marked this pull request as ready for review October 7, 2024 16:34
@seanlinsley seanlinsley requested a review from a team October 7, 2024 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant