From b0c06287039a37985af211e35441817a69d9170e Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Fri, 6 Oct 2023 15:57:23 +0530 Subject: [PATCH 1/2] perf: avoid byte slice to string conversion --- pkg/api/ontapi/zapi/client.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/api/ontapi/zapi/client.go b/pkg/api/ontapi/zapi/client.go index 5e6ab2166..aee9e054f 100644 --- a/pkg/api/ontapi/zapi/client.go +++ b/pkg/api/ontapi/zapi/client.go @@ -551,11 +551,11 @@ func (c *Client) TraceLogSet(collectorName string, config *node.Node) { } func (c *Client) printRequestAndResponse(req string, response []byte) { - res := "" - if response != nil { - res = string(response) - } if req != "" { + res := "" + if response != nil { + res = string(response) + } c.Logger.Info(). Str("Request", req). Str("Response", res). From dbb405d9e9ef5bff0d28caeae330bbab205a5247 Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Fri, 6 Oct 2023 17:44:05 +0530 Subject: [PATCH 2/2] perf: address review comments --- cmd/tools/rest/client.go | 8 ++------ pkg/api/ontapi/zapi/client.go | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/cmd/tools/rest/client.go b/cmd/tools/rest/client.go index 0aaff5ce7..13c4da307 100644 --- a/cmd/tools/rest/client.go +++ b/cmd/tools/rest/client.go @@ -103,14 +103,10 @@ func (c *Client) TraceLogSet(collectorName string, config *node.Node) { func (c *Client) printRequestAndResponse(req string, response []byte) { if c.logRest { - res := "" - if response != nil { - res = string(response) - } c.Logger.Info(). Str("Request", req). - Str("Response", res). - Msg("") + Bytes("Response", response). + Send() } } diff --git a/pkg/api/ontapi/zapi/client.go b/pkg/api/ontapi/zapi/client.go index aee9e054f..4d1e1c406 100644 --- a/pkg/api/ontapi/zapi/client.go +++ b/pkg/api/ontapi/zapi/client.go @@ -552,14 +552,10 @@ func (c *Client) TraceLogSet(collectorName string, config *node.Node) { func (c *Client) printRequestAndResponse(req string, response []byte) { if req != "" { - res := "" - if response != nil { - res = string(response) - } c.Logger.Info(). Str("Request", req). - Str("Response", res). - Msg("") + Bytes("Response", response). + Send() } }