Skip to content

Commit

Permalink
Not found error handling + metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
pschork committed Apr 26, 2024
1 parent fdc52a8 commit aba080f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 8 additions & 0 deletions disperser/dataapi/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ func (g *Metrics) IncrementFailedRequestNum(method string) {
}).Inc()
}

// IncrementNotFoundRequestNum increments the number of not found requests
func (g *Metrics) IncrementNotFoundRequestNum(method string) {
g.NumRequests.With(prometheus.Labels{
"status": "not found",
"method": method,
}).Inc()
}

// Start starts the metrics server
func (g *Metrics) Start(ctx context.Context) {
g.logger.Info("Starting metrics server at ", "port", g.httpPort)
Expand Down
5 changes: 3 additions & 2 deletions disperser/dataapi/operator_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dataapi

import (
"context"
"errors"
"net"
"sort"
"time"
Expand Down Expand Up @@ -106,8 +107,8 @@ func checkIsOnlineAndProcessOperator(operatorStatus OperatorOnlineStatus, operat
func (s *server) probeOperatorPorts(ctx context.Context, operatorId string) (*OperatorPortCheckResponse, error) {
operatorInfo, err := s.subgraphClient.QueryOperatorInfoByOperatorId(context.Background(), operatorId)
if err != nil {
s.logger.Error("Failed to fetch operator", "error", err)
return &OperatorPortCheckResponse{}, err
s.logger.Warn("Failed to fetch operator info", "error", err)
return &OperatorPortCheckResponse{}, errors.New("not found")
}

retrieverSocket := core.OperatorSocket(operatorInfo.Socket).GetRetrievalSocket()
Expand Down
9 changes: 7 additions & 2 deletions disperser/dataapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,15 @@ func (s *server) OperatorPortCheck(c *gin.Context) {
}))
defer timer.ObserveDuration()

operatorId := c.DefaultQuery("operatorId", "")
operatorId := c.DefaultQuery("operator_id", "")
s.logger.Info("Checking operator ports", "operatorId", operatorId)
portCheckResponse, err := s.probeOperatorPorts(c.Request.Context(), operatorId)
if err != nil {
s.metrics.IncrementFailedRequestNum("OperatorPortCheck")
if err == errNotFound {
s.metrics.IncrementNotFoundRequestNum("OperatorPortCheck")
} else {
s.metrics.IncrementFailedRequestNum("OperatorPortCheck")
}
errorResponse(c, err)
return
}
Expand Down

0 comments on commit aba080f

Please sign in to comment.