From d0ebd4782f1cc4a30d3fbc32b5ed8ec1f548867c Mon Sep 17 00:00:00 2001 From: kompotkot Date: Tue, 11 Jan 2022 21:21:50 +0000 Subject: [PATCH] Updated logs for middleware and status of nodes at node balancer --- nodes/node_balancer/cmd/balancer.go | 3 +-- nodes/node_balancer/cmd/clients.go | 2 +- nodes/node_balancer/cmd/middleware.go | 8 +++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/nodes/node_balancer/cmd/balancer.go b/nodes/node_balancer/cmd/balancer.go index e23b5543..e7fcb210 100644 --- a/nodes/node_balancer/cmd/balancer.go +++ b/nodes/node_balancer/cmd/balancer.go @@ -113,7 +113,6 @@ func (bpool *BlockchainPool) GetNextNode(blockchain string) *Node { continue } - fmt.Printf("Used node: %s with hi block: %d\n", np.Nodes[idx].GethURL, np.Nodes[idx].CurrentBlock) return np.Nodes[idx] } } @@ -180,7 +179,7 @@ func (bpool *BlockchainPool) HealthCheck() { n.SetCurrentBlock(statusResponse.CurrentBlock) } - log.Printf("Node %s is alive: %t with current block: %d\n", n.StatusURL, true, statusResponse.CurrentBlock) + log.Printf("Node %s is alive: %t with current block: %d blockchain called: %d times\n", n.StatusURL, true, statusResponse.CurrentBlock, b.Current) } } } diff --git a/nodes/node_balancer/cmd/clients.go b/nodes/node_balancer/cmd/clients.go index 4942070a..43b7650b 100644 --- a/nodes/node_balancer/cmd/clients.go +++ b/nodes/node_balancer/cmd/clients.go @@ -93,5 +93,5 @@ func (cpool *ClientPool) CleanInactiveClientNodes() { } } - log.Printf("Active clients: %d", len(cpool.Clients)) + log.Printf("Active clients: %d\n", len(cpool.Clients)) } diff --git a/nodes/node_balancer/cmd/middleware.go b/nodes/node_balancer/cmd/middleware.go index 60976441..1bc69fda 100644 --- a/nodes/node_balancer/cmd/middleware.go +++ b/nodes/node_balancer/cmd/middleware.go @@ -5,6 +5,7 @@ package cmd import ( "log" + "net" "net/http" humbug "github.com/bugout-dev/humbug/go/pkg" @@ -31,6 +32,11 @@ func panicMiddleware(next http.Handler) http.Handler { func logMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { next.ServeHTTP(w, r) - log.Printf("%s %s %s\n", r.Method, r.URL.Path, r.RemoteAddr) + ip, _, err := net.SplitHostPort(r.RemoteAddr) + if err != nil { + log.Printf("Unable to parse client IP: %s\n", r.RemoteAddr) + } else { + log.Printf("%s %s %s\n", ip, r.Method, r.URL.Path) + } }) }