47 lines
980 B
Go
47 lines
980 B
Go
package app
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func transportShouldPersistHealthSnapshot(prev, next TransportClient, now time.Time) bool {
|
|
if transportHealthChanged(prev, next) {
|
|
return true
|
|
}
|
|
prevTS, ok := parseTransportHealthLastCheck(prev)
|
|
if !ok {
|
|
return true
|
|
}
|
|
return now.Sub(prevTS) >= transportHealthPersistMinAge
|
|
}
|
|
|
|
func transportHealthChanged(prev, next TransportClient) bool {
|
|
if normalizeTransportStatus(prev.Status) != normalizeTransportStatus(next.Status) {
|
|
return true
|
|
}
|
|
if strings.TrimSpace(prev.Health.LastError) != strings.TrimSpace(next.Health.LastError) {
|
|
return true
|
|
}
|
|
if transportHealthLatencyBucket(prev.Health.LatencyMS) != transportHealthLatencyBucket(next.Health.LatencyMS) {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func transportHealthLatencyBucket(ms int) string {
|
|
if ms <= 0 {
|
|
return "none"
|
|
}
|
|
switch {
|
|
case ms < 100:
|
|
return "lt100"
|
|
case ms < 300:
|
|
return "100-299"
|
|
case ms < 800:
|
|
return "300-799"
|
|
default:
|
|
return "ge800"
|
|
}
|
|
}
|