Skip to content

Commit

Permalink
Add TypeMismatch error
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria committed Nov 6, 2024
1 parent a38224b commit af593ea
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct ContentView: View {
.padding(10)
Text(text.text)
Button("Get remote flag value") {
let test = confidence.getEvaluation(key: "swift-demoapp.color", defaultValue: true)
print("\(test)")
text.text = confidence.getValue(key: "swift-demoapp.color", defaultValue: "ERROR")
if text.text == "Green" {
color.color = .green
Expand Down
3 changes: 1 addition & 2 deletions Sources/Confidence/Confidence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ public class Confidence: ConfidenceEventSender {
return self.cache.evaluate(
flagName: key,
defaultValue: defaultValue,
// TMP - TESTING (force a different context, causing STALE)
context: ["test":ConfidenceValue(null: ())],
context: getContext(),
flagApplier: flagApplier
)
}
Expand Down
22 changes: 18 additions & 4 deletions Sources/Confidence/Telemetry/TelemetryManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import Foundation

protocol TelemetryManager {
func incrementStaleAccess()
func incrementFlagTypeMismatch()
func getSnapshot() -> TelemetryPayload
}

class Telemetry: TelemetryManager {
private let queue = DispatchQueue(label: "com.confidence.telemetry_manager")
private var staleAccessCounter = 0;

Check failure on line 11 in Sources/Confidence/Telemetry/TelemetryManager.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Semicolon Violation: Lines should not have trailing semicolons (trailing_semicolon)
private var flagTypeMismatchCounter = 0;

Check failure on line 12 in Sources/Confidence/Telemetry/TelemetryManager.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Semicolon Violation: Lines should not have trailing semicolons (trailing_semicolon)

public init() {}

static public let shared: TelemetryManager = Telemetry()
static public let shared: TelemetryManager = Telemetry.init()

public func getSnapshot() -> TelemetryPayload {
return queue.sync {
TelemetryPayload(staleAccess: getStaleAccessAndReset())
}
TelemetryPayload(flagMismatch: getFlagTypeMismatch(), staleAccess: getStaleAccessAndReset())
}

public func incrementStaleAccess() {
Expand All @@ -25,11 +25,25 @@ class Telemetry: TelemetryManager {
}
}

public func incrementFlagTypeMismatch() {
queue.sync {
flagTypeMismatchCounter += 1
}
}

private func getStaleAccessAndReset() -> Int {
return queue.sync {
let currentCounter = staleAccessCounter
staleAccessCounter = 0;

Check failure on line 37 in Sources/Confidence/Telemetry/TelemetryManager.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Semicolon Violation: Lines should not have trailing semicolons (trailing_semicolon)
return currentCounter
}
}

private func getFlagTypeMismatch() -> Int {
return queue.sync {
let currentCounter = flagTypeMismatchCounter
flagTypeMismatchCounter = 0;

Check failure on line 45 in Sources/Confidence/Telemetry/TelemetryManager.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Semicolon Violation: Lines should not have trailing semicolons (trailing_semicolon)
return currentCounter
}
}
}
1 change: 1 addition & 0 deletions Sources/Confidence/Telemetry/TelemetryPayload.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation

struct TelemetryPayload: Encodable {
var flagMismatch = 0
var staleAccess = 0
}

0 comments on commit af593ea

Please sign in to comment.