Skip to content

Commit

Permalink
Add logging to remote client (#13847)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-cordenier authored Jul 15, 2024
1 parent 8a6202c commit f594ee3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion core/capabilities/remote/target/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var _ services.Service = &client{}
func NewClient(remoteCapabilityInfo commoncap.CapabilityInfo, localDonInfo commoncap.DON, dispatcher types.Dispatcher,
requestTimeout time.Duration, lggr logger.Logger) *client {
return &client{
lggr: lggr,
lggr: lggr.Named("TargetClient"),
remoteCapabilityInfo: remoteCapabilityInfo,
localDONInfo: localDonInfo,
dispatcher: dispatcher,
Expand Down Expand Up @@ -130,6 +130,8 @@ func (c *client) Execute(ctx context.Context, capReq commoncap.CapabilityRequest
return nil, fmt.Errorf("failed to get message ID for request: %w", err)
}

c.lggr.Debugw("executing remote target", "messageID", messageID)

if _, ok := c.messageIDToCallerRequest[messageID]; ok {
return nil, fmt.Errorf("request for message ID %s already exists", messageID)
}
Expand All @@ -151,6 +153,8 @@ func (c *client) Receive(ctx context.Context, msg *types.MessageBody) {

messageID := GetMessageID(msg)

c.lggr.Debugw("Remote client target receiving message", "messageID", messageID)

req := c.messageIDToCallerRequest[messageID]
if req == nil {
c.lggr.Warnw("received response for unknown message ID ", "messageID", messageID)
Expand Down
4 changes: 4 additions & 0 deletions core/capabilities/remote/target/request/client_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ClientRequest struct {
responseIDCount map[[32]byte]int
errorCount map[string]int
responseReceived map[p2ptypes.PeerID]bool
lggr logger.Logger

requiredIdenticalResponses int

Expand Down Expand Up @@ -99,6 +100,7 @@ func NewClientRequest(ctx context.Context, lggr logger.Logger, req commoncap.Cap
responseReceived: responseReceived,
responseCh: make(chan commoncap.CapabilityResponse, 1),
wg: wg,
lggr: lggr,
}, nil
}

Expand Down Expand Up @@ -129,6 +131,8 @@ func (c *ClientRequest) OnMessage(_ context.Context, msg *types.MessageBody) err
return fmt.Errorf("sender missing from message")
}

c.lggr.Debugw("OnMessage called for client request", "messageID", msg.MessageId)

sender := remote.ToPeerID(msg.Sender)

received, expected := c.responseReceived[sender]
Expand Down
5 changes: 3 additions & 2 deletions core/capabilities/remote/target/request/server_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewServerRequest(capability capabilities.TargetCapability, capabilityID str
callingDon: callingDon,
requestMessageID: requestMessageID,
requestTimeout: requestTimeout,
lggr: lggr,
lggr: lggr.Named("ServerRequest"),
}
}

Expand All @@ -79,6 +79,7 @@ func (e *ServerRequest) OnMessage(ctx context.Context, msg *types.MessageBody) e
return fmt.Errorf("failed to add requester to request: %w", err)
}

e.lggr.Debugw("OnMessage called for request", "msgId", msg.MessageId, "calls", len(e.requesters), "hasResponse", e.response != nil)
if e.minimumRequiredRequestsReceived() && !e.hasResponse() {
if err := e.executeRequest(ctx, msg.Payload); err != nil {
e.setError(types.Error_INTERNAL_ERROR, err.Error())
Expand Down Expand Up @@ -216,7 +217,7 @@ func (e *ServerRequest) sendResponse(requester p2ptypes.PeerID) error {
responseMsg.Payload = e.response.response
}

e.lggr.Debugw("Sending response", "receiver", requester)
e.lggr.Debugw("Sending response", "receiver", requester, "msgId", e.requestMessageID)
if err := e.dispatcher.Send(requester, &responseMsg); err != nil {
return fmt.Errorf("failed to send response to dispatcher: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion core/capabilities/remote/target/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewServer(peerID p2ptypes.PeerID, underlying commoncap.TargetCapability, ca
requestIDToRequest: map[string]*request.ServerRequest{},
requestTimeout: requestTimeout,

lggr: lggr,
lggr: lggr.Named("TargetServer"),
stopCh: make(services.StopChan),
}
}
Expand Down Expand Up @@ -110,6 +110,7 @@ func (r *server) Receive(ctx context.Context, msg *types.MessageBody) {
r.receiveLock.Lock()
defer r.receiveLock.Unlock()

r.lggr.Debugw("received request for msg", "msgId", msg.MessageId)
if msg.Method != types.MethodExecute {
r.lggr.Errorw("received request for unsupported method type", "method", msg.Method)
return
Expand Down

0 comments on commit f594ee3

Please sign in to comment.