HealthNotifier: fix dependent messages handling (#573)

Fixes tailscale/corp#24582

Android port of tailscale/corp#24719. We were not clearing dependency warnings when a new warning was added which was listed as a dependency of a pre-existing warning. For instance, if `dns-read-os-config-failed` is added to the warnings before `network-status` is added, we were ignoring the dependency by not removing `dns-read-os-config-failed` upon adding `network-status`. This PR addresses that.

Signed-off-by: Andrea Gottardo <andrea@gottardo.me>
pull/575/head
Andrea Gottardo 1 year ago committed by GitHub
parent 91a1316452
commit 61c7c3c8c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -62,8 +62,21 @@ class HealthNotifier(
val warningsBeforeAdd = currentWarnings.value
val currentWarnableCodes = warnings.map { it.WarnableCode }.toSet()
val addedWarnings: MutableSet<UnhealthyState> = mutableSetOf()
val removedByNewDependency: MutableSet<UnhealthyState> = mutableSetOf()
val isWarmingUp = warnings.any { it.WarnableCode == "warming-up" }
/// Checks if there is any warning in `warningsBeforeAdd` that needs to be removed because the new warning `w`
/// is listed as a dependency of a warning already in `warningsBeforeAdd`, and removes it.
fun dropDependenciesForAddedWarning(w: UnhealthyState) {
for (warning in warningsBeforeAdd) {
warning.DependsOn?.let {
if (it.contains(w.WarnableCode)) {
removedByNewDependency.add(warning)
}
}
}
}
for (warning in warnings) {
if (ignoredWarnableCodes.contains(warning.WarnableCode)) {
continue
@ -81,6 +94,7 @@ class HealthNotifier(
} else if (!isWarmingUp) {
TSLog.d(TAG, "Adding health warning: ${warning.WarnableCode}")
this.currentWarnings.set(this.currentWarnings.value + warning)
dropDependenciesForAddedWarning(warning)
if (warning.Severity == Health.Severity.high) {
this.sendNotification(warning.Title, warning.Text, warning.WarnableCode)
}
@ -89,7 +103,7 @@ class HealthNotifier(
}
}
val warningsToDrop = warningsBeforeAdd.minus(addedWarnings)
val warningsToDrop = warningsBeforeAdd.minus(addedWarnings).union(removedByNewDependency)
if (warningsToDrop.isNotEmpty()) {
TSLog.d(TAG, "Dropping health warnings with codes $warningsToDrop")
this.removeNotifications(warningsToDrop)

Loading…
Cancel
Save