Tracing and integration test tweaks (#3336)

* Disable image and document picker integration tests as they randomly fail to load and are flakey.

* Delete any pre-existing log files

* Various tracing tweaks and fixes:
- delete the custom tracing log levels as we can't control their ouput
- implement comparable on them
- change default levels only if the new chosen level increases their verbosity

* Make logging targets mandatory and fix their logging levels

* Switch back to using the `run_tests` reset simulator flag as `fastlane snapshot reset_simulators` was too generic and slow

* Switch all integration test taps to `tapCenter` (nee forceTap) after noticing missed taps on CI.

* Make the logging file prefix explicit, let the main app not use one.

* Rename tracing configuration `target` to `currentTarget`
This commit is contained in:
Stefan Ceriu
2024-09-27 15:08:47 +03:00
committed by GitHub
parent df6d0a999f
commit 9d23dec2e9
16 changed files with 126 additions and 138 deletions
@@ -70,7 +70,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
let appSettings = appHooks.appSettingsHook.configure(AppSettings())
MXLog.configure(logLevel: appSettings.logLevel)
MXLog.configure(currentTarget: "elementx", filePrefix: nil, logLevel: appSettings.logLevel)
let appName = InfoPlistReader.main.bundleDisplayName
let appVersion = InfoPlistReader.main.bundleShortVersionString
@@ -9,7 +9,7 @@ import XCTest
extension XCUIElement {
func clearAndTypeText(_ text: String) {
forceTap()
tapCenter()
guard let currentValue = value as? String else {
XCTFail("Tried to clear and type text into a non string value")
@@ -24,7 +24,7 @@ extension XCUIElement {
}
}
func forceTap() {
func tapCenter() {
let coordinate: XCUICoordinate = coordinate(withNormalizedOffset: .init(dx: 0.5, dy: 0.5))
coordinate.tap()
}
+8 -11
View File
@@ -22,21 +22,18 @@ enum MXLog {
private static var didConfigureOnce = false
private static var rootSpan: Span!
private static var target: String!
private static var currentTarget: String!
static func configure(target: String? = nil,
static func configure(currentTarget: String,
filePrefix: String?,
logLevel: TracingConfiguration.LogLevel) {
guard !didConfigureOnce else { return }
RustTracing.setup(configuration: .init(logLevel: logLevel, target: target))
RustTracing.setup(configuration: .init(logLevel: logLevel, currentTarget: currentTarget, filePrefix: filePrefix))
if let target {
self.target = target
} else {
self.target = Constants.target
}
self.currentTarget = currentTarget
rootSpan = Span(file: #file, line: #line, level: .info, target: self.target, name: "root")
rootSpan = Span(file: #file, line: #line, level: .info, target: self.currentTarget, name: "root")
rootSpan.enter()
didConfigureOnce = true
@@ -138,7 +135,7 @@ enum MXLog {
rootSpan.enter()
}
return Span(file: file, line: UInt32(line), level: level, target: target, name: name)
return Span(file: file, line: UInt32(line), level: level, target: currentTarget, name: name)
}
// periphery:ignore:parameters function,column,context
@@ -157,6 +154,6 @@ enum MXLog {
rootSpan.enter()
}
logEvent(file: (file as NSString).lastPathComponent, line: UInt32(line), level: level, target: target, message: "\(message)")
logEvent(file: (file as NSString).lastPathComponent, line: UInt32(line), level: level, target: currentTarget, message: "\(message)")
}
}
@@ -32,7 +32,7 @@ enum RustTracing {
// Log everything on integration tests to check whether
// the logs contain any sensitive data. See `UserFlowTests.swift`
let filter = if ProcessInfo.isRunningIntegrationTests {
TracingConfiguration(logLevel: .trace, target: nil).filter
TracingConfiguration(logLevel: .trace, currentTarget: "integrationtests", filePrefix: nil).filter
} else {
configuration.filter
}
@@ -11,9 +11,8 @@ import Collections
// We can filter by level, crate and even file. See more details here:
// https://docs.rs/tracing-subscriber/0.2.7/tracing_subscriber/filter/struct.EnvFilter.html#examples
struct TracingConfiguration {
enum LogLevel: Codable, Hashable {
enum LogLevel: String, Codable, Hashable, Comparable {
case error, warn, info, debug, trace
case custom(String)
var title: String {
switch self {
@@ -27,34 +26,32 @@ struct TracingConfiguration {
return "Debug"
case .trace:
return "Trace"
case .custom:
return "Custom"
}
}
fileprivate var rawValue: String {
switch self {
case .error:
return "error"
case .warn:
return "warn"
case .info:
return "info"
case .debug:
return "debug"
case .trace:
return "trace"
case .custom(let filter):
return filter
static func < (lhs: TracingConfiguration.LogLevel, rhs: TracingConfiguration.LogLevel) -> Bool {
switch (lhs, rhs) {
case (.error, _):
true
case (.warn, .error):
false
case (.warn, _):
true
case (.info, .error), (.info, .warn):
false
case (.info, _):
true
case (.debug, .error), (.debug, .warn), (.debug, .info):
false
case (.debug, _):
true
case (.trace, _):
false
}
}
}
enum Target: String {
case common = ""
case elementx
case hyper, matrix_sdk_ffi, matrix_sdk_crypto
case matrix_sdk_client = "matrix_sdk::client"
@@ -66,9 +63,8 @@ struct TracingConfiguration {
case matrix_sdk_ui_timeline = "matrix_sdk_ui::timeline"
}
// The `common` target is excluded because 3rd-party crates might end up logging user data.
static let targets: OrderedDictionary<Target, LogLevel> = [
.common: .info, // Never set this lower than info - 3rd-party crates may start logging user data.
.elementx: .info,
.hyper: .warn,
.matrix_sdk_ffi: .info,
.matrix_sdk_client: .trace,
@@ -92,33 +88,30 @@ struct TracingConfiguration {
/// - Parameter logLevel: the desired log level
/// - Parameter target: the name of the target being configured
/// - Returns: a custom tracing configuration
init(logLevel: LogLevel, target: String?) {
fileName = if let target {
"\(RustTracing.filePrefix)-\(target)"
init(logLevel: LogLevel, currentTarget: String, filePrefix: String?) {
fileName = if let filePrefix {
"\(RustTracing.filePrefix)-\(filePrefix)"
} else {
RustTracing.filePrefix
}
if case let .custom(filter) = logLevel {
self.filter = filter
return
}
let overrides = Self.targets.keys.reduce(into: [Target: LogLevel]()) { partialResult, target in
// Keep the defaults here
let ignoredTargets: [Target] = [.common, // Never remove common from the ignored targets (see above for more info).
.hyper,
.matrix_sdk_ffi,
.matrix_sdk_oidc,
.matrix_sdk_client,
.matrix_sdk_crypto,
.matrix_sdk_crypto_account,
.matrix_sdk_http_client]
let ignoredTargets: [Target] = [.hyper]
if ignoredTargets.contains(target) {
return
}
partialResult[target] = logLevel
guard let defaultTargetLogLevel = Self.targets[target] else {
return
}
// Only change the targets that have default values
// smaller than the desired log level
if defaultTargetLogLevel < logLevel {
partialResult[target] = logLevel
}
}
var newTargets = Self.targets
@@ -126,7 +119,7 @@ struct TracingConfiguration {
newTargets.updateValue(logLevel, forKey: target)
}
let components = newTargets.map { (target: Target, logLevel: LogLevel) in
var components = newTargets.map { (target: Target, logLevel: LogLevel) in
guard !target.rawValue.isEmpty else {
return logLevel.rawValue
}
@@ -134,6 +127,10 @@ struct TracingConfiguration {
return "\(target.rawValue)=\(logLevel.rawValue)"
}
// With `common` not being used we manually need to specify the log
// level for passed in targets
components.append("\(currentTarget)=\(logLevel.rawValue)")
filter = components.joined(separator: ",")
}
}
@@ -135,18 +135,6 @@ struct DeveloperOptionsScreen: View {
private struct LogLevelConfigurationView: View {
@Binding var logLevel: TracingConfiguration.LogLevel
@State private var customTracingConfiguration: String
init(logLevel: Binding<TracingConfiguration.LogLevel>) {
_logLevel = logLevel
if case .custom(let configuration) = logLevel.wrappedValue {
customTracingConfiguration = configuration
} else {
customTracingConfiguration = TracingConfiguration(logLevel: .info, target: nil).filter
}
}
var body: some View {
Picker(selection: $logLevel) {
ForEach(logLevels, id: \.self) { logLevel in
@@ -156,24 +144,11 @@ private struct LogLevelConfigurationView: View {
Text("Log level")
Text("Requires app reboot")
}
if case .custom = logLevel {
TextEditor(text: $customTracingConfiguration)
.textInputAutocapitalization(.never)
.autocorrectionDisabled()
.onChange(of: customTracingConfiguration) { newValue in
logLevel = .custom(newValue)
}
}
}
/// Allows the picker to work with associated values
private var logLevels: [TracingConfiguration.LogLevel] {
if case let .custom(filter) = logLevel {
return [.error, .warn, .info, .debug, .trace, .custom(filter)]
} else {
return [.error, .warn, .info, .debug, .trace, .custom("")]
}
[.error, .warn, .info, .debug, .trace]
}
}
@@ -30,7 +30,7 @@ class UITestsAppCoordinator: AppCoordinatorProtocol, SecureWindowManagerDelegate
windowManager.delegate = self
MXLog.configure(logLevel: .debug)
MXLog.configure(currentTarget: "uitests", filePrefix: nil, logLevel: .debug)
ServiceLocator.shared.register(userIndicatorController: UserIndicatorController())