Skip to content

Commit

Permalink
apply comments and fix #1707
Browse files Browse the repository at this point in the history
Signed-off-by: denis-tingaikin <[email protected]>
  • Loading branch information
denis-tingaikin committed Dec 19, 2024
1 parent aad7b0c commit 7dfb136
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions pkg/networkservice/core/trace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Benchmark_LongRequest_Info-8 340 3765718 ns/op 273254 B/op
Benchmark_ShortRequest_Trace-8 79 13600986 ns/op 344445 B/op 8475 allocs/op
Benchmark_LongRequest_Trace-8 2 916385562 ns/op 20998324 B/op 694678 allocs/op
Benchmark_LongRequest_Trace_NoDiff-8 2 565520104 ns/op 12236116 B/op 585667 allocs/op
Benchmark_LongRequest_NoDiff_Trace-8 2 565520104 ns/op 12236116 B/op 585667 allocs/op
Benchmark_LongRequest_Diff_Warn-8 340 3765718 ns/op 273254 B/op 861 allocs/op
```
Expand All @@ -28,7 +28,7 @@ Benchmark_LongRequest_Info-8 373 3064039 ns/op 253359 B/op
Benchmark_ShortRequest_Trace-8 543 2599280 ns/op 237262 B/op 1825 allocs/op
Benchmark_LongRequest_Trace-8 9 131145361 ns/op 22433480 B/op 20749 allocs/op
Benchmark_LongRequest_Trace_NoDiff-8 18 72167456 ns/op 10900859 B/op 13685 allocs/op
Benchmark_LongRequest_NoDiff_Trace-8 18 72167456 ns/op 10900859 B/op 13685 allocs/op
Benchmark_LongRequest_Diff_Warn-8 31128 36019 ns/op 9600 B/op 200 allocs/op
```
2 changes: 1 addition & 1 deletion pkg/networkservice/core/trace/server_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func Benchmark_LongRequest_Trace(b *testing.B) {
}
}

func Benchmark_LongRequest_Trace_NoDiff(b *testing.B) {
func Benchmark_LongRequest_NoDiff_Trace(b *testing.B) {
var s = newTestStaticServerChain(100)
var request = newTestRequest(100)
var ctx = context.Background()
Expand Down
34 changes: 17 additions & 17 deletions pkg/networkservice/core/trace/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,21 @@ func TestTraceOutput(t *testing.T) {
require.NotNil(t, e)

expectedOutput := ` [TRAC] [id:conn-1] [type:networkService] (1) ⎆ testutil/LabelChangerFirstServer.Request()
[INFO] [id:conn-1] [type:networkService] (1.1) request={"connection":{"id":"conn-1","context":{"ip_context":{"src_ip_required":true}}},"mechanism_preferences":[{"cls":"LOCAL","type":"KERNEL"},{"cls":"LOCAL","type":"KERNEL","parameters":{"label":"v2"}}]}
[INFO] [id:conn-1] [type:networkService] (1.2) request-diff={"connection":{"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"A"}},"mechanism_preferences":[{"cls":"LOCAL","type":"KERNEL"},{"cls":"LOCAL","type":"KERNEL","parameters":{"label":"v2"}}]}
[TRAC] [id:conn-1] [type:networkService] (1.1) request={"connection":{"id":"conn-1","context":{"ip_context":{"src_ip_required":true}}},"mechanism_preferences":[{"cls":"LOCAL","type":"KERNEL"},{"cls":"LOCAL","type":"KERNEL","parameters":{"label":"v2"}}]}
[TRAC] [id:conn-1] [type:networkService] (1.2) request-diff={"connection":{"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"A"}},"mechanism_preferences":[{"cls":"LOCAL","type":"KERNEL"},{"cls":"LOCAL","type":"KERNEL","parameters":{"label":"v2"}}]}
[TRAC] [id:conn-1] [type:networkService] (2) ⎆ testutil/LabelChangerSecondServer.Request()
[INFO] [id:conn-1] [type:networkService] (2.1) request-diff={"connection":{"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"B"}},"mechanism_preferences":[{"cls":"LOCAL","type":"KERNEL"},{"cls":"LOCAL","type":"KERNEL","parameters":{"label":"v2"}}]}
[INFO] [id:conn-1] [type:networkService] (2.2) request-response={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"B"}}
[INFO] [id:conn-1] [type:networkService] (2.3) request-response-diff={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"C"}}
[INFO] [id:conn-1] [type:networkService] (1.3) request-response-diff={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"D"}}
[TRAC] [id:conn-1] [type:networkService] (2.1) request-diff={"connection":{"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"B"}},"mechanism_preferences":[{"cls":"LOCAL","type":"KERNEL"},{"cls":"LOCAL","type":"KERNEL","parameters":{"label":"v2"}}]}
[TRAC] [id:conn-1] [type:networkService] (2.2) request-response={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"B"}}
[TRAC] [id:conn-1] [type:networkService] (2.3) request-response-diff={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"C"}}
[TRAC] [id:conn-1] [type:networkService] (1.3) request-response-diff={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"D"}}
[TRAC] [id:conn-1] [type:networkService] (1) ⎆ testutil/LabelChangerFirstServer.Close()
[INFO] [id:conn-1] [type:networkService] (1.1) close={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"D"}}
[INFO] [id:conn-1] [type:networkService] (1.2) close-diff={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"W"}}
[TRAC] [id:conn-1] [type:networkService] (1.1) close={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"D"}}
[TRAC] [id:conn-1] [type:networkService] (1.2) close-diff={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"W"}}
[TRAC] [id:conn-1] [type:networkService] (2) ⎆ testutil/LabelChangerSecondServer.Close()
[INFO] [id:conn-1] [type:networkService] (2.1) close-diff={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"X"}}
[INFO] [id:conn-1] [type:networkService] (2.2) close-response={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"X"}}
[INFO] [id:conn-1] [type:networkService] (2.3) close-response-diff={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"Y"}}
[INFO] [id:conn-1] [type:networkService] (1.3) close-response-diff={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"Z"}}
[TRAC] [id:conn-1] [type:networkService] (2.1) close-diff={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"X"}}
[TRAC] [id:conn-1] [type:networkService] (2.2) close-response={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"X"}}
[TRAC] [id:conn-1] [type:networkService] (2.3) close-response-diff={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"Y"}}
[TRAC] [id:conn-1] [type:networkService] (1.3) close-response-diff={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"Z"}}
`
result := testutil.TrimLogTime(&buff)

Expand Down Expand Up @@ -146,14 +146,14 @@ func TestErrorOutput(t *testing.T) {
require.Nil(t, conn)

expectedOutput := ` [TRAC] [id:conn-1] [type:networkService] (1) ⎆ testutil/LabelChangerFirstServer.Request()
[INFO] [id:conn-1] [type:networkService] (1.1) request={"connection":{"id":"conn-1","context":{"ip_context":{"src_ip_required":true}}},"mechanism_preferences":[{"cls":"LOCAL","type":"KERNEL"},{"cls":"LOCAL","type":"KERNEL","parameters":{"label":"v2"}}]}
[INFO] [id:conn-1] [type:networkService] (1.2) request-diff={"connection":{"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"A"}},"mechanism_preferences":[{"cls":"LOCAL","type":"KERNEL"},{"cls":"LOCAL","type":"KERNEL","parameters":{"label":"v2"}}]}
[TRAC] [id:conn-1] [type:networkService] (1.1) request={"connection":{"id":"conn-1","context":{"ip_context":{"src_ip_required":true}}},"mechanism_preferences":[{"cls":"LOCAL","type":"KERNEL"},{"cls":"LOCAL","type":"KERNEL","parameters":{"label":"v2"}}]}
[TRAC] [id:conn-1] [type:networkService] (1.2) request-diff={"connection":{"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"A"}},"mechanism_preferences":[{"cls":"LOCAL","type":"KERNEL"},{"cls":"LOCAL","type":"KERNEL","parameters":{"label":"v2"}}]}
[TRAC] [id:conn-1] [type:networkService] (2) ⎆ testutil/LabelChangerSecondServer.Request()
[INFO] [id:conn-1] [type:networkService] (2.1) request-diff={"connection":{"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"B"}},"mechanism_preferences":[{"cls":"LOCAL","type":"KERNEL"},{"cls":"LOCAL","type":"KERNEL","parameters":{"label":"v2"}}]}
[TRAC] [id:conn-1] [type:networkService] (2.1) request-diff={"connection":{"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"B"}},"mechanism_preferences":[{"cls":"LOCAL","type":"KERNEL"},{"cls":"LOCAL","type":"KERNEL","parameters":{"label":"v2"}}]}
[TRAC] [id:conn-1] [type:networkService] (3) ⎆ testutil/ErrorServer.Request()
[INFO] [id:conn-1] [type:networkService] (3.1) request-response={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"B"}}
[TRAC] [id:conn-1] [type:networkService] (3.1) request-response={"id":"conn-1","context":{"ip_context":{"src_ip_required":true}},"labels":{"Label":"B"}}
[ERRO] [id:conn-1] [type:networkService] (3.2) Error returned from api/pkg/api/networkservice/networkServiceClient.Close; github.com/networkservicemesh/sdk/pkg/networkservice/core/trace.(*beginTraceClient).Close; /root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/trace/client.go:85; github.com/networkservicemesh/sdk/pkg/networkservice/core/next.(*nextClient).Close; /root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/next/client.go:65; github.com/networkservicemesh/sdk/pkg/networkservice/core/next.(*nextClient).Close; /root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/next/client.go:65; github.com/networkservicemesh/sdk/pkg/networkservice/core/trace.(*endTraceClient).Close; /root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/trace/client.go:106; github.com/networkservicemesh/sdk/pkg/networkservice/core/next.(*nextClient).Close; /root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/next/client.go:65;
[INFO] [id:conn-1] [type:networkService] (2.2) request-response-diff=null
[TRAC] [id:conn-1] [type:networkService] (2.2) request-response-diff=null
[ERRO] [id:conn-1] [type:networkService] (2.3) Error returned from api/pkg/api/networkservice/networkServiceClient.Close; github.com/networkservicemesh/sdk/pkg/networkservice/core/trace.(*beginTraceClient).Close; /root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/trace/client.go:85; github.com/networkservicemesh/sdk/pkg/networkservice/core/next.(*nextClient).Close; /root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/next/client.go:65; github.com/networkservicemesh/sdk/pkg/networkservice/core/next.(*nextClient).Close; /root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/next/client.go:65; github.com/networkservicemesh/sdk/pkg/networkservice/core/trace.(*endTraceClient).Close; /root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/trace/client.go:106; github.com/networkservicemesh/sdk/pkg/networkservice/core/next.(*nextClient).Close; /root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/next/client.go:65;
[ERRO] [id:conn-1] [type:networkService] (1.3) Error returned from api/pkg/api/networkservice/networkServiceClient.Close; github.com/networkservicemesh/sdk/pkg/networkservice/core/trace.(*beginTraceClient).Close; /root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/trace/client.go:85; github.com/networkservicemesh/sdk/pkg/networkservice/core/next.(*nextClient).Close; /root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/next/client.go:65; github.com/networkservicemesh/sdk/pkg/networkservice/core/next.(*nextClient).Close; /root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/next/client.go:65; github.com/networkservicemesh/sdk/pkg/networkservice/core/trace.(*endTraceClient).Close; /root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/trace/client.go:106; github.com/networkservicemesh/sdk/pkg/networkservice/core/next.(*nextClient).Close; /root/go/pkg/mod/github.com/networkservicemesh/[email protected]/pkg/networkservice/core/next/client.go:65;
`
Expand Down
2 changes: 1 addition & 1 deletion pkg/networkservice/core/trace/traceconcise/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func logObject(ctx context.Context, k, v interface{}) {
msg := ""
cc, err := json.Marshal(v)
if err == nil {
msg = stringutils.CovertBytesToString(cc)
msg = stringutils.ConvertBytesToString(cc)
} else {
msg = fmt.Sprint(v)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/networkservice/core/trace/traceverbose/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ func logObjectTrace(ctx context.Context, k, v interface{}) {
msg := ""
cc, err := json.Marshal(v)
if err == nil {
msg = stringutils.CovertBytesToString(cc)
msg = stringutils.ConvertBytesToString(cc)
} else {
msg = fmt.Sprint(v)
}
s.Infof("%v=%s", k, msg)
s.Tracef("%v=%s", k, msg)
}
2 changes: 1 addition & 1 deletion pkg/registry/core/trace/traceconcise/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func logObject(ctx context.Context, k, v interface{}) {
msg := ""
cc, err := json.Marshal(v)
if err == nil {
msg = stringutils.CovertBytesToString(cc)
msg = stringutils.ConvertBytesToString(cc)
} else {
msg = fmt.Sprint(v)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/core/trace/traceverbose/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func logObjectTrace(ctx context.Context, k, v interface{}) {
msg := ""
cc, err := json.Marshal(v)
if err == nil {
msg = stringutils.CovertBytesToString(cc)
msg = stringutils.ConvertBytesToString(cc)
} else {
msg = fmt.Sprint(v)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tools/log/defaultlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (l *defaultLogger) Object(k, v interface{}) {
msg := ""
cc, err := json.Marshal(v)
if err == nil {
msg = stringutils.CovertBytesToString(cc)
msg = stringutils.ConvertBytesToString(cc)
} else {
msg = fmt.Sprint(v)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/tools/log/logruslogger/logruslogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (s *logrusLogger) Object(k, v interface{}) {
msg := ""
cc, err := json.Marshal(v)
if err == nil {
msg = stringutils.CovertBytesToString(cc)
msg = stringutils.ConvertBytesToString(cc)
} else {
msg = fmt.Sprint(v)
}
Expand Down Expand Up @@ -197,7 +197,7 @@ func (s *traceLogger) Object(k, v interface{}) {
msg := ""
cc, err := json.Marshal(v)
if err == nil {
msg = stringutils.CovertBytesToString(cc)
msg = stringutils.ConvertBytesToString(cc)
} else {
msg = fmt.Sprint(v)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tools/log/spanlogger/spanlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (s *spanLogger) Object(k, v interface{}) {
msg := ""
cc, err := json.Marshal(v)
if err == nil {
msg = stringutils.CovertBytesToString(cc)
msg = stringutils.ConvertBytesToString(cc)
} else {
msg = fmt.Sprint(v)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/tools/stringutils/stringutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package stringutils

import "unsafe"

// CovertBytesToString converts slice of bytes to string via unsafe package with zero allocations.
// ConvertBytesToString converts slice of bytes to string via unsafe package with zero allocations.
// Note: slice MUST NOT be modified after using this function.
func CovertBytesToString(slice []byte) string {
func ConvertBytesToString(slice []byte) string {
// nolint
return *(*string)(unsafe.Pointer(&slice))
}

0 comments on commit 7dfb136

Please sign in to comment.