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

PB-8293 : Implement a new log writer which flushes the logs in every 30 seconds (for real time logs) #397

Merged
merged 2 commits into from
Sep 20, 2024

Conversation

px-kesavan
Copy link
Contributor

@px-kesavan px-kesavan commented Sep 19, 2024

…30 seconds (for real time logs)

What this PR does / why we need it: Currently the output of kopia backup/restore command is flushed in to the pod logs only after the cmd execution , so the user is not aware of the progress This PR Implements a new log writer which flushes the logs in every 30 seconds (for real time logs)

Which issue(s) this PR fixes (optional)
Closes # https://purestorage.atlassian.net/browse/PB-8293

Special notes for your reviewer:

Output for backup

Screenshot from 2024-09-19 10-28-56

Attached additional testing details with logs in the ticket https://purestorage.atlassian.net/browse/PB-8293

…30 seconds (for real time logs)

Signed-off-by: Kesavan Thiruvenkadasamy <[email protected]>
Copy link
Contributor

@lalat-das lalat-das left a comment

Choose a reason for hiding this comment

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

please address the review Comment.

}

func (lw *logWriter) Write(p []byte) (n int, err error) {
lw.mu.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need this mutex. What is the scenario when write will be called from two parallel path.
Isn't multi writer already takes care of writing to two file descriptor in parallel with synchronization on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even though we create two separate objects by calling newLogWriter for stderr and stdout, there is a chance that write can be called by multiple goroutines at the same time if the snapshot create command generates output quickly. It's unlikely to happen, but I have added a mutex for extra integrity of the output data

now := time.Now()
// log if the interval has passed since the last log
// this is to avoid bloating the logs
if now.Sub(lw.lastLogTime) >= lw.interval {
Copy link
Contributor

Choose a reason for hiding this comment

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

What will be the behavior if backup gets completed with 30 sec. Nothing will be written ? Say some error in the command line happens and command is done. I am confused about the lastLogTime's value when for the first time the write call is invoked ? Any default value need to be assigned? or is it because it will be zero and So now - 0 already takes care of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First write will not wait for 30secs, it will be written as when it comes.
To explain on the lastLogTime value for the first time will be 0 time format.
if block basically does (time.Now() - lastLogTime ) > 30 sec, Which will succeed .

// log if the interval has passed since the last log
// this is to avoid bloating the logs
if now.Sub(lw.lastLogTime) >= lw.interval {
lw.logger.Println(string(p), time.Now())
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a test case showcasing failure of kopia command if it can happen within 30 sec and log appears as expected then we are good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please refer the ticket, have attached for the same


// Create multi-writers to stream output to both buffer and CLI
stdoutWriter := io.MultiWriter(b.outBuf, newLogWriter(log.New(os.Stdout, "", 0), commandExecLogInterval))
stderrWriter := io.MultiWriter(b.errBuf, newLogWriter(log.New(os.Stderr, "", 0), commandExecLogInterval))
Copy link
Contributor

@lalat-das lalat-das Sep 19, 2024

Choose a reason for hiding this comment

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

Not doubting the golang primitives here but it would be good if we can check outBuf errBuf are working as expected by checking summary response also populated as expected. A unit test around that would be great.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not doubting , but still doubting :) . Have attached the logs for the same in the ticket. Thanks

@portworx portworx deleted a comment from github-actions bot Sep 20, 2024
@portworx portworx deleted a comment from github-actions bot Sep 20, 2024
@portworx portworx deleted a comment from github-actions bot Sep 20, 2024
@portworx portworx deleted a comment from github-actions bot Sep 20, 2024
Copy link
Contributor

@lalat-das lalat-das left a comment

Choose a reason for hiding this comment

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

lgtm.

@px-kesavan px-kesavan merged commit f4c7e34 into master Sep 20, 2024
3 checks passed
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.

3 participants