Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 connection issues (unresponsive/no data, abnormal closures), used to trigger URL failover. Resets to 0 when data flows successfully.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where this is reset to 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't. The underlying variable it is meant to expose streamHandlerInvocationsWithNoConnection also never resets. It just increments forever, and Tiingo uses modulo arithmetic on it, it is used in this PR:
https://github.com/smartcontractkit/external-adapters-js/pull/4543/files (even before my changes).

Open to resetting it if there is a good reason.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it should reset, but the description says "Resets to 0 when data flows successfully."

labelNames: ['transport_name'] as const,
}),
}))
8 changes: 5 additions & 3 deletions src/transports/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,10 @@ 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.
Expand All @@ -431,9 +432,10 @@ 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...`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this no longer close the connection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, but that string got moved to the info level log, so it is always visible with info level logs.

`Websocket URL changed from ${this.currentUrl} to ${urlFromConfig}`,
),
)
} else {
Expand Down
Loading