Skip to content

Commit

Permalink
ALL-2673 Updated loadbalancer logging (#973)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hathoriel authored Oct 11, 2023
1 parent 7282e98 commit fb25600
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
41 changes: 20 additions & 21 deletions src/service/rpc/generic/LoadBalancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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(),
Expand All @@ -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)
Expand Down

0 comments on commit fb25600

Please sign in to comment.