Skip to content

Conversation

@melekr
Copy link
Collaborator

@melekr melekr commented Apr 28, 2023

  • Remove Cassette dependency
  • Replace Cassette Queue and file operations

@rick-bt rick-bt requested a review from ianrice07 April 28, 2023 20:39
Copy link

@KrzaQ KrzaQ left a comment

Choose a reason for hiding this comment

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

I don't have much to say, it looks ok to me.

self.queue = try CASQueueFile.init(path: breadcrumbSettings.getBreadcrumbLogPath().path)


self.breadcrumbLogURL = try breadcrumbSettings.getBreadcrumbLogPath()
Copy link
Collaborator

Choose a reason for hiding this comment

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

why it can throw? Maybe it would be better to throw an error faster and here pass only data needed by BacktraceBreadcrumbFileHelper?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure

self.queue = try CASQueueFile.init(path: breadcrumbSettings.getBreadcrumbLogPath().path)


self.breadcrumbLogURL = try breadcrumbSettings.getBreadcrumbLogPath()
Copy link
Collaborator

Choose a reason for hiding this comment

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

what if the file doesn't exist? we don't create it anywhere. We always write to a file. How about creating a start method that will do startup logic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the file will always exist;
getBreadcrumbLogPath() method will create a file if doesn't exist

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there is no good way to do this since BacktraceBreadcrumbSettings forces us to (try/unwrap), if for any reason the file is nil the files operations methods will catch the error and warn BacktraceLogger.

melekr added 2 commits May 3, 2023 16:38
Rename BacktraceBreadcrumbFileHelper to BacktraceBreadcrumbFile
Code improvements
Add BacktraceBreadcrumbFile extension to host file operations
Add remove(at index: Int) to Queue class
Update BacktraceLogger error messages

func clearBreadcrumbLogFile(at breadcrumbLogURL: URL) {
do {
try "".write(to: breadcrumbLogURL, atomically: false, encoding: .utf8)
Copy link
Collaborator

Choose a reason for hiding this comment

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

what if someone deletes a file when you're generating breadcrumbs?

BacktraceLogger.warning("Error when adding breadcrumbSize to array")
return false
}
let queueBreadcrumb = queuedBreadcrumbs[index]
Copy link
Collaborator

Choose a reason for hiding this comment

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

We receive index out of bounds when we access breadcrumbs with an invalid index, right? or will it return null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it shouldn't but I'll guard it

@@ -1,5 +1,15 @@
import Foundation

struct BreadcrumbRecord {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it should be moved to a separated file.
You implemented queue to be generic. However, putting BreadcrumbRecord definition in the Queue implementation sounds weird.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

moving it

@@ -1,5 +1,15 @@
import Foundation
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it QueueFile? I believe its a generic queue instead. Can we rename the file to Queue or something like that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Queue it is!

melekr added 2 commits May 5, 2023 10:52
Add BreadcrumbRecord class definition
Rename QueueFile to Queue
Guard queue index when iterating
let text = "this is Breadcrumb number \(writeIndex)"
// submit a task to the queue for background execution
DispatchQueue.global().async(group: group, execute: {
expect { breadcrumbs.addBreadcrumb(text) }.to(beTrue())
Copy link
Contributor

@vlussenburg vlussenburg May 8, 2023

Choose a reason for hiding this comment

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

Without this background task, this test doesn't do what is intended to do (in fact, the entire loop is useless).

We had lots of problems with multithreaded behavior corrupting the file, so beware!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll seep a close eye on multithreaded behaviour, thank you!

let fileSize = attr[FileAttributeKey.size] as? Int
let requestedSize = settings.maxQueueFileSizeBytes
expect { fileSize }.to(beLessThanOrEqualTo(requestedSize))
expect { fileSize }.to(beGreaterThanOrEqualTo(requestedSize - 1000))
Copy link
Contributor

Choose a reason for hiding this comment

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

This check is important. I would consider adjusting it, not deleting it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will do

// Currently, we accept we lose this Breadcrumb in the UI - it will still be in the file
// for manual inspection.
let expectedNumberOfMatches = writeIndex - wrapIndex - 1
expect(matches).to(beGreaterThanOrEqualTo(expectedNumberOfMatches),
Copy link
Contributor

@vlussenburg vlussenburg May 8, 2023

Choose a reason for hiding this comment

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

This check is important. I would consider adjusting it, not deleting it. The -1 may no longer be necessary due to the Cassette dependency being removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

This test is specifically there to make sure the file rolls over, so the number of expected matches are really important. Otherwise the entire test doesn't do anything the other (smaller) tests already do.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed this one for the same reason, I'll adjust it.
Thank you :)

s.osx.public_header_files = ["Backtrace-macOS/**/*.h*"]
s.tvos.public_header_files = ["Backtrace-tvOS/**/*.h*"]

s.ios.dependency "Cassette", '1.0.0-beta5'
Copy link
Contributor

@vlussenburg vlussenburg May 8, 2023

Choose a reason for hiding this comment

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

Check if there's any superfluous #if os(iOS) || os(OSX) left in prod/test code. I know there were a bunch of 'm

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll take a look :)

@vlussenburg
Copy link
Contributor

Hey hey!

Cool that that pesky Cassette is finally being removed :). I forgot where, but there's performance test results stored in Github or Hack somewhere that document for which file sizes the performance is what.

This PR seems to be doing somewhat similar to what #95 was meant to do (but is outdated now). You may want to compare and then close it.

Thanks :)
Vincent

@melekr melekr closed this May 11, 2023
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.

6 participants