diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 4bed43085..197812d83 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -9841,7 +9841,7 @@ repositoryURL = "https://github.com/element-hq/matrix-rust-components-swift"; requirement = { kind = exactVersion; - version = 26.02.10; + version = 26.02.13; }; }; 701C7BEF8F70F7A83E852DCC /* XCRemoteSwiftPackageReference "GZIP" */ = { diff --git a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 08dbcfd8c..92c104eeb 100644 --- a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -158,8 +158,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/element-hq/matrix-rust-components-swift", "state" : { - "revision" : "b4a065799c4b73d3c7c345ab13e701344568bd91", - "version" : "26.2.10" + "revision" : "113131fa5f779a22319b61525c3126ba63045fa0", + "version" : "26.2.13" } }, { diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index 0a4a8be66..82655baf2 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -134,7 +134,6 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg bugReportService = BugReportService(rageshakeURLPublisher: appSettings.bugReportRageshakeURL.publisher, applicationID: appSettings.bugReportApplicationID, sdkGitSHA: sdkGitSha(), - maxUploadSize: appSettings.bugReportMaxUploadSize, appHooks: appHooks) Self.setupSentry(bugReportService: bugReportService, appSettings: appSettings) diff --git a/ElementX/Sources/Application/Settings/AppSettings.swift b/ElementX/Sources/Application/Settings/AppSettings.swift index 328c876f2..02fbfc4a1 100644 --- a/ElementX/Sources/Application/Settings/AppSettings.swift +++ b/ElementX/Sources/Application/Settings/AppSettings.swift @@ -313,8 +313,6 @@ final class AppSettings { let bugReportSentryRustURL: URL? = Secrets.sentryRustDSN.map { URL(string: $0)! } // swiftlint:disable:this force_unwrapping /// The name allocated by the bug report server private(set) var bugReportApplicationID = "element-x-ios" - /// The maximum size of the upload request. Default value is just below CloudFlare's max request size. - let bugReportMaxUploadSize = 50 * 1024 * 1024 // MARK: - Analytics diff --git a/ElementX/Sources/Application/TargetConfiguration.swift b/ElementX/Sources/Application/TargetConfiguration.swift index 50004d476..681d5afa8 100644 --- a/ElementX/Sources/Application/TargetConfiguration.swift +++ b/ElementX/Sources/Application/TargetConfiguration.swift @@ -25,10 +25,12 @@ enum Target: String { } } - var logFilePrefix: String? { + var logFilePrefix: String { switch self { - case .mainApp: nil - default: rawValue + case .mainApp: + "console" + default: + rawValue } } diff --git a/ElementX/Sources/Other/Logging/Tracing.swift b/ElementX/Sources/Other/Logging/Tracing.swift index 6c61f6ba1..3bdc6f86a 100644 --- a/ElementX/Sources/Other/Logging/Tracing.swift +++ b/ElementX/Sources/Other/Logging/Tracing.swift @@ -10,9 +10,6 @@ import Foundation import MatrixRustSDK enum Tracing { - /// The base filename used for log files. This may be suffixed by the target - /// name and other log management metadata during rotation. - static let filePrefix = "console" /// The directory that stores all of the log files. static var logsDirectory: URL { if ProcessInfo.isRunningIntegrationTests { @@ -30,22 +27,13 @@ enum Tracing { .appGroupContainerDirectory } - static let fileExtension = "log" + static let fileExtension = ".log" - static func buildConfiguration(logLevel: LogLevel, traceLogPacks: Set, + static func buildConfiguration(logLevel: LogLevel, + traceLogPacks: Set, currentTarget: String, - filePrefix: String?, + filePrefix: String, sentryURL: URL?) -> TracingConfiguration { - let fileName = if let filePrefix { - "\(Tracing.filePrefix)-\(filePrefix)" - } else { - Tracing.filePrefix - } - - // Keep a minimum of 1 week of log files. In reality it will be longer - // as the app is unlikely to be running continuously. - let maxFiles: UInt64 = 24 * 7 - // Log everything on integration tests to check whether // the logs contain any sensitive data. See `integration-tests.yml` let level: LogLevel = ProcessInfo.isRunningIntegrationTests ? .trace : logLevel @@ -55,9 +43,11 @@ enum Tracing { extraTargets: [currentTarget], writeToStdoutOrSystem: true, writeToFiles: .init(path: logsDirectory.path(percentEncoded: false), - filePrefix: fileName, + filePrefix: filePrefix, fileSuffix: fileExtension, - maxFiles: maxFiles), + // Total compressed size needs to be under CloudFlare's max request size of 50Mb + maxTotalSizeBytes: 100 * 1024 * 1024, // 100Mb + maxAgeSeconds: 7 * 24 * 60 * 60), // One week sentryDsn: sentryURL?.absoluteString) } @@ -81,7 +71,7 @@ enum Tracing { let modificationDate = resourceValues.contentModificationDate else { continue } - if logURL.lastPathComponent.hasPrefix(filePrefix) { + if logURL.lastPathComponent.hasSuffix(fileExtension) { logFiles.append((logURL, modificationDate)) } } diff --git a/ElementX/Sources/Services/BugReport/BugReportService.swift b/ElementX/Sources/Services/BugReport/BugReportService.swift index 403fde08f..fe2a19914 100644 --- a/ElementX/Sources/Services/BugReport/BugReportService.swift +++ b/ElementX/Sources/Services/BugReport/BugReportService.swift @@ -16,7 +16,6 @@ class BugReportService: NSObject, BugReportServiceProtocol { private var rageshakeURL: RageshakeConfiguration private let applicationID: String private let sdkGitSHA: String - private let maxUploadSize: Int private let session: URLSession private let appHooks: AppHooks @@ -32,13 +31,11 @@ class BugReportService: NSObject, BugReportServiceProtocol { init(rageshakeURLPublisher: CurrentValuePublisher, applicationID: String, sdkGitSHA: String, - maxUploadSize: Int, session: URLSession = .shared, appHooks: AppHooks) { rageshakeURL = rageshakeURLPublisher.value self.applicationID = applicationID self.sdkGitSHA = sdkGitSHA - self.maxUploadSize = maxUploadSize self.session = session self.appHooks = appHooks @@ -210,7 +207,7 @@ class BugReportService: NSObject, BugReportServiceProtocol { private func zipFiles(_ logFiles: [URL]) async -> Logs { MXLog.info("zipFiles") - var compressedLogs = Logs(maxFileSize: maxUploadSize) + var compressedLogs = Logs() for url in logFiles { do { @@ -228,15 +225,6 @@ class BugReportService: NSObject, BugReportServiceProtocol { /// Zips a file creating chunks based on 10MB inputs. private func attachFile(at url: URL, to zippedFiles: inout Logs) throws { - // We check the compressed size to determine whether or not to attach the files. - // **However:** given our gzip library compresses in memory it is possible to OOM - // on files that will obviously be thrown away, so check the uncompressed size too. - let uncompressedSizeThreshold = maxUploadSize * 5 - if try FileManager.default.sizeForItem(at: url) > uncompressedSizeThreshold { - MXLog.error("Uncompressed logs too large, skipping attachment: \(url.lastPathComponent)") - return - } - let fileHandle = try FileHandle(forReadingFrom: url) while let data = try fileHandle.readToEnd() { @@ -254,9 +242,6 @@ class BugReportService: NSObject, BugReportServiceProtocol { /// A collection of logs to be uploaded to the bug report service. struct Logs { - /// The maximum total size of all the files. - let maxFileSize: Int - /// The files included. private(set) var files: [URL] = [] /// The total size of the files after compression. @@ -265,10 +250,6 @@ class BugReportService: NSObject, BugReportServiceProtocol { private(set) var originalSize = 0 mutating func appendFile(at url: URL, zippedSize: Int, originalSize: Int) { - guard self.zippedSize + zippedSize < maxFileSize else { - MXLog.error("Logs too large, skipping attachment: \(url.lastPathComponent)") - return - } files.append(url) self.originalSize += originalSize self.zippedSize += zippedSize diff --git a/UnitTests/Sources/BugReportServiceTests.swift b/UnitTests/Sources/BugReportServiceTests.swift index af6be553d..19131f141 100644 --- a/UnitTests/Sources/BugReportServiceTests.swift +++ b/UnitTests/Sources/BugReportServiceTests.swift @@ -55,7 +55,6 @@ class BugReportServiceTests: XCTestCase { let service = BugReportService(rageshakeURLPublisher: urlPublisher.asCurrentValuePublisher(), applicationID: "mock_app_id", sdkGitSHA: "1234", - maxUploadSize: ServiceLocator.shared.settings.bugReportMaxUploadSize, session: .mock, appHooks: AppHooks()) XCTAssertTrue(service.isEnabled) @@ -67,7 +66,6 @@ class BugReportServiceTests: XCTestCase { let service = BugReportService(rageshakeURLPublisher: urlPublisher.asCurrentValuePublisher(), applicationID: "mock_app_id", sdkGitSHA: "1234", - maxUploadSize: ServiceLocator.shared.settings.bugReportMaxUploadSize, session: .mock, appHooks: AppHooks()) XCTAssertFalse(service.isEnabled) @@ -79,7 +77,6 @@ class BugReportServiceTests: XCTestCase { let service = BugReportService(rageshakeURLPublisher: urlPublisher.asCurrentValuePublisher(), applicationID: "mock_app_id", sdkGitSHA: "1234", - maxUploadSize: ServiceLocator.shared.settings.bugReportMaxUploadSize, session: .mock, appHooks: AppHooks()) @@ -107,7 +104,6 @@ class BugReportServiceTests: XCTestCase { let service = BugReportService(rageshakeURLPublisher: appSettings.bugReportRageshakeURL.publisher, applicationID: "mock_app_id", sdkGitSHA: "1234", - maxUploadSize: ServiceLocator.shared.settings.bugReportMaxUploadSize, session: .mock, appHooks: AppHooks()) XCTAssertTrue(service.isEnabled) @@ -139,31 +135,6 @@ class BugReportServiceTests: XCTestCase { XCTAssertEqual(defaultConfigurationResponse.reportURL, initialURL.absoluteString.replacingOccurrences(of: "submit", with: "123")) } - - func testLogsMaxSize() { - // Given a new set of logs - var logs = BugReportService.Logs(maxFileSize: 1000) - XCTAssertEqual(logs.zippedSize, 0) - XCTAssertEqual(logs.originalSize, 0) - XCTAssertTrue(logs.files.isEmpty) - - // When adding new files within the size limit - logs.appendFile(at: .homeDirectory, zippedSize: 250, originalSize: 1000) - logs.appendFile(at: .picturesDirectory, zippedSize: 500, originalSize: 2000) - - // Then the logs should be included - XCTAssertEqual(logs.zippedSize, 750) - XCTAssertEqual(logs.originalSize, 3000) - XCTAssertEqual(logs.files, [.homeDirectory, .picturesDirectory]) - - // When adding a new file larger that will exceed the size limit - logs.appendFile(at: .homeDirectory, zippedSize: 500, originalSize: 2000) - - // Then the files shouldn't be included. - XCTAssertEqual(logs.zippedSize, 750) - XCTAssertEqual(logs.originalSize, 3000) - XCTAssertEqual(logs.files, [.homeDirectory, .picturesDirectory]) - } } private class MockURLProtocol: URLProtocol { diff --git a/UnitTests/Sources/LoggingTests.swift b/UnitTests/Sources/LoggingTests.swift index e7281744c..83e81a438 100644 --- a/UnitTests/Sources/LoggingTests.swift +++ b/UnitTests/Sources/LoggingTests.swift @@ -19,8 +19,9 @@ class LoggingTests: XCTestCase { Tracing.logsDirectoryOverride = nil try reloadTracingFileWriter(configuration: .init(path: URL.appGroupLogsDirectory.path(percentEncoded: false), filePrefix: "console-tests", - fileSuffix: "log", - maxFiles: 100)) + fileSuffix: ".log", + maxTotalSizeBytes: 1000, + maxAgeSeconds: 1000)) } func testFileLogging() throws { @@ -343,8 +344,9 @@ class LoggingTests: XCTestCase { if redirectTracingFileWriter { try reloadTracingFileWriter(configuration: .init(path: testDirectory.path(percentEncoded: false), filePrefix: "console", - fileSuffix: "log", - maxFiles: 100)) + fileSuffix: ".log", + maxTotalSizeBytes: 1000, + maxAgeSeconds: 1000)) } } } diff --git a/project.yml b/project.yml index 155367934..625f043bf 100644 --- a/project.yml +++ b/project.yml @@ -73,7 +73,7 @@ packages: # Element/Matrix dependencies MatrixRustSDK: url: https://github.com/element-hq/matrix-rust-components-swift - exactVersion: 26.02.10 + exactVersion: 26.02.13 # path: ../matrix-rust-sdk Compound: path: compound-ios