Skip to content

Commit

Permalink
Add FXIOS-9517 [Logging] Add logging to track Jul 17 incident (#21068) (
Browse files Browse the repository at this point in the history
#21072)

* Added window UUID for additional logging.

* Added fetchWindowData logging for incident info.

* Remove not useful check.

* Remove unnecessary method.

* Update consistency across window data logs.

* Continue logging window data restore failures as fatal.

* Escalate window data parsing errors from debug to warning.

* Breakdown each possible error scenario into an individual log for debugging purposes. Added even more logging!

* Refactoring to a single point of logging.

(cherry picked from commit 4db2c17)

Co-authored-by: Isabella <[email protected]>
  • Loading branch information
mergify[bot] and ih-codes authored Jul 17, 2024
1 parent 9431e46 commit ecb4381
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 15 deletions.
66 changes: 57 additions & 9 deletions BrowserKit/Sources/TabDataStore/TabDataStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,70 @@ public actor DefaultTabDataStore: TabDataStore {
// MARK: Fetching Window Data

public func fetchWindowData(uuid: UUID) async -> WindowData? {
logger.log("Attempting to fetch window/tab data", level: .debug, category: .tabs)
logger.log("Attempting to fetch window data", level: .debug, category: .tabs)

// Adding more logging for FXIOS-9517
var shouldLogFileFailure = false // Whether pulling from the main file failed
var shouldLogBackupFailure = false // Whether pulling from the backup file failed
var fileInfoMessage = "" // Specifics of main file failure
var backupInfoMessage = "" // Specifics of backup file failure
defer {
if shouldLogFileFailure {
let errorMessage: String
errorMessage = shouldLogBackupFailure
? "Failed to open window data (including backup data) for UUID: \(uuid)"
: "Failed to open window data (but backup recovery worked) for UUID: \(uuid)"
logger.log(
"\(errorMessage) File Info: [\(fileInfoMessage)] Backup File Info: [\(backupInfoMessage)]",
level: .fatal,
category: .tabs
)
}
}

do {
guard let fileURL = windowURLPath(for: uuid, isBackup: false),
fileManager.fileExists(atPath: fileURL),
let windowData = parseWindowDataFile(fromURL: fileURL) else {
logger.log("Failed to open window/tab data for UUID: \(uuid)", level: .fatal, category: .tabs)
guard let fileURL = windowURLPath(for: uuid, isBackup: false) else {
fileInfoMessage += "fileURL nil"
shouldLogFileFailure = true
throw TabDataError.failedToFetchData
}

guard fileManager.fileExists(atPath: fileURL) else {
fileInfoMessage += "file doesn't exist"
shouldLogFileFailure = true
throw TabDataError.failedToFetchData
}

guard let windowData = parseWindowDataFile(fromURL: fileURL) else {
fileInfoMessage += "file parsing failed"
shouldLogFileFailure = true
throw TabDataError.failedToFetchData
}

logger.log("Successfully fetched window data", level: .debug, category: .tabs)
return windowData
} catch {
logger.log("Error fetching window data: UUID = \(uuid) Error = \(error)", level: .warning, category: .tabs)
guard let backupURL = windowURLPath(for: uuid, isBackup: true),
fileManager.fileExists(atPath: backupURL),
let backupWindowData = parseWindowDataFile(fromURL: backupURL) else {
logger.log("Error fetching window data for UUID: \(uuid) Error: \(error)", level: .warning, category: .tabs)

guard let backupURL = windowURLPath(for: uuid, isBackup: true) else {
backupInfoMessage += "backup fileURL nil"
shouldLogBackupFailure = true
return nil
}

guard fileManager.fileExists(atPath: backupURL) else {
backupInfoMessage += "backup file doesn't exist"
shouldLogBackupFailure = true
return nil
}

guard let backupWindowData = parseWindowDataFile(fromURL: backupURL) else {
backupInfoMessage += "backup file parsing failed"
shouldLogBackupFailure = true
return nil
}

logger.log("Returned backup window data for UUID: \(uuid)", level: .debug, category: .tabs)
return backupWindowData
}
}
Expand Down
20 changes: 15 additions & 5 deletions BrowserKit/Sources/TabDataStore/TabFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,21 @@ public struct DefaultTabFileManager: TabFileManager {
}

public func windowDataDirectory(isBackup: Bool) -> URL? {
guard let containerID = BrowserKitInformation.shared.sharedContainerIdentifier else { return nil }
guard let containerID = BrowserKitInformation.shared.sharedContainerIdentifier else {
logger.log(
"Failed to get the window data container ID from BrowserKit's sharedContainerIdentifier",
level: .warning,
category: .tabs
)
return nil
}
let pathInfo = isBackup ? PathInfo.backup : PathInfo.primary
var containerURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: containerID)
containerURL = containerURL?.appendingPathComponent(PathInfo.rootDirectory)
return containerURL?.appendingPathComponent(pathInfo)
guard let containerURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: containerID) else {
logger.log("Failed to get the window data container URL", level: .warning, category: .tabs)
return nil
}
let appendedURL = containerURL.appendingPathComponent(PathInfo.rootDirectory)
return appendedURL.appendingPathComponent(pathInfo)
}

public func contentsOfDirectory(at path: URL) -> [URL] {
Expand Down Expand Up @@ -144,7 +154,7 @@ public struct DefaultTabFileManager: TabFileManager {
return windowData
} catch {
logger.log("Error decoding window data: \(error)",
level: .debug,
level: .warning,
category: .tabs)
throw error
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class TabManagerImplementation: LegacyTabManager, Notifiable, WindowSimpleTabsPr
let windowCount = windowManager.windows.count
let totalTabCount =
(windowCount > 1 ? windowManager.allWindowTabManagers().map({ $0.normalTabs.count }).reduce(0, +) : 0)
logInfo = (windowCount == 1) ? "(1 window)" : "(of \(totalTabCount) total tabs across \(windowCount) windows)"
logInfo = (windowCount == 1) ? "(1 window [\(windowUUID)])" : "(of \(totalTabCount) total tabs across \(windowCount) windows)"
logger.log("Tab manager is preserving \(tabData.count) tabs \(logInfo)", level: .debug, category: .tabs)

return tabData
Expand Down

1 comment on commit ecb4381

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

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

Uh oh! Looks like an error!

InterpreterError at template.tasks[0].extra[0].treeherder[1].symbol: unknown context value cron

Please sign in to comment.