Accept endpoint health from mesh config

This commit is contained in:
2026-05-16 11:17:07 +03:00
parent 53a5a457e3
commit 4516046a20
6 changed files with 225 additions and 57 deletions
@@ -33,6 +33,15 @@ func TestLoadScopedSyntheticConfig(t *testing.T) {
},
},
},
PeerEndpointObservations: map[string]EndpointCandidateHealthObservation{
"node-b-public": {
EndpointID: "node-b-public",
LastLatencyMs: 42,
SuccessCount: 3,
ReliabilityScore: 95,
ObservedAt: expiresAt.Add(-time.Minute),
},
},
PeerDirectory: []PeerDirectoryEntry{
{
NodeID: "node-b",
@@ -81,6 +90,9 @@ func TestLoadScopedSyntheticConfig(t *testing.T) {
if got := cfg.PeerEndpointCandidates["node-b"]; len(got) != 1 || got[0].EndpointID != "node-b-public" {
t.Fatalf("unexpected endpoint candidates: %+v", cfg.PeerEndpointCandidates)
}
if got := cfg.PeerEndpointObservations["node-b-public"]; got.EndpointID != "node-b-public" || got.ReliabilityScore != 95 {
t.Fatalf("unexpected endpoint observations: %+v", cfg.PeerEndpointObservations)
}
if len(cfg.PeerDirectory) != 1 || cfg.PeerDirectory[0].NodeID != "node-b" || !cfg.PeerDirectory[0].RecoverySeed {
t.Fatalf("unexpected peer directory: %+v", cfg.PeerDirectory)
}
@@ -162,6 +174,26 @@ func TestLoadScopedSyntheticConfigRejectsInvalidPeerEndpointCandidate(t *testing
}
}
func TestLoadScopedSyntheticConfigRejectsInvalidPeerEndpointObservation(t *testing.T) {
path := writeScopedConfig(t, ScopedSyntheticConfig{
SchemaVersion: "c17f.synthetic.v1",
ClusterID: "cluster-1",
LocalNodeID: "node-a",
PeerEndpoints: map[string]string{},
PeerEndpointObservations: map[string]EndpointCandidateHealthObservation{
"endpoint-a": {
EndpointID: "endpoint-b",
ReliabilityScore: 101,
},
},
Routes: []SyntheticRoute{liveSyntheticRoute("route-a-b", []string{"node-a", "node-b"})},
})
_, err := LoadScopedSyntheticConfig(path, PeerIdentity{ClusterID: "cluster-1", NodeID: "node-a"})
if err == nil {
t.Fatal("expected invalid peer endpoint observation error")
}
}
func TestLoadScopedSyntheticConfigRejectsInvalidPeerDirectory(t *testing.T) {
path := writeScopedConfig(t, ScopedSyntheticConfig{
SchemaVersion: "c17f.synthetic.v1",