Expose peer cache endpoint score reasons

This commit is contained in:
2026-05-16 11:27:18 +03:00
parent 831701003c
commit 6817d150f8
3 changed files with 8 additions and 0 deletions
@@ -55,6 +55,7 @@ type PeerCacheEntry struct {
BestNATType string `json:"best_nat_type,omitempty"` BestNATType string `json:"best_nat_type,omitempty"`
BestPolicyTags []string `json:"best_policy_tags,omitempty"` BestPolicyTags []string `json:"best_policy_tags,omitempty"`
BestCandidateScore int `json:"best_candidate_score,omitempty"` BestCandidateScore int `json:"best_candidate_score,omitempty"`
BestScoreReasons []string `json:"best_score_reasons,omitempty"`
EndpointCandidates []PeerEndpointCandidate `json:"endpoint_candidates,omitempty"` EndpointCandidates []PeerEndpointCandidate `json:"endpoint_candidates,omitempty"`
RendezvousLeaseID string `json:"rendezvous_lease_id,omitempty"` RendezvousLeaseID string `json:"rendezvous_lease_id,omitempty"`
RelayNodeID string `json:"relay_node_id,omitempty"` RelayNodeID string `json:"relay_node_id,omitempty"`
@@ -133,6 +134,7 @@ func NewPeerCache(cfg PeerCacheConfig) *PeerCache {
entry.BestNATType = scored[0].Candidate.NATType entry.BestNATType = scored[0].Candidate.NATType
entry.BestPolicyTags = append([]string{}, scored[0].Candidate.PolicyTags...) entry.BestPolicyTags = append([]string{}, scored[0].Candidate.PolicyTags...)
entry.BestCandidateScore = scored[0].Score entry.BestCandidateScore = scored[0].Score
entry.BestScoreReasons = append([]string{}, scored[0].Reasons...)
entry.bestScore = scored[0].Score entry.bestScore = scored[0].Score
if strings.TrimSpace(scored[0].Candidate.Address) != "" { if strings.TrimSpace(scored[0].Candidate.Address) != "" {
entry.Endpoint = strings.TrimSpace(scored[0].Candidate.Address) entry.Endpoint = strings.TrimSpace(scored[0].Candidate.Address)
@@ -151,6 +151,9 @@ func TestPeerCacheAppliesEndpointHealthObservations(t *testing.T) {
if entry.BestCandidateID != "node-b-wss" || entry.Endpoint != "https://node-b.example.test:443" { if entry.BestCandidateID != "node-b-wss" || entry.Endpoint != "https://node-b.example.test:443" {
t.Fatalf("peer cache did not apply endpoint observations: %+v", entry) t.Fatalf("peer cache did not apply endpoint observations: %+v", entry)
} }
if !containsString(entry.BestScoreReasons, "transport:wss") {
t.Fatalf("peer cache did not expose score reasons: %+v", entry.BestScoreReasons)
}
} }
func TestPeerCacheUsesPreferredCorporateEndpointAddress(t *testing.T) { func TestPeerCacheUsesPreferredCorporateEndpointAddress(t *testing.T) {
@@ -350,6 +350,9 @@ report level for simpler multi-node ingestion and diagnostics.
Peer cache construction now applies endpoint health observations when ranking Peer cache construction now applies endpoint health observations when ranking
peer endpoint candidates, so recovery and warm-peer decisions see the same peer endpoint candidates, so recovery and warm-peer decisions see the same
degraded-path feedback as VPN fabric-session dialing. degraded-path feedback as VPN fabric-session dialing.
Peer cache snapshots expose best-candidate score reasons, giving diagnostics a
direct explanation for why a QUIC, WebSocket, relay, or fallback endpoint was
chosen.
Deliverables: Deliverables: