Skip to content

Commit cb32d86

Browse files
AnnaR-progclaude
andcommitted
fix(rpcsmartrouter): health says a provider serves no subscriptions when every ws url is refused (MAG-3950)
health added "serves no subscriptions" to a provider's admitted rows only when it had no ws(s) url. A provider whose ws urls the router refuses, a dead socket for one, serves no subscriptions either, and the metric publishes both cases as the websocket service. Its admitted rows now say "no ws(s) node url admitted: serves no subscriptions", read as websocketLeft reads the admission. The case with no ws(s) url keeps its reason (review of #602). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent f38c240 commit cb32d86

2 files changed

Lines changed: 59 additions & 5 deletions

File tree

‎protocol/rpcsmartrouter/health_cmd.go‎

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,16 +441,25 @@ func probeProvider(ctx context.Context, provider healthProvider, opts healthOpti
441441
if excluded == nil {
442442
excluded = admissionErr
443443
}
444-
missingWebsocket := chainlib.MissingWebsocket(endpoint.NodeUrls, chainParser)
444+
// A provider serves no subscriptions with no ws(s) url on a chain that subscribes, and
445+
// with ws(s) urls the router refuses every one of: the metric publishes both as the
446+
// websocket service (refusalsOf, websocketLeft), so each admitted row says so too.
447+
noSubscriptions := ""
448+
switch {
449+
case chainlib.MissingWebsocket(endpoint.NodeUrls, chainParser):
450+
noSubscriptions = noWebsocketReason
451+
case everyWebsocketRefused(provider.nodeUrls, validations):
452+
noSubscriptions = noWebsocketAdmittedReason
453+
}
445454

446455
rows := make([]healthEndpointResult, 0, len(provider.nodeUrls))
447456
for i, url := range provider.nodeUrls {
448457
row := baseRow(provider, url)
449458
row.SpecValid = true
450459
applyValidation(&row, validations[i])
451460
row.Router = routerVerdict(validations[i], excluded)
452-
if missingWebsocket {
453-
row.Router = row.Router.withoutSubscriptions()
461+
if noSubscriptions != "" {
462+
row.Router = row.Router.withoutSubscriptions(noSubscriptions)
454463
}
455464
rows = append(rows, row)
456465
}
@@ -461,14 +470,34 @@ func probeProvider(ctx context.Context, provider healthProvider, opts healthOpti
461470
// a chain that subscribes: the router serves it without subscriptions (MAG-3950).
462471
const noWebsocketReason = "no ws(s) node url: serves no subscriptions"
463472

464-
func (v healthRouterVerdict) withoutSubscriptions() healthRouterVerdict {
473+
// noWebsocketAdmittedReason is what an admitted row adds when the router refuses every
474+
// ws(s) url of its provider, a dead socket for one: it serves no subscriptions either.
475+
const noWebsocketAdmittedReason = "no ws(s) node url admitted: serves no subscriptions"
476+
477+
// everyWebsocketRefused reports whether a provider has a ws(s) url and the router
478+
// refuses each one it has, as websocketLeft reads the admission.
479+
func everyWebsocketRefused(urls []commonlib.NodeUrl, validations []chainlib.NodeURLValidation) bool {
480+
sockets := 0
481+
for i, url := range urls {
482+
if !chainlib.IsWebSocketURL(url.Url) {
483+
continue
484+
}
485+
sockets++
486+
if i >= len(validations) || !validations[i].Refused {
487+
return false
488+
}
489+
}
490+
return sockets > 0
491+
}
492+
493+
func (v healthRouterVerdict) withoutSubscriptions(reason string) healthRouterVerdict {
465494
if v.Verdict != routerAdmitted {
466495
return v
467496
}
468497
if v.Reason != "" {
469498
v.Reason += "; "
470499
}
471-
v.Reason += noWebsocketReason
500+
v.Reason += reason
472501
return v
473502
}
474503

‎protocol/rpcsmartrouter/websocket_part_test.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,31 @@ func TestHealth_NoWebsocketURLIsAdmittedWithoutSubscriptions(t *testing.T) {
9191
require.NotContains(t, rows[0].Router.Reason, noWebsocketReason)
9292
}
9393

94+
// health says a provider serves no subscriptions when the router refuses each of its ws(s)
95+
// urls, as when it has none: its admitted http row names the reason, and the refused ws
96+
// row says why it is refused. The metric publishes both as the websocket service. A socket
97+
// that answers leaves the reason out.
98+
func TestHealth_EveryWebsocketURLRefusedServesNoSubscriptions(t *testing.T) {
99+
up := newFakeUpstreams(t)
100+
wsURL, accepting := refusingSocket(t, up, "/dead-health/"+upArchive)
101+
urls := []commonlib.NodeUrl{{Url: up.httpURL("/dead-health/" + upArchive)}, {Url: wsURL}}
102+
for _, skipWebsocket := range []bool{false, true} {
103+
rows := healthProbe(t, "ETH1", skipWebsocket, 20*time.Second, urls...)
104+
require.Len(t, rows, 2)
105+
require.Equal(t, routerAdmitted, rows[0].Router.Verdict, "skip-websocket-verification=%t", skipWebsocket)
106+
require.Equal(t, noWebsocketAdmittedReason, rows[0].Router.Reason, "skip-websocket-verification=%t", skipWebsocket)
107+
require.NotEqual(t, routerAdmitted, rows[1].Router.Verdict, "the ws url that cannot be dialed is refused")
108+
}
109+
110+
accepting.Store(true)
111+
rows := healthProbe(t, "ETH1", true, 20*time.Second, urls...)
112+
require.Len(t, rows, 2)
113+
for _, row := range rows {
114+
require.Equal(t, routerAdmitted, row.Router.Verdict)
115+
require.Empty(t, row.Router.Reason, "a socket that answers serves the subscriptions")
116+
}
117+
}
118+
94119
// A missing websocket url is not a failed run, since no check ran: the counter leaves it
95120
// out, while the gauge holds it for as long as it lasts.
96121
func TestCountRefusals_LeavesOutAMissingWebsocketURL(t *testing.T) {

0 commit comments

Comments
 (0)