From fb2560032d4a3a713f5c5d3bf112d5058ceb4376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kotol?= Date: Wed, 11 Oct 2023 13:36:00 +0200 Subject: [PATCH] ALL-2673 Updated loadbalancer logging (#973) --- CHANGELOG.md | 4 +++ package.json | 2 +- src/service/rpc/generic/LoadBalancer.ts | 41 ++++++++++++------------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa8ad19366..472e3cf43b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [4.0.19] - 2023.10.11 +### Added +- Updated loadbalancer logging with detailed logs + ## [4.0.18] - 2023.10.11 ### Fixed - Update debug storage range parameters. The `debugStorageRangeAt` function in the EvmRpc now takes a number instead of a string for the `maxResults` parameter. diff --git a/package.json b/package.json index 8ec4318ce1..f6062fd6da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tatumio/tatum", - "version": "4.0.18", + "version": "4.0.19", "description": "Tatum JS SDK", "author": "Tatum", "repository": "https://github.com/tatumio/tatum-js", diff --git a/src/service/rpc/generic/LoadBalancer.ts b/src/service/rpc/generic/LoadBalancer.ts index c8e5492533..e97ad9d5a8 100644 --- a/src/service/rpc/generic/LoadBalancer.ts +++ b/src/service/rpc/generic/LoadBalancer.ts @@ -331,6 +331,11 @@ export class LoadBalancer implements AbstractRpcInterface { })), ] + Utils.log({ + id: this.id, + message: `Added ${filteredNodes.length} nodes (${filteredNodes.map(s => s.url).join(', ')}) for ${this.network} blockchain during the initialization for node ${NODE_TYPE_LABEL[nodeType]}.`, + }) + const randomIndex = Math.floor(Math.random() * this.rpcUrls[nodeType].length) Utils.log({ @@ -349,27 +354,8 @@ export class LoadBalancer implements AbstractRpcInterface { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const [normal, archive] = await Promise.all(rpcList.map((url) => fetch(url))) - if (normal.ok) { - const nodes: RpcNode[] = await normal.json() - this.initRemoteHosts({ nodeType: RpcNodeType.NORMAL, nodes: nodes }) - this.initRemoteHosts({ nodeType: RpcNodeType.ARCHIVE, nodes: nodes }) - } else { - Utils.log({ - id: this.id, - message: `Failed to fetch RPC configuration for ${network} blockchain for normal nodes`, - }) - } - - if (archive.ok) { - const nodes: RpcNode[] = await archive.json() - this.initRemoteHosts({ nodeType: RpcNodeType.NORMAL, nodes: nodes }) - this.initRemoteHosts({ nodeType: RpcNodeType.ARCHIVE, nodes: nodes }) - } else { - Utils.log({ - id: this.id, - message: `Failed to fetch RPC configuration for ${network} blockchain for archive nodes`, - }) - } + await this.initRemoteHostsFromResponse(normal, RpcNodeType.NORMAL) + await this.initRemoteHostsFromResponse(archive, RpcNodeType.ARCHIVE) } catch (e) { console.error( new Date().toISOString(), @@ -378,6 +364,19 @@ export class LoadBalancer implements AbstractRpcInterface { } } + async initRemoteHostsFromResponse(response: Response, nodeType: RpcNodeType) { + if (response.ok) { + const nodes: RpcNode[] = await response.json() + this.initRemoteHosts({ nodeType: RpcNodeType.NORMAL, nodes: nodes }) + this.initRemoteHosts({ nodeType: RpcNodeType.ARCHIVE, nodes: nodes }) + } else { + Utils.log({ + id: this.id, + message: `Failed to fetch RPC configuration for ${this.network} blockchain for ${RpcNodeType[nodeType]} nodes`, + }) + } + } + async handleFailedRpcCall(rpcCall: JsonRpcCall | JsonRpcCall[] | PostI, e: unknown, nodeType: RpcNodeType) { const { rpc: rpcConfig } = Container.of(this.id).get(CONFIG) const { url } = this.getActiveUrl(nodeType)