Skip to content

Commit

Permalink
Improved reachability check 404 handling (#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
pschork authored May 21, 2024
1 parent a19f62c commit 374500a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions disperser/dataapi/queried_operators_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
12 changes: 9 additions & 3 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"net/http"
"net/url"
"os"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit 374500a

Please sign in to comment.