Skip to content

Commit 8777d6f

Browse files
authored
Add WebSocket failover counter metric and URL change logging (#661)
* Add WebSocket failover counter metric, abnormal closure tracking, and URL change logging * Remove increment on 1006 * Remove bad description * run prettier
1 parent 1cfa5dc commit 8777d6f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/metrics/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,4 +357,9 @@ export const metrics = new Metrics(() => ({
357357
help: 'The number of addresses in PoR request input parameters',
358358
labelNames: ['feed_id'] as const,
359359
}),
360+
wsConnectionFailoverCount: new client.Gauge({
361+
name: 'ws_connection_failover_count',
362+
help: 'The number of consecutive unresponsive connection detections (no data for WS_SUBSCRIPTION_UNRESPONSIVE_TTL), used to trigger URL failover',
363+
labelNames: ['transport_name'] as const,
364+
}),
360365
}))

src/transports/websocket.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,13 @@ export class WebSocketTransport<
414414
// to determine minimum TTL of an open connection given no explicit connection errors.
415415
if (connectionUnresponsive) {
416416
this.streamHandlerInvocationsWithNoConnection += 1
417-
logger.trace(
418-
`The connection is unresponsive, incremented streamHandlerIterationsWithNoConnection = ${this.streamHandlerInvocationsWithNoConnection}`,
417+
logger.info(
418+
`The connection is unresponsive (last message ${timeSinceLastMessage}ms ago), incremented failover counter to ${this.streamHandlerInvocationsWithNoConnection}`,
419419
)
420+
metrics
421+
.get('wsConnectionFailoverCount')
422+
.labels({ transport_name: this.name })
423+
.set(this.streamHandlerInvocationsWithNoConnection)
420424
}
421425

422426
// We want to check if the URL we calculate is different from the one currently connected.
@@ -431,10 +435,9 @@ export class WebSocketTransport<
431435
// Check if we should close the current connection
432436
if (!connectionClosed && (urlChanged || connectionUnresponsive)) {
433437
if (urlChanged) {
438+
logger.info('Websocket URL has changed, closing connection to reconnect...')
434439
censorLogs(() =>
435-
logger.debug(
436-
`Websocket url has changed from ${this.currentUrl} to ${urlFromConfig}, closing connection...`,
437-
),
440+
logger.debug(`Websocket URL changed from ${this.currentUrl} to ${urlFromConfig}`),
438441
)
439442
} else {
440443
censorLogs(() =>

0 commit comments

Comments
 (0)