From 2224cbfb5bbe27b2ef9520d65655f2b34b72de57 Mon Sep 17 00:00:00 2001 From: Jonathan Vuillemin Date: Tue, 1 Oct 2024 10:03:28 +0200 Subject: [PATCH 1/4] feat(grpcserver): Added bufconn connection factory --- grpcserver/go.mod | 21 +++++------ grpcserver/go.sum | 34 ++++++++++------- grpcserver/grpcservertest/factory.go | 37 +++++++++++++++++++ grpcserver/grpcservertest/factory_test.go | 9 +++++ .../{bufconn.go => listener.go} | 0 .../{bufconn_test.go => listener_test.go} | 4 +- 6 files changed, 78 insertions(+), 27 deletions(-) create mode 100644 grpcserver/grpcservertest/factory.go create mode 100644 grpcserver/grpcservertest/factory_test.go rename grpcserver/grpcservertest/{bufconn.go => listener.go} (100%) rename grpcserver/grpcservertest/{bufconn_test.go => listener_test.go} (72%) diff --git a/grpcserver/go.mod b/grpcserver/go.mod index 84651b68..5c5614f9 100644 --- a/grpcserver/go.mod +++ b/grpcserver/go.mod @@ -3,16 +3,16 @@ module github.com/ankorstore/yokai/grpcserver go 1.20 require ( - github.com/ankorstore/yokai/generate v1.1.0 + github.com/ankorstore/yokai/generate v1.2.0 github.com/ankorstore/yokai/healthcheck v1.1.0 github.com/ankorstore/yokai/log v1.2.0 - github.com/ankorstore/yokai/trace v1.2.0 + github.com/ankorstore/yokai/trace v1.3.0 github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 - github.com/rs/zerolog v1.32.0 + github.com/rs/zerolog v1.33.0 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/otel/trace v1.24.0 - google.golang.org/grpc v1.62.1 - google.golang.org/protobuf v1.33.0 + google.golang.org/grpc v1.64.1 + google.golang.org/protobuf v1.34.2 ) require ( @@ -20,7 +20,6 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-logr/logr v1.4.1 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/golang/protobuf v1.5.4 // indirect github.com/google/uuid v1.6.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect github.com/mattn/go-colorable v0.1.13 // indirect @@ -33,10 +32,10 @@ require ( go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/sdk v1.24.0 // indirect go.opentelemetry.io/proto/otlp v1.1.0 // indirect - golang.org/x/net v0.22.0 // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240311173647-c811ad7063a7 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 // indirect + golang.org/x/net v0.26.0 // indirect + golang.org/x/sys v0.21.0 // indirect + golang.org/x/text v0.16.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/grpcserver/go.sum b/grpcserver/go.sum index a932365f..f07a1354 100644 --- a/grpcserver/go.sum +++ b/grpcserver/go.sum @@ -1,11 +1,15 @@ github.com/ankorstore/yokai/generate v1.1.0 h1:tu3S+uEYh+2qNo8Rf/WxWneDjh49YgDPzSnJfF8JkXA= github.com/ankorstore/yokai/generate v1.1.0/go.mod h1:gqS/i20wnvCOhcXydYdiGcASzBaeuW7GK6YYg/kkuY4= +github.com/ankorstore/yokai/generate v1.2.0 h1:37siukjPGSS2kRnCnPhiuiF373+0tgwp0teXHnMsBhA= +github.com/ankorstore/yokai/generate v1.2.0/go.mod h1:gqS/i20wnvCOhcXydYdiGcASzBaeuW7GK6YYg/kkuY4= github.com/ankorstore/yokai/healthcheck v1.1.0 h1:PXkEccym7iaVnQltpM5UFi0Xl0n+5rZDzlQju6HmGms= github.com/ankorstore/yokai/healthcheck v1.1.0/go.mod h1:IiYgjRa4G3OLZMwAuacuryZZAfDHsBH8PQoK4PgRdZ4= github.com/ankorstore/yokai/log v1.2.0 h1:jiuDiC0dtqIGIOsFQslUHYoFJ1qjI+rOMa6dI1LBf2Y= github.com/ankorstore/yokai/log v1.2.0/go.mod h1:MVvUcms1AYGo0BT6l88B9KJdvtK6/qGKdgyKVXfbmyc= github.com/ankorstore/yokai/trace v1.2.0 h1:Jnl++IGNpDYumsZJXP3qjhMdvyHbejiajQwIlU604w0= github.com/ankorstore/yokai/trace v1.2.0/go.mod h1:m7EL2MRBilgCtrly5gA4F0jkGSXR2EbG6LsotbTJ4nA= +github.com/ankorstore/yokai/trace v1.3.0 h1:0ji32oymIcxTmH5h6GRWLo5ypwBbWrZkXRf9rWF9070= +github.com/ankorstore/yokai/trace v1.3.0/go.mod h1:m7EL2MRBilgCtrly5gA4F0jkGSXR2EbG6LsotbTJ4nA= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= @@ -17,8 +21,6 @@ github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ4 github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= -github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -41,6 +43,8 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= +github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= @@ -61,23 +65,25 @@ go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw go.opentelemetry.io/proto/otlp v1.1.0 h1:2Di21piLrCqJ3U3eXGCTPHE9R8Nh+0uglSnOyxikMeI= go.opentelemetry.io/proto/otlp v1.1.0/go.mod h1:GpBHCBWiqvVLDqmHZsoMM3C5ySeKTC7ej/RNTae6MdY= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= -golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= -golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -google.golang.org/genproto/googleapis/api v0.0.0-20240311173647-c811ad7063a7 h1:oqta3O3AnlWbmIE3bFnWbu4bRxZjfbWCp0cKSuZh01E= -google.golang.org/genproto/googleapis/api v0.0.0-20240311173647-c811ad7063a7/go.mod h1:VQW3tUculP/D4B+xVCo+VgSq8As6wA9ZjHl//pmk+6s= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 h1:8EeVk1VKMD+GD/neyEHGmz7pFblqPjHoi+PGQIlLx2s= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= -google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk= -google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 h1:RFiFrvy37/mpSpdySBDrUdipW/dHwsRwh3J3+A9VgT4= +google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237/go.mod h1:Z5Iiy3jtmioajWHDGFk7CeugTyHtPvMHA4UTmUkyalE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= +google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= +google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/grpcserver/grpcservertest/factory.go b/grpcserver/grpcservertest/factory.go new file mode 100644 index 00000000..cd304b1a --- /dev/null +++ b/grpcserver/grpcservertest/factory.go @@ -0,0 +1,37 @@ +package grpcservertest + +import ( + "context" + "fmt" + "net" + + "google.golang.org/grpc" + "google.golang.org/grpc/test/bufconn" +) + +type TestBufconnConnectionFactory interface { + Create(opts ...grpc.DialOption) (*grpc.ClientConn, error) +} + +type DefaultTestBufconnConnectionFactory struct { + lis *bufconn.Listener +} + +func NewDefaultTestBufconnConnectionFactory(lis *bufconn.Listener) *DefaultTestBufconnConnectionFactory { + return &DefaultTestBufconnConnectionFactory{ + lis: lis, + } +} + +func (f *DefaultTestBufconnConnectionFactory) Create(opts ...grpc.DialOption) (*grpc.ClientConn, error) { + dialOptions := append( + []grpc.DialOption{ + grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { + return f.lis.Dial() + }), + }, + opts..., + ) + + return grpc.NewClient(fmt.Sprintf("passthrough://%s", f.lis.Addr().String()), dialOptions...) +} diff --git a/grpcserver/grpcservertest/factory_test.go b/grpcserver/grpcservertest/factory_test.go new file mode 100644 index 00000000..0821d31e --- /dev/null +++ b/grpcserver/grpcservertest/factory_test.go @@ -0,0 +1,9 @@ +package grpcservertest_test + +import ( + "testing" +) + +func TestDefaultTestBufconnConnectionFactory(t *testing.T) { + t.Parallel() +} diff --git a/grpcserver/grpcservertest/bufconn.go b/grpcserver/grpcservertest/listener.go similarity index 100% rename from grpcserver/grpcservertest/bufconn.go rename to grpcserver/grpcservertest/listener.go diff --git a/grpcserver/grpcservertest/bufconn_test.go b/grpcserver/grpcservertest/listener_test.go similarity index 72% rename from grpcserver/grpcservertest/bufconn_test.go rename to grpcserver/grpcservertest/listener_test.go index 93f39f3f..6e1c163d 100644 --- a/grpcserver/grpcservertest/bufconn_test.go +++ b/grpcserver/grpcservertest/listener_test.go @@ -11,6 +11,6 @@ import ( func TestNewBufconnListener(t *testing.T) { t.Parallel() - conn := grpcservertest.NewBufconnListener(1024) - assert.IsType(t, &bufconn.Listener{}, conn) + lis := grpcservertest.NewBufconnListener(1024) + assert.IsType(t, &bufconn.Listener{}, lis) } From e35f96205bb4550be2d396a9988315a166b0ba46 Mon Sep 17 00:00:00 2001 From: Daniel Halasz Date: Tue, 1 Oct 2024 10:24:52 +0200 Subject: [PATCH 2/4] feat(grpcserver): Added factory tests --- grpcserver/.golangci.yml | 2 +- grpcserver/grpcservertest/factory.go | 4 ++++ grpcserver/grpcservertest/factory_test.go | 24 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/grpcserver/.golangci.yml b/grpcserver/.golangci.yml index edf0e9ec..c5443fc8 100644 --- a/grpcserver/.golangci.yml +++ b/grpcserver/.golangci.yml @@ -40,7 +40,7 @@ linters: - importas - ineffassign - interfacebloat - - logrlint + - loggercheck - maintidx - makezero - misspell diff --git a/grpcserver/grpcservertest/factory.go b/grpcserver/grpcservertest/factory.go index cd304b1a..74df7231 100644 --- a/grpcserver/grpcservertest/factory.go +++ b/grpcserver/grpcservertest/factory.go @@ -9,6 +9,10 @@ import ( "google.golang.org/grpc/test/bufconn" ) +var ( + _ TestBufconnConnectionFactory = (*DefaultTestBufconnConnectionFactory)(nil) +) + type TestBufconnConnectionFactory interface { Create(opts ...grpc.DialOption) (*grpc.ClientConn, error) } diff --git a/grpcserver/grpcservertest/factory_test.go b/grpcserver/grpcservertest/factory_test.go index 0821d31e..b74c0631 100644 --- a/grpcserver/grpcservertest/factory_test.go +++ b/grpcserver/grpcservertest/factory_test.go @@ -2,8 +2,32 @@ package grpcservertest_test import ( "testing" + + "github.com/ankorstore/yokai/grpcserver/grpcservertest" + "github.com/stretchr/testify/assert" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" ) func TestDefaultTestBufconnConnectionFactory(t *testing.T) { t.Parallel() + + lis := grpcservertest.NewBufconnListener(1024) + factory := grpcservertest.NewDefaultTestBufconnConnectionFactory(lis) + + t.Run("implements TestBufconnConnectionFactory", func(t *testing.T) { + t.Parallel() + + assert.Implements(t, (*grpcservertest.TestBufconnConnectionFactory)(nil), factory) + }) + + t.Run("creates a connection", func(t *testing.T) { + t.Parallel() + + conn, err := factory.Create( + grpc.WithTransportCredentials(insecure.NewCredentials()), + ) + assert.NoError(t, err) + assert.IsType(t, &grpc.ClientConn{}, conn) + }) } From 49eb52d5a9bbd5eeff4569051580e6f091d7e206 Mon Sep 17 00:00:00 2001 From: Jonathan Vuillemin Date: Tue, 1 Oct 2024 11:05:12 +0200 Subject: [PATCH 3/4] feat(grpcserver): Adapted tests and linter --- grpcserver/factory_test.go | 8 +------- grpcserver/healthcheck_test.go | 11 +---------- grpcserver/logger.go | 12 ++++++------ grpcserver/logger_test.go | 11 +---------- 4 files changed, 9 insertions(+), 33 deletions(-) diff --git a/grpcserver/factory_test.go b/grpcserver/factory_test.go index 96951df9..0a793300 100644 --- a/grpcserver/factory_test.go +++ b/grpcserver/factory_test.go @@ -2,7 +2,6 @@ package grpcserver_test import ( "context" - "net" "testing" "github.com/ankorstore/yokai/generate/generatetest/uuid" @@ -98,12 +97,7 @@ func TestCreate(t *testing.T) { ctx = metadata.AppendToOutgoingContext(ctx, "x-request-id", testRequestId) // gRPC client preparation - conn, err := grpc.DialContext( - ctx, - "", - grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { - return lis.Dial() - }), + conn, err := grpcservertest.NewDefaultTestBufconnConnectionFactory(lis).Create( grpc.WithTransportCredentials(insecure.NewCredentials()), ) assert.NoError(t, err) diff --git a/grpcserver/healthcheck_test.go b/grpcserver/healthcheck_test.go index cedba6f5..26a42338 100644 --- a/grpcserver/healthcheck_test.go +++ b/grpcserver/healthcheck_test.go @@ -2,7 +2,6 @@ package grpcserver_test import ( "context" - "net" "testing" "github.com/ankorstore/yokai/generate/generatetest/uuid" @@ -156,9 +155,6 @@ func TestWatch(t *testing.T) { func prepareHealthCheckServiceGrpcServerAndClient(t *testing.T, checker *healthcheck.Checker, logger *log.Logger) (grpc_health_v1.HealthClient, func()) { t.Helper() - // context preparation - ctx := logger.WithContext(context.Background()) - // bufconn listener preparation lis := grpcservertest.NewBufconnListener(1024 * 1024) @@ -181,12 +177,7 @@ func prepareHealthCheckServiceGrpcServerAndClient(t *testing.T, checker *healthc }() // gRPC client preparation - conn, err := grpc.DialContext( - ctx, - "", - grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { - return lis.Dial() - }), + conn, err := grpcservertest.NewDefaultTestBufconnConnectionFactory(lis).Create( grpc.WithTransportCredentials(insecure.NewCredentials()), ) assert.NoError(t, err) diff --git a/grpcserver/logger.go b/grpcserver/logger.go index 65a64c4c..e3cb857f 100644 --- a/grpcserver/logger.go +++ b/grpcserver/logger.go @@ -106,7 +106,7 @@ func (i *GrpcLoggerInterceptor) UnaryInterceptor() grpc.UnaryServerInterceptor { Err(err). Str("grpcType", "unary"). Str("grpcMethod", info.FullMethod). - Int32("grpcCode", int32(errStatus.Code())). + Uint32("grpcCode", uint32(errStatus.Code())). Str("grpcStatus", errStatus.Code().String()). Str("grpcDuration", time.Since(now).String()) @@ -124,7 +124,7 @@ func (i *GrpcLoggerInterceptor) UnaryInterceptor() grpc.UnaryServerInterceptor { Info(). Str("grpcType", "unary"). Str("grpcMethod", info.FullMethod). - Int32("grpcCode", int32(codes.OK)). + Uint32("grpcCode", uint32(codes.OK)). Str("grpcStatus", codes.OK.String()). Str("grpcDuration", time.Since(now).String()) @@ -144,7 +144,7 @@ func (i *GrpcLoggerInterceptor) UnaryInterceptor() grpc.UnaryServerInterceptor { Err(err). Str("grpcType", "unary"). Str("grpcMethod", info.FullMethod). - Int32("grpcCode", int32(errStatus.Code())). + Uint32("grpcCode", uint32(errStatus.Code())). Str("grpcStatus", errStatus.Code().String()). Str("grpcDuration", time.Since(now).String()) @@ -226,7 +226,7 @@ func (i *GrpcLoggerInterceptor) StreamInterceptor() grpc.StreamServerInterceptor Err(err). Str("grpcType", "server-streaming"). Str("grpcMethod", info.FullMethod). - Int32("grpcCode", int32(errStatus.Code())). + Uint32("grpcCode", uint32(errStatus.Code())). Str("grpcStatus", errStatus.Code().String()). Str("grpcDuration", time.Since(now).String()) @@ -244,7 +244,7 @@ func (i *GrpcLoggerInterceptor) StreamInterceptor() grpc.StreamServerInterceptor Info(). Str("grpcType", "server-streaming"). Str("grpcMethod", info.FullMethod). - Int32("grpcCode", int32(codes.OK)). + Uint32("grpcCode", uint32(codes.OK)). Str("grpcStatus", codes.OK.String()). Str("grpcDuration", time.Since(now).String()) @@ -264,7 +264,7 @@ func (i *GrpcLoggerInterceptor) StreamInterceptor() grpc.StreamServerInterceptor Err(err). Str("grpcType", "server-streaming"). Str("grpcMethod", info.FullMethod). - Int32("grpcCode", int32(errStatus.Code())). + Uint32("grpcCode", uint32(errStatus.Code())). Str("grpcStatus", errStatus.Code().String()). Str("grpcDuration", time.Since(now).String()) diff --git a/grpcserver/logger_test.go b/grpcserver/logger_test.go index 5df7b179..426a51fe 100644 --- a/grpcserver/logger_test.go +++ b/grpcserver/logger_test.go @@ -4,7 +4,6 @@ import ( "context" "errors" "io" - "net" "testing" "github.com/ankorstore/yokai/generate/generatetest/uuid" @@ -753,9 +752,6 @@ func TestBidiWithExclusionAndError(t *testing.T) { func prepareTestServiceGrpcServerAndClient(t *testing.T, logger *log.Logger, exclusions []string, metadata map[string]string, withTestInterceptors bool) (proto.ServiceClient, func()) { t.Helper() - // context preparation - ctx := logger.WithContext(context.Background()) - // bufconn listener preparation lis := grpcservertest.NewBufconnListener(1024 * 1024) @@ -809,12 +805,7 @@ func prepareTestServiceGrpcServerAndClient(t *testing.T, logger *log.Logger, exc }() // gRPC client preparation - conn, err := grpc.DialContext( - ctx, - "", - grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { - return lis.Dial() - }), + conn, err := grpcservertest.NewDefaultTestBufconnConnectionFactory(lis).Create( grpc.WithTransportCredentials(insecure.NewCredentials()), ) assert.NoError(t, err) From efe113a9da963ea3b190f3b949e80e75235880ee Mon Sep 17 00:00:00 2001 From: Jonathan Vuillemin Date: Tue, 1 Oct 2024 11:24:57 +0200 Subject: [PATCH 4/4] feat(grpcserver): Code style --- grpcserver/grpcservertest/factory.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/grpcserver/grpcservertest/factory.go b/grpcserver/grpcservertest/factory.go index 74df7231..0a96d7a3 100644 --- a/grpcserver/grpcservertest/factory.go +++ b/grpcserver/grpcservertest/factory.go @@ -9,9 +9,7 @@ import ( "google.golang.org/grpc/test/bufconn" ) -var ( - _ TestBufconnConnectionFactory = (*DefaultTestBufconnConnectionFactory)(nil) -) +var _ TestBufconnConnectionFactory = (*DefaultTestBufconnConnectionFactory)(nil) type TestBufconnConnectionFactory interface { Create(opts ...grpc.DialOption) (*grpc.ClientConn, error)