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

[iOS] Remove URP debug logging (uplift to 1.71.x) #25620

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ios/brave-ios/App/iOS/Delegates/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Clean Logger for Secure content state
DebugLogger.cleanLogger(for: .secureState)

// Clean Logger for URP (no longer used)
DebugLogger.cleanUrpLogs()

return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1048,17 +1048,6 @@ class SettingsViewController: TableViewController {
accessory: .disclosureIndicator,
cellClass: MultilineValue1Cell.self
),
Row(
text: "View URP Logs",
selection: { [unowned self] in
self.navigationController?.pushViewController(
DebugLogViewController(type: .urp),
animated: true
)
},
accessory: .disclosureIndicator,
cellClass: MultilineValue1Cell.self
),
Row(text: "URP Code: \(UserReferralProgram.getReferralCode() ?? "--")"),
Row(
text: "BraveCore Switches",
Expand Down
13 changes: 6 additions & 7 deletions ios/brave-ios/Sources/BraveShared/DebugLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import Shared
import UIKit

public enum LoggerType {
case urp, secureState
case secureState

var prefsKey: String {
switch self {
case .urp:
return "urpLogs"
case .secureState:
return "secureStateLogs"
}
Expand Down Expand Up @@ -49,8 +47,6 @@ public struct DebugLogger {
case .secureState:
logs.append("------------------------------------\n\n")
logs.append(" [\(time)]\n\n \(text)\n")
case .urp:
logs.append("[\(time)] \(text)\n")
}

UserDefaults.standard.set(logs, forKey: type.prefsKey)
Expand All @@ -59,6 +55,11 @@ public struct DebugLogger {
public static func cleanLogger(for type: LoggerType) {
UserDefaults.standard.removeObject(forKey: type.prefsKey)
}

public static func cleanUrpLogs() {
// Delete the no-longer used urp logs if they exist
UserDefaults.standard.removeObject(forKey: "urpLogs")
}
}

public class DebugLogViewController: UIViewController {
Expand All @@ -78,8 +79,6 @@ public class DebugLogViewController: UIViewController {
super.viewDidLoad()

switch loggerType {
case .urp:
title = "URP Logs"
case .secureState:
title = "Secure Content State"
}
Expand Down
4 changes: 0 additions & 4 deletions ios/brave-ios/Sources/Growth/DAU.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public class DAU {
@objc private func sendPingToServerInternal() {
guard let paramsAndPrefs = paramsAndPrefsSetup(for: Date()) else {
Logger.module.debug("dau, no changes detected, no server ping")
DebugLogger.log(for: .urp, text: "dau, no changes detected, no server ping")
return
}

Expand All @@ -123,7 +122,6 @@ public class DAU {
}

Logger.module.debug("send ping to server, url: \(pingRequestUrl)")
DebugLogger.log(for: .urp, text: "send ping to server, url: \(pingRequestUrl)")

var request = URLRequest(url: pingRequestUrl)
for (key, value) in paramsAndPrefs.headers {
Expand All @@ -137,7 +135,6 @@ public class DAU {

if let e = error {
Logger.module.error("status update error: \(e.localizedDescription)")
DebugLogger.log(for: .urp, text: "status update error: \(e)")
return
}

Expand Down Expand Up @@ -224,7 +221,6 @@ public class DAU {

if let referralCode = UserReferralProgram.getReferralCode() {
params.append(URLQueryItem(name: "ref", value: referralCode))
DebugLogger.log(for: .urp, text: "DAU ping with added ref, params: \(params)")
}

let lastPingTimestamp = [Int((date).timeIntervalSince1970)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,11 @@ public struct AdAttributionData {
// They will indicate if the Apple Searhs Ads is clicked and for which campaign
guard let attribution = json["attribution"] as? Bool else {
Logger.module.error("Failed to unwrap json to Ad Attribution property.")
DebugLogger.log(for: .urp, text: "Failed to unwrap json to Ad Attribution property. \(json)")

throw SerializationError.missing("Attribution Context")
}

guard let campaignId = json["campaignId"] as? Int else {
Logger.module.error("Failed to unwrap json to Campaign Id property.")
DebugLogger.log(for: .urp, text: "Failed to unwrap json to Campaign Id property. \(json)")

throw SerializationError.missing("Campaign Id")
}

Expand Down
1 change: 0 additions & 1 deletion ios/brave-ios/Sources/Growth/URP/ReferralData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ struct ReferralData {
guard let downloadId = json["download_id"].string, let code = json["referral_code"].string
else {
Logger.module.error("Failed to unwrap json to Referral struct.")
DebugLogger.log(for: .urp, text: "Failed to unwrap json to Referral struct. \(json)")
return nil
}

Expand Down
10 changes: 0 additions & 10 deletions ios/brave-ios/Sources/Growth/URP/UrpService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ struct UrpService {
) {
guard var endPoint = URL(string: host) else {
completion(nil, .endpointError)
DebugLogger.log(for: .urp, text: "Host not a url: \(host)")
return
}

Expand All @@ -76,19 +75,12 @@ struct UrpService {
)
}

DebugLogger.log(for: .urp, text: "Referral code lookup response: \(data)")

let json = JSON(data)
let referral = ReferralData(json: json)
completion(referral, nil)

case .failure(let error):
Logger.module.error("Referral code lookup response: \(error.localizedDescription)")
DebugLogger.log(
for: .urp,
text: "Referral code lookup response: \(error.localizedDescription)"
)

completion(nil, .endpointError)
}
}
Expand All @@ -113,7 +105,6 @@ struct UrpService {
isRetryEnabled: isRetryEnabled,
timeout: timeout
)
DebugLogger.log(for: .urp, text: "Ad Attribution response: \(result)")

if let resultData = result as? Data {
let jsonResponse =
Expand Down Expand Up @@ -146,7 +137,6 @@ struct UrpService {

do {
let (result, _) = try await sessionManager.adGroupsReportApiRequest(endPoint: endPoint)
DebugLogger.log(for: .urp, text: "Ad Groups Report response: \(result)")

if let resultData = result as? Data {
let adGroupsReportData = try AdGroupReportData(data: resultData, keywordId: keywordId)
Expand Down
36 changes: 3 additions & 33 deletions ios/brave-ios/Sources/Growth/URP/UserReferralProgram.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public class UserReferralProgram {
adReportsURL: adReportsURLString
)

DebugLogger.log(for: .urp, text: "URP init, host: \(host)")

self.service = urpService
}

Expand All @@ -61,16 +59,10 @@ public class UserReferralProgram {
refCode: String? = nil,
completion: @escaping (_ refCode: String?, _ offerUrl: String?) -> Void
) {
DebugLogger.log(for: .urp, text: "first run referral lookup")

let referralBlock: (ReferralData?, UrpError?) -> Void = { [weak self] referral, error in
guard let self = self else { return }

if error == Growth.UrpError.endpointError {
DebugLogger.log(
for: .urp,
text: "URP look up had endpoint error, will retry on next launch."
)
self.referralLookupRetry.timer?.invalidate()
self.referralLookupRetry.timer = nil

Expand All @@ -95,17 +87,12 @@ public class UserReferralProgram {
Preferences.URP.referralLookupOutstanding.value = false
guard let ref = referral else {
Logger.module.info("No referral code found")
DebugLogger.log(for: .urp, text: "No referral code found")
completion(nil, nil)
return
}

if ref.isExtendedUrp() {
completion(ref.referralCode, ref.offerPage)
DebugLogger.log(
for: .urp,
text: "Extended referral code found, opening landing page: \(ref.offerPage ?? "404")"
)
// We do not want to persist referral data for extended URPs
return
}
Expand All @@ -116,10 +103,6 @@ public class UserReferralProgram {
self.referralLookupRetry.timer?.invalidate()
self.referralLookupRetry.timer = nil

DebugLogger.log(
for: .urp,
text: "Found referral: downloadId: \(ref.downloadId), code: \(ref.referralCode)"
)
// In case of network errors or getting `isFinalized = false`, we retry the api call.
self.initRetryPingConnection(numberOfTimes: 30)

Expand Down Expand Up @@ -192,13 +175,12 @@ public class UserReferralProgram {

public func pingIfEnoughTimePassed() {
if !DeviceInfo.hasConnectivity() {
DebugLogger.log(for: .urp, text: "No internet connection, not sending update ping.")
Logger.module.info("No internet connection, not sending update ping.")
return
}

guard let downloadId = Preferences.URP.downloadId.value else {
Logger.module.info("Could not retrieve download id model from preferences.")
DebugLogger.log(for: .urp, text: "Update ping, no download id found.")
return
}

Expand All @@ -211,11 +193,9 @@ public class UserReferralProgram {

if todayInSeconds <= checkDate {
Logger.module.debug("Not enough time has passed for referral ping.")
DebugLogger.log(for: .urp, text: "Not enough time has passed for referral ping.")
return
}

DebugLogger.log(for: .urp, text: "Update ping")
service.checkIfAuthorizedForGrant(with: downloadId) { initialized, error in
guard let counter = Preferences.URP.retryCountdown.value else {
Logger.module.error("Could not retrieve retry countdown from preferences.")
Expand All @@ -225,33 +205,23 @@ public class UserReferralProgram {
var shouldRemoveData = false

if error == .downloadIdNotFound {
DebugLogger.log(for: .urp, text: "Download id not found on server.")
shouldRemoveData = true
}

if initialized == true {
DebugLogger.log(for: .urp, text: "Got initialized = true from server.")
shouldRemoveData = true
}

// Last retry attempt
if counter <= 1 {
DebugLogger.log(for: .urp, text: "Last retry and failed to get data from server.")
shouldRemoveData = true
}

if shouldRemoveData {
DebugLogger.log(for: .urp, text: "Removing all referral data from device")

Preferences.URP.downloadId.value = nil
Preferences.URP.nextCheckDate.value = nil
Preferences.URP.retryCountdown.value = nil
} else {
DebugLogger.log(
for: .urp,
text:
"Network error or isFinalized returned false, decrementing retry counter and trying again next time."
)
// Decrement counter, next retry happens on next day
Preferences.URP.retryCountdown.value = counter - 1
Preferences.URP.nextCheckDate.value = checkDate + 1.days
Expand All @@ -266,13 +236,13 @@ public class UserReferralProgram {
{
Preferences.URP.referralCode.value = nil
Preferences.URP.referralCodeDeleteDate.value = nil
DebugLogger.log(for: .urp, text: "Enough time has passed, removing referral code data")
Logger.module.info("Enough time has passed, removing referral code data")
return nil
} else if let referralCode = Preferences.URP.referralCode.value {
// Appending ref code to dau ping if user used installed the app via
// user referral program or apple search ad
if Preferences.URP.referralCodeDeleteDate.value == nil {
DebugLogger.log(for: .urp, text: "Setting new date for deleting referral code.")
Logger.module.info("Setting new date for deleting referral code.")
let timeToDelete = AppConstants.isOfficialBuild ? 90.days : 20.minutes
Preferences.URP.referralCodeDeleteDate.value = Date().timeIntervalSince1970 + timeToDelete
}
Expand Down
Loading