Skip to content

Commit

Permalink
Merge pull request #108 from getditto/BP/health_metrics_fix
Browse files Browse the repository at this point in the history
Fix Health Metrics properly emitting
  • Loading branch information
bplattenburg authored May 9, 2024
2 parents a8ad598 + fa46570 commit 5e8e1f5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
18 changes: 17 additions & 1 deletion Sources/DittoHeartbeat/HeartbeatModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public extension DittoHeartbeatInfo {
String.sdk: sdk,
String.presenceSnapshotDirectlyConnectedPeersCount: presenceSnapshotDirectlyConnectedPeers.count,
String.presenceSnapshotDirectlyConnectedPeers: connectionsValue(),
String.metadata: metadata
String.metadata: metadata,
String.healthMetrics: healthMetricsValue()
]
}

Expand All @@ -107,6 +108,14 @@ public extension DittoHeartbeatInfo {
}
return cxVal
}

private func healthMetricsValue() -> [String: Any] {
var healthMetricsVal = [String: Any]()
for (metricName, metric) in healthMetrics {
healthMetricsVal[metricName] = metric.value
}
return healthMetricsVal
}
}

//MARK: PeerConnection
Expand Down Expand Up @@ -175,4 +184,11 @@ private extension HealthMetric {
}
self.init(isHealthy: isHealthy, details: details)
}

var value: [String: Any] {
[
String.isHealthy: isHealthy,
String.details: details
]
}
}
5 changes: 2 additions & 3 deletions Sources/DittoHeartbeat/HeartbeatVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,12 @@ public class HeartbeatVM: ObservableObject {
}

private func updateHealthMetrics() {
guard var hbInfo = hbInfo,
let hbConfig = hbConfig else { return }
guard let hbConfig = hbConfig else { return }
var newHealthMetrics: [String: HealthMetric] = [:]
hbConfig.healthMetricProviders.forEach { provider in
newHealthMetrics[provider.metricName] = provider.getCurrentState()
}
hbInfo.healthMetrics = newHealthMetrics
hbInfo?.healthMetrics = newHealthMetrics
}

private func startTimer() {
Expand Down
4 changes: 2 additions & 2 deletions Sources/DittoPermissionsHealth/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
//

struct DittoPermissionsHealthConstants {
static let networkManagerHealthMetricName = "DittoPermissionsHealth.WiFi"
static let bluetoothManagerHealthMetricName = "DittoPermissionsHealth.Bluetooth"
static let networkManagerHealthMetricName = "DittoPermissionsHealth_WiFi"
static let bluetoothManagerHealthMetricName = "DittoPermissionsHealth_Bluetooth"
}

0 comments on commit 5e8e1f5

Please sign in to comment.