Skip to content

Commit

Permalink
add error logging on api
Browse files Browse the repository at this point in the history
  • Loading branch information
iskakaushik committed Dec 10, 2023
1 parent 9960cb6 commit eebf5f6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions flow/cmd/peer_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/PeerDB-io/peer-flow/connectors/utils"
"github.com/PeerDB-io/peer-flow/generated/protos"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/sirupsen/logrus"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -204,18 +205,21 @@ func (h *FlowRequestHandler) GetSlotInfo(
) (*protos.PeerSlotResponse, error) {
pgConfig, err := h.getPGPeerConfig(ctx, req.PeerName)
if err != nil {
logrus.Errorf("Error getting pg config for peer %s: %v", req.PeerName, err)
return &protos.PeerSlotResponse{SlotData: nil}, err
}

pgConnector, err := connpostgres.NewPostgresConnector(ctx, pgConfig)
if err != nil {
logrus.Errorf("Error getting pg connector for peer %s: %v", req.PeerName, err)
return &protos.PeerSlotResponse{SlotData: nil,
ErrorMessage: err.Error(),
}, err
}

slotInfo, err := pgConnector.GetSlotInfo("")
if err != nil {
logrus.Errorf("Error getting slot info for peer %s: %v", req.PeerName, err)
return &protos.PeerSlotResponse{
SlotData: nil,
ErrorMessage: err.Error(),
Expand All @@ -232,6 +236,7 @@ func (h *FlowRequestHandler) GetStatInfo(
) (*protos.PeerStatResponse, error) {
peerPool, peerUser, err := h.getPoolForPGPeer(ctx, req.PeerName)
if err != nil {
logrus.Errorf("Error getting pg pool for peer %s: %v", req.PeerName, err)
return &protos.PeerStatResponse{
StatData: nil,
ErrorMessage: err.Error(),
Expand All @@ -243,6 +248,7 @@ func (h *FlowRequestHandler) GetStatInfo(
" FROM pg_stat_activity WHERE "+
"usename=$1 AND state != 'idle';", peerUser)
if err != nil {
logrus.Errorf("Error getting stat info for peer %s: %v", req.PeerName, err)
return &protos.PeerStatResponse{
StatData: nil,
ErrorMessage: err.Error(),
Expand All @@ -260,6 +266,7 @@ func (h *FlowRequestHandler) GetStatInfo(

err := rows.Scan(&pid, &waitEvent, &waitEventType, &queryStart, &query, &duration)
if err != nil {
logrus.Errorf("Error scanning stat info for peer %s: %v", req.PeerName, err)
return &protos.PeerStatResponse{
StatData: nil,
ErrorMessage: err.Error(),
Expand Down

0 comments on commit eebf5f6

Please sign in to comment.