From 87d034f48a223e726aaa1597c4d2ca49bab4a49a Mon Sep 17 00:00:00 2001 From: kompotkot Date: Mon, 16 Jan 2023 11:08:18 +0000 Subject: [PATCH] Updated README.md and debug logs --- nodes/node_balancer/README.md | 15 +++++++++++++++ .../node_balancer/cmd/nodebalancer/middleware.go | 10 +++++----- nodes/node_balancer/cmd/nodebalancer/routes.go | 4 ++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/nodes/node_balancer/README.md b/nodes/node_balancer/README.md index a807ad5d..895865b4 100644 --- a/nodes/node_balancer/README.md +++ b/nodes/node_balancer/README.md @@ -41,6 +41,8 @@ So if with request will be specified tag `local` will be returned node with corr ## Work with nodebalancer +**IMPORTANT** Do not use flag `-debug` in production. + ### add-access Add new access for user: @@ -127,3 +129,16 @@ For Web3 providers `access_id` and `data_source` could be specified in headers --header 'x-node-balancer-data-source: ' --header 'x-node-balancer-access-id: ' ``` + +Same request to fetch specific nodes using tags + +```bash +curl --request POST 'http://127.0.0.1:8544/nb/ethereum/jsonrpc?access_id=&data_source=&tag=&tag=' \ + --header 'Content-Type: application/json' \ + --data-raw '{ + "jsonrpc":"2.0", + "method":"eth_getBlockByNumber", + "params":["latest", false], + "id":1 + }' +``` diff --git a/nodes/node_balancer/cmd/nodebalancer/middleware.go b/nodes/node_balancer/cmd/nodebalancer/middleware.go index 42f4f26f..b5799b60 100644 --- a/nodes/node_balancer/cmd/nodebalancer/middleware.go +++ b/nodes/node_balancer/cmd/nodebalancer/middleware.go @@ -105,7 +105,7 @@ func initCacheCleaning() { case <-t.C: removedAccessIds, totalAccessIds := accessIdCache.Cleanup() if stateCLI.enableDebugFlag { - log.Printf("Removed %d elements from access id cache", removedAccessIds) + log.Printf("[DEBUG] Removed %d elements from access id cache", removedAccessIds) } log.Printf("Elements in access id cache: %d", totalAccessIds) } @@ -241,7 +241,7 @@ func logMiddleware(next http.Handler) http.Handler { if stateCLI.enableDebugFlag { if r.URL.RawQuery != "" { - logStr += fmt.Sprintf(" %s", r.URL.RawQuery) + logStr += fmt.Sprintf(" [DEBUG] %s", r.URL.RawQuery) } accessID := extractAccessID(r) if accessID != "" { @@ -269,20 +269,20 @@ func accessMiddleware(next http.Handler) http.Handler { // If access id does not belong to internal crawlers, then check cache or find it in Bugout resources if accessID == NB_CONTROLLER_ACCESS_ID { if stateCLI.enableDebugFlag { - log.Printf("Access id belongs to internal crawlers") + log.Printf("[DEBUG] Access id belongs to internal crawlers") } currentClientAccess = internalCrawlersAccess currentClientAccess.dataSource = dataSource } else if accessIdCache.FindAccessIdInCache(accessID) != "" { if stateCLI.enableDebugFlag { - log.Printf("Access id found in cache") + log.Printf("[DEBUG] Access id found in cache") } currentClientAccess = accessIdCache.accessIds[accessID] currentClientAccess.dataSource = dataSource accessIdCache.UpdateAccessIdAtCache(accessID, dataSource) } else { if stateCLI.enableDebugFlag { - log.Printf("New access id, looking at Brood resources") + log.Printf("[DEBUG] New access id, looking at Brood resources") } resources, err := bugoutClient.Brood.GetResources( NB_CONTROLLER_TOKEN, diff --git a/nodes/node_balancer/cmd/nodebalancer/routes.go b/nodes/node_balancer/cmd/nodebalancer/routes.go index 57a5e6a8..19f1c230 100644 --- a/nodes/node_balancer/cmd/nodebalancer/routes.go +++ b/nodes/node_balancer/cmd/nodebalancer/routes.go @@ -114,6 +114,10 @@ func lbJSONRPCHandler(w http.ResponseWriter, r *http.Request, blockchain string, cpool.AddClientNode(currentClientAccess.AccessID, node) } + if stateCLI.enableDebugFlag { + log.Printf("[DEBUG] Used node with endpoint: %s, call counter equals: %d", node.Endpoint, node.CallCounter) + } + switch { case currentClientAccess.dataSource == "blockchain": if currentClientAccess.BlockchainAccess == false {