Skip to content

Commit

Permalink
Merge pull request #34 from flagship-io/dut_bugs
Browse files Browse the repository at this point in the history
Dut bugs
  • Loading branch information
ABTastyAdel authored Feb 6, 2024
2 parents 055ff77 + 79a58a0 commit e9e988d
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 62 deletions.
2 changes: 1 addition & 1 deletion FlagShip.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "FlagShip"
s.version = "3.3.1"
s.version = "3.3.2"
s.summary = "Flagship SDK"

# This description is used to generate tags and improve search results.
Expand Down
9 changes: 3 additions & 6 deletions FlagShip/FlagShipTests/FSDataUsageTrackingTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ final class FSDataUsageTrackingTest: XCTestCase {

/// Test Processing
func testTimeSlotTr() {

FSDataUsageTracking.sharedInstance._troubleshooting?.startDate = Date()
FSDataUsageTracking.sharedInstance._troubleshooting?.endDate = Date().addingTimeInterval(1000)
FSDataUsageTracking.sharedInstance.evaluateTroubleShootingConditions()
Expand All @@ -47,8 +46,6 @@ final class FSDataUsageTrackingTest: XCTestCase {
FSDataUsageTracking.sharedInstance._troubleshooting?.endDate = Date().addingTimeInterval(-100)
FSDataUsageTracking.sharedInstance.evaluateTroubleShootingConditions()
XCTAssertFalse(FSDataUsageTracking.sharedInstance.troubleShootingReportAllowed)


}

func testConsent() {
Expand All @@ -60,7 +57,7 @@ final class FSDataUsageTrackingTest: XCTestCase {
}

func testCreateCriticalFieldsForVisitor() {
let config: FlagshipConfig = FSConfigBuilder().withTimeout(12345).withLogLevel(.ERROR).Bucketing().build()
let config: FlagshipConfig = FSConfigBuilder().withTimeout(3).withLogLevel(.ERROR).Bucketing().build()

let consentVisitor: FSVisitor = FSVisitorBuilder("userTest").hasConsented(hasConsented: true).withContext(context: ["trCtx": "valCtx"]).build()

Expand All @@ -78,7 +75,7 @@ final class FSDataUsageTrackingTest: XCTestCase {
XCTAssertTrue((ret["sdk.config.mode"] ?? "") == "BUCKETING")
XCTAssertTrue((ret["sdk.config.trackingManager.strategy"] ?? "") == "CONTINUOUS_CACHING")
XCTAssertTrue((ret["visitor.context.trCtx"] ?? "") == "valCtx")
XCTAssertTrue((ret["sdk.config.timeout"] ?? "") == "12.345")
XCTAssertTrue((ret["sdk.config.timeout"] ?? "") == "3.0")
}

func testCreateCrticalXpc() {
Expand Down Expand Up @@ -120,7 +117,7 @@ final class FSDataUsageTrackingTest: XCTestCase {
FSDataUsageTracking.sharedInstance.configureWithVisitor(pVisitor: devUsageVisitor)
XCTAssertFalse(FSDataUsageTracking.sharedInstance.dataUsageTrackingReportAllowed)

config.disableDeveloperUsageTracking = false
config.disableDeveloperUsageTracking = false
FSDataUsageTracking.sharedInstance.dataUsageTrackingReportAllowed = true
XCTAssertTrue(FSDataUsageTracking.sharedInstance.dataUsageTrackingReportAllowed)
}
Expand Down
4 changes: 2 additions & 2 deletions FlagShip/Flagship.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 3.3.1;
MARKETING_VERSION = 3.3.2;
OTHER_LDFLAGS = "";
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = ABTasty.FlagShip;
Expand Down Expand Up @@ -1786,7 +1786,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 3.3.1;
MARKETING_VERSION = 3.3.2;
OTHER_LDFLAGS = "";
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = ABTasty.FlagShip;
Expand Down
1 change: 1 addition & 0 deletions FlagShip/Source/API/FSService+Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extension FSService {
onCompleted(data, nil)

} else {
FSDataUsageTracking.sharedInstance.processTSHttpError(requestType: type, response as? HTTPURLResponse, request, data)
onCompleted(nil, FlagshipError(type: .sendRequest, code: httpResponse.statusCode))
}
} else {
Expand Down
10 changes: 5 additions & 5 deletions FlagShip/Source/Core/FSFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class FSFlag: NSObject {
@objc public func value(visitorExposed: Bool = true)->Any? {
var result: Any?
if let flagModification = strategy?.getStrategy().getFlagModification(key) {
if isSameType_or_DefaultValue_Nil(flagModification.value){ /// _ have same type with default value OR the default value is nil
if isSameType_or_DefaultValue_Nil(flagModification.value) { /// _ have same type with default value OR the default value is nil
///
FlagshipLogManager.Log(level: .ALL, tag: .GET_MODIFICATION, messageToDisplay: .MESSAGE("The value of the flag `\(key)` is `\(flagModification.value)"))

Expand Down Expand Up @@ -57,7 +57,7 @@ public class FSFlag: NSObject {
@objc public func visitorExposed() {
if let flagModification = strategy?.getStrategy().getFlagModification(key) {
/// The activate can be activated event whatever the type if the flag's value is nil
if flagModification.value is NSNull || isSameType_or_DefaultValue_Nil(flagModification.value){
if flagModification.value is NSNull || isSameType_or_DefaultValue_Nil(flagModification.value) {
/// Activate the flag
strategy?.getStrategy().activateFlag(self)
} else {
Expand All @@ -67,8 +67,8 @@ public class FSFlag: NSObject {
}
} else {
FlagshipLogManager.Log(level: .ALL, tag: .ACTIVATE, messageToDisplay: FSLogMessage.MESSAGE("Return the default value due to the Type error"))
// Send TRon vistor expose and not found
FSDataUsageTracking.sharedInstance.proceesTSFlag(crticalPointLabel: .VISITOR_EXPOSED_FLAG_NO_FOUND, f: self, v: strategy?.visitor)
// Send TR on flag not found
FSDataUsageTracking.sharedInstance.proceesTSFlag(crticalPointLabel: .VISITOR_EXPOSED_FLAG_NOT_FOUND, f: self, v: strategy?.visitor)
}
}

Expand All @@ -78,7 +78,7 @@ public class FSFlag: NSObject {

@objc public func metadata()->FSFlagMetadata {
if let flagModification = strategy?.getStrategy().getFlagModification(key) {
if flagModification.value is NSNull || isSameType_or_DefaultValue_Nil(flagModification.value){
if flagModification.value is NSNull || isSameType_or_DefaultValue_Nil(flagModification.value) {
return FSFlagMetadata(flagModification)
}
}
Expand Down
54 changes: 35 additions & 19 deletions FlagShip/Source/Logger/FSLogManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

@objc public enum FSLevel:Int{
@objc public enum FSLevel: Int {
/**
* NONE = 0: Logging will be disabled.
*/
Expand Down Expand Up @@ -36,38 +36,54 @@ import Foundation
* ALL = 6: All logs will be logged.
*/
case ALL

var name: String {
var ret = ""
switch self {
case .NONE:
ret = "NONE"
case .EXCEPTIONS:
ret = "EXCEPTIONS"
case .ERROR:
ret = "ERROR"
case .WARNING:
ret = "WARNING"
case .DEBUG:
ret = "DEBUG"
case .INFO:
ret = "INFO"
case .ALL:
ret = "ALL"
}
return ret
}
}

public class FSLogManager {


init(){

init() {
_level = .ALL
}

internal var _level:FSLevel
var _level: FSLevel

internal var level:FSLevel{

get{
var level: FSLevel {
get {
return _level
}
set{
set {
_level = newValue
}
}

/**
* Called when the SDK produce a log.
* @param level log level.
* @param tag location where the log come from.
* @param message log message.
*/
func onLog(level:FSLevel, tag:String, message:String){

}
* Called when the SDK produce a log.
* @param level log level.
* @param tag location where the log come from.
* @param message log message.
*/
func onLog(level: FSLevel, tag: String, message: String) {}

func getLevel()->FSLevel{
func getLevel() -> FSLevel {
return _level
}
}
Expand Down
2 changes: 1 addition & 1 deletion FlagShip/Source/Tools/FlagShipVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ import Foundation

/// This file is automatically updated 2.0.0

public let FlagShipVersion = "3.3.1"
public let FlagShipVersion = "3.3.2"
35 changes: 32 additions & 3 deletions FlagShip/Source/Troubleshooting/FSDataReportUsage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ let troubleShootingVersion = "1"
let stackType = "SDK"
let stackName = "iOS"

// This enum describe the level gievn to hits Troubleshooting or DeveloperUsage
enum HitUsageLevel: String {
case INFO
case ERROR
case WARNING
}

class TroubleshootingHit: FSTracking {
// Commun Fields
var _communCustomFields: [String: String] = [:]
Expand All @@ -23,12 +30,33 @@ class TroubleshootingHit: FSTracking {
// Label for the critical point
var label: String = ""

// Level by default is INFO
var hitLevelUsage: HitUsageLevel = .INFO

init(pVisitorId: String, pLabel: String, pSpeceficCustomFields: [String: String]) {
super.init()
// Set the vid
visitorId = pVisitorId

// Set the Type
type = .TROUBLESHOOTING
self.label = pLabel

// Set The Label
label = pLabel

// Set Level according to the type
if label.contains("ERROR") {
hitLevelUsage = .ERROR
} else if label.contains("WARNING") || label.contains("FLAG_NOT_FOUND") {
hitLevelUsage = .WARNING
} else {
hitLevelUsage = .INFO
}

// Fill with a specefic values
speceficCustomFields.merge(pSpeceficCustomFields) { _, new in new }

// Fill the commun CV dico
fillTheCommunFieldsAndCompleteWithCustom()
}

Expand Down Expand Up @@ -60,7 +88,8 @@ class TroubleshootingHit: FSTracking {
"stack.name": stackName,
"stack.version": FlagShipVersion,
"flagshipInstanceId":
FSTools.generateUuidv4()
FSTools.generateUuidv4(),
"logLevel": hitLevelUsage.rawValue
]
_communCustomFields.merge(speceficCustomFields) { _, new in new }
}
Expand Down Expand Up @@ -103,7 +132,7 @@ enum CriticalPoints: String {
// Trigger when the Flag.getValue method is called and no flag is found
case GET_FLAG_VALUE_FLAG_NOT_FOUND
// Trigger when the Flag.visitorExposed method is called and no flag is found
case VISITOR_EXPOSED_FLAG_NO_FOUND
case VISITOR_EXPOSED_FLAG_NOT_FOUND
// Trigger when the Flag.visitorExposed method is called and the flag value has a different type with default value
case GET_FLAG_VALUE_TYPE_WARNING
// Trigger when the SDK catches any other error but those listed here.
Expand Down
25 changes: 13 additions & 12 deletions FlagShip/Source/Troubleshooting/FSDataUsageTracking+Criticals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extension FSDataUsageTracking {
"http.request.url": request.url?.absoluteString ?? "",
"http.response.body": String(data?.prettyPrintedJSONString ?? ""),
"http.response.headers": response?.allHeaderFields.description ?? "",
"http.response.code": String(describing: response?.statusCode)
"http.response.code": String(describing: response?.statusCode ?? 0)
]
criticalJson.merge(httpFields) { _, new in new }

Expand All @@ -73,7 +73,7 @@ extension FSDataUsageTracking {
sendTroubleshootingReport(_trHit:
TroubleshootingHit(pVisitorId: _visitorId, pLabel: criticalLabel, pSpeceficCustomFields: criticalJson))
}

// Process http on bucketing error
func processTSHttp(crticalPointLabel: CriticalPoints, _ response: HTTPURLResponse?, _ request: URLRequest, _ data: Data? = nil) {
var criticalJson: [String: String] = ["visitor.sessionId": _visitorSessionId,
Expand All @@ -84,14 +84,14 @@ extension FSDataUsageTracking {
"http.request.url": request.url?.absoluteString ?? "",
"http.response.body": String(data?.prettyPrintedJSONString ?? ""),
"http.response.headers": response?.allHeaderFields.description ?? "",
"http.response.code": String(describing: response?.statusCode)
"http.response.code": String(describing: response?.statusCode ?? 0)
]
criticalJson.merge(httpFields) { _, new in new }
// Send TS report
sendTroubleshootingReport(_trHit:
TroubleshootingHit(pVisitorId: _visitorId, pLabel: crticalPointLabel.rawValue, pSpeceficCustomFields: criticalJson))
}

// Process on download bucketing file
func processTSBucketingFile(_ response: HTTPURLResponse?, _ request: URLRequest, _ data: Data) {
var criticalJson: [String: String] = ["visitor.sessionId": _visitorSessionId,
Expand All @@ -102,7 +102,7 @@ extension FSDataUsageTracking {
"http.request.url": request.url?.absoluteString ?? "",
"http.response.body": String(data.prettyPrintedJSONString ?? ""),
"http.response.headers": response?.allHeaderFields.description ?? "",
"http.response.code": String(describing: response?.statusCode)
"http.response.code": String(describing: response?.statusCode ?? 0)
]
criticalJson.merge(httpFields) { _, new in new }
// Send TS report
Expand Down Expand Up @@ -147,7 +147,7 @@ extension FSDataUsageTracking {
sendTroubleshootingReport(_trHit: TroubleshootingHit(
pVisitorId: v.visitorId, pLabel: CriticalPoints.VISITOR_FETCH_CAMPAIGNS.rawValue, pSpeceficCustomFields: criticalJson))
}

// Process on authenticate
func processTSXPC(label: String, visitor: FSVisitor) {
var criticalJson: [String: String] = [:]
Expand Down Expand Up @@ -247,17 +247,18 @@ extension FSDataUsageTracking {
configFields = [
"sdk.status": Flagship.sharedInstance.currentStatus.name,
"sdk.config.mode": (aSdkConfig.mode == .DECISION_API) ? "DECISION_API" : "BUCKETING",
"sdk.config.timeout": String(aSdkConfig.timeout),
"sdk.config.pollingTime": String(aSdkConfig.pollingTime),
"sdk.config.timeout": String(aSdkConfig.timeout * 1000),
"sdk.config.pollingTime": String(aSdkConfig.pollingTime * 1000),
"sdk.config.usingCustomLogManager": "false",
"sdk.config.usingCustomHitCache": String(aSdkConfig.cacheManager.hitCacheDelegate is FSDefaultCacheHit),
"sdk.config.usingCustomVisitorCache": String(aSdkConfig.cacheManager.cacheVisitorDelegate is FSDefaultCacheVisitor),
"sdk.config.usingCustomHitCache": String(!(aSdkConfig.cacheManager.hitCacheDelegate is FSDefaultCacheHit)),
"sdk.config.usingCustomVisitorCache": String(!(aSdkConfig.cacheManager.cacheVisitorDelegate is FSDefaultCacheVisitor)),
"sdk.config.usingOnVisitorExposed": String(aSdkConfig.onVisitorExposed != nil),
"sdk.config.decisionApiUrl": FlagShipEndPoint,
"sdk.config.trackingManager.strategy": aSdkConfig.trackingConfig.strategy.name,
"sdk.config.trackingManager.batchIntervals": String(aSdkConfig.trackingConfig.batchIntervalTimer),
"sdk.config.trackingManager.batchIntervals": String(aSdkConfig.trackingConfig.batchIntervalTimer * 1000),
"sdk.config.trackingManager.poolMaxSize": String(aSdkConfig.trackingConfig.poolMaxSize),
"sdk.lastInitializationTimestamp": String(Flagship.sharedInstance.lastInitializationTimestamp)
"sdk.lastInitializationTimestamp": String(Flagship.sharedInstance.lastInitializationTimestamp),
"sdk.config.logLevel": aSdkConfig.logLevel.name
]
}
return configFields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension FSDataUsageTracking {
formatDate.dateFormat = "yyyyMMdd"
let combinedId: String = _visitorId + formatDate.string(from: Date())

let hashAlloc = Int(MurmurHash3.hash32(key: combinedId) % 100)
let hashAlloc = Int(MurmurHash3.hash32(key: combinedId) % 1000)

// print(" -------- The hashalloc for \(combinedId) is \(hashAlloc) ----------")

Expand Down
2 changes: 1 addition & 1 deletion FlagShip/Source/Troubleshooting/FSDataUsageTracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

// Allocation threshold for data usage tracking
let FSDataUsageAllocationThreshold = 20
let FSDataUsageAllocationThreshold = 1

class FSDataUsageTracking {
var visitorSessionId: String = FSTools.generateUuidv4()
Expand Down
Loading

0 comments on commit e9e988d

Please sign in to comment.