From 374500ae4c8edb3d5231fb82c9b1147957082fea Mon Sep 17 00:00:00 2001 From: pschork <354473+pschork@users.noreply.github.com> Date: Tue, 21 May 2024 12:58:35 -0700 Subject: [PATCH] Improved reachability check 404 handling (#571) --- disperser/dataapi/queried_operators_handlers.go | 6 +++--- node/node.go | 12 +++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/disperser/dataapi/queried_operators_handlers.go b/disperser/dataapi/queried_operators_handlers.go index 0714c1016a..b2ff89d78b 100644 --- a/disperser/dataapi/queried_operators_handlers.go +++ b/disperser/dataapi/queried_operators_handlers.go @@ -169,8 +169,8 @@ func ValidOperatorIP(address string, logger logging.Logger) bool { func (s *server) probeOperatorPorts(ctx context.Context, operatorId string) (*OperatorPortCheckResponse, error) { operatorInfo, err := s.subgraphClient.QueryOperatorInfoByOperatorId(context.Background(), operatorId) if err != nil { - s.logger.Warn("failed to fetch operator info", "error", err) - return &OperatorPortCheckResponse{}, errors.New("not found") + s.logger.Warn("failed to fetch operator info", "operatorId", operatorId, "error", err) + return &OperatorPortCheckResponse{}, errors.New("operator info not found") } operatorSocket := core.OperatorSocket(operatorInfo.Socket) @@ -190,7 +190,7 @@ func (s *server) probeOperatorPorts(ctx context.Context, operatorId string) (*Op } // Log the online status - s.logger.Info("operator port check response", portCheckResponse) + s.logger.Info("operator port check response", "response", portCheckResponse) // Send the metadata to the results channel return portCheckResponse, nil diff --git a/node/node.go b/node/node.go index a9ecd88726..76f2b60e4d 100644 --- a/node/node.go +++ b/node/node.go @@ -12,6 +12,7 @@ import ( "net/http" "net/url" "os" + "strings" "sync" "time" @@ -477,7 +478,7 @@ func (n *Node) checkNodeReachability() { return } - checkUrl, err := url.Parse(fmt.Sprintf("%s/api/v1/operators-info/port-check?operator_id=%s", n.Config.DataApiUrl, n.Config.ID.Hex())) + checkUrl, err := url.Parse(fmt.Sprintf("%s/api/v1/operators-info/port-check?operator_id=%s", strings.TrimSuffix(n.Config.DataApiUrl, "/"), n.Config.ID.Hex())) if err != nil { n.Logger.Error("Reachability check failed - invalid check url", err, "checkUrl", checkUrl.String()) return @@ -497,7 +498,12 @@ func (n *Node) checkNodeReachability() { n.Logger.Error("Reachability check request failed", err) continue } else if resp.StatusCode == 404 { - n.Logger.Error("Reachability check failed - operator id not found", "status", resp.StatusCode, "operator_id", n.Config.ID.Hex()) + body, _ := io.ReadAll(resp.Body) + if string(body) == "404 page not found" { + n.Logger.Error("Invalid reachability check url", "checkUrl", checkUrl.String()) + } else { + n.Logger.Warn("Reachability check operator id not found", "status", resp.StatusCode, "operator_id", n.Config.ID.Hex()) + } continue } else if resp.StatusCode != 200 { n.Logger.Error("Reachability check request failed", "status", resp.StatusCode) @@ -506,7 +512,7 @@ func (n *Node) checkNodeReachability() { data, err := io.ReadAll(resp.Body) if err != nil { - n.Logger.Error("Failed to read reachability check response", err, "data", resp.Body) + n.Logger.Error("Failed to read reachability check response", err) continue }