-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
agent_handler: Add wrapper to log request and response error
Signed-off-by: Cosmin Tupangiu <[email protected]>
- Loading branch information
1 parent
b6567b5
commit a2de742
Showing
4 changed files
with
76 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package service | ||
|
||
import ( | ||
"context" | ||
|
||
agentServer "github.com/kubev2v/migration-planner/internal/api/server/agent" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type AgentServiceHandlerLogger struct { | ||
delegate *AgentServiceHandler | ||
} | ||
|
||
func NewAgentServiceHandlerLogger(delegate *AgentServiceHandler) *AgentServiceHandlerLogger { | ||
return &AgentServiceHandlerLogger{delegate: delegate} | ||
} | ||
|
||
func (h *AgentServiceHandlerLogger) UpdateSourceInventory(ctx context.Context, request agentServer.UpdateSourceInventoryRequestObject) (agentServer.UpdateSourceInventoryResponseObject, error) { | ||
zap.S().Named("agent_handler").Debugw("update source inventory request", | ||
"source_id", request.Id, | ||
"agent_id", request.Body.AgentId, | ||
"inventory", request.Body.Inventory, | ||
) | ||
|
||
resp, err := h.delegate.UpdateSourceInventory(ctx, request) | ||
if err != nil { | ||
zap.S().Named("agent_handler").Errorf("failed to update source inventory: %s", err) | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
func (h *AgentServiceHandlerLogger) UpdateAgentStatus(ctx context.Context, request agentServer.UpdateAgentStatusRequestObject) (agentServer.UpdateAgentStatusResponseObject, error) { | ||
zap.S().Named("agent_handler").Debugw("update agent status request", | ||
"agent_id", request.Id, | ||
"source_id", request.Body.SourceId, | ||
"credential_url", request.Body.CredentialUrl, | ||
"status", request.Body.Status, | ||
"version", request.Body.Version, | ||
) | ||
|
||
resp, err := h.delegate.UpdateAgentStatus(ctx, request) | ||
if err != nil { | ||
zap.S().Named("agent_handler").Errorf("failed to update agent status: %s", err) | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
func (h *AgentServiceHandlerLogger) Health(ctx context.Context, request agentServer.HealthRequestObject) (agentServer.HealthResponseObject, error) { | ||
return h.delegate.Health(ctx, request) | ||
} |