diff --git a/src/metrics/index.ts b/src/metrics/index.ts index 08d15242..658b46a6 100644 --- a/src/metrics/index.ts +++ b/src/metrics/index.ts @@ -357,4 +357,9 @@ export const metrics = new Metrics(() => ({ help: 'The number of addresses in PoR request input parameters', labelNames: ['feed_id'] as const, }), + wsConnectionFailoverCount: new client.Gauge({ + name: 'ws_connection_failover_count', + help: 'The number of consecutive unresponsive connection detections (no data for WS_SUBSCRIPTION_UNRESPONSIVE_TTL), used to trigger URL failover', + labelNames: ['transport_name'] as const, + }), })) diff --git a/src/transports/websocket.ts b/src/transports/websocket.ts index eafb3077..de74ac64 100644 --- a/src/transports/websocket.ts +++ b/src/transports/websocket.ts @@ -414,9 +414,13 @@ export class WebSocketTransport< // to determine minimum TTL of an open connection given no explicit connection errors. if (connectionUnresponsive) { this.streamHandlerInvocationsWithNoConnection += 1 - logger.trace( - `The connection is unresponsive, incremented streamHandlerIterationsWithNoConnection = ${this.streamHandlerInvocationsWithNoConnection}`, + logger.info( + `The connection is unresponsive (last message ${timeSinceLastMessage}ms ago), incremented failover counter to ${this.streamHandlerInvocationsWithNoConnection}`, ) + metrics + .get('wsConnectionFailoverCount') + .labels({ transport_name: this.name }) + .set(this.streamHandlerInvocationsWithNoConnection) } // We want to check if the URL we calculate is different from the one currently connected. @@ -431,10 +435,9 @@ export class WebSocketTransport< // Check if we should close the current connection if (!connectionClosed && (urlChanged || connectionUnresponsive)) { if (urlChanged) { + logger.info('Websocket URL has changed, closing connection to reconnect...') censorLogs(() => - logger.debug( - `Websocket url has changed from ${this.currentUrl} to ${urlFromConfig}, closing connection...`, - ), + logger.debug(`Websocket URL changed from ${this.currentUrl} to ${urlFromConfig}`), ) } else { censorLogs(() =>