Score capacity pressure softly
This commit is contained in:
@@ -237,8 +237,13 @@ func scoreEndpointCandidateObservation(observation EndpointCandidateHealthObserv
|
||||
reasons = append(reasons, "history:failure")
|
||||
}
|
||||
if strings.TrimSpace(observation.LastFailureReason) != "" {
|
||||
score -= 8
|
||||
reasons = append(reasons, "failure:recent")
|
||||
if strings.TrimSpace(observation.LastFailureReason) == "capacity_limited" {
|
||||
score -= 4
|
||||
reasons = append(reasons, "capacity:limited")
|
||||
} else {
|
||||
score -= 8
|
||||
reasons = append(reasons, "failure:recent")
|
||||
}
|
||||
}
|
||||
return score, reasons
|
||||
}
|
||||
|
||||
@@ -353,6 +353,40 @@ func TestRankPeerEndpointCandidatesDoesNotRewardZeroLatencyFailure(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRankPeerEndpointCandidatesTreatsCapacityAsSoftPressure(t *testing.T) {
|
||||
now := time.Date(2026, 5, 16, 12, 0, 0, 0, time.UTC)
|
||||
ranked := RankPeerEndpointCandidates([]PeerEndpointCandidate{
|
||||
{
|
||||
EndpointID: "node-b-quic",
|
||||
NodeID: "node-b",
|
||||
Transport: "direct_quic",
|
||||
Address: "quic://node-b.example.test:19443",
|
||||
Reachability: "public",
|
||||
ConnectivityMode: "direct",
|
||||
Priority: 10,
|
||||
LastVerifiedAt: &now,
|
||||
},
|
||||
}, EndpointCandidateScoreOptions{
|
||||
Now: now,
|
||||
MaxVerificationAge: time.Minute,
|
||||
Observations: map[string]EndpointCandidateHealthObservation{
|
||||
"node-b-quic": {
|
||||
EndpointID: "node-b-quic",
|
||||
LastFailureReason: "capacity_limited",
|
||||
ReliabilityScore: 95,
|
||||
ObservedAt: now,
|
||||
},
|
||||
},
|
||||
MaxObservationAge: time.Minute,
|
||||
})
|
||||
if len(ranked) != 1 || !containsReason(ranked[0].Reasons, "capacity:limited") {
|
||||
t.Fatalf("capacity pressure reason missing: %+v", ranked)
|
||||
}
|
||||
if containsReason(ranked[0].Reasons, "failure:recent") {
|
||||
t.Fatalf("capacity pressure treated as recent failure: %+v", ranked[0].Reasons)
|
||||
}
|
||||
}
|
||||
|
||||
func containsReason(reasons []string, reason string) bool {
|
||||
for _, item := range reasons {
|
||||
if item == reason {
|
||||
|
||||
Reference in New Issue
Block a user