Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Mazurskiy <mmazurskiy@gitlab.com>2021-06-28 14:37:06 +0300
committerMikhail Mazurskiy <mmazurskiy@gitlab.com>2021-06-28 14:37:06 +0300
commitc8bf3820f427d4dbf145238ffb6b4d44b22864f9 (patch)
treeaa7d2bf64f03ee740f221d267457913868a6168b
parentca1785dbca6cad0643a34d0a987e5164dad3d52f (diff)
Use ForceServerCodec() instead of CustomCodec()
Pick up https://github.com/grpc/grpc-go/pull/4205 Changelog: fixed
-rw-r--r--.golangci.yml3
-rw-r--r--internal/praefect/grpc-proxy/proxy/codec.go40
-rw-r--r--internal/praefect/grpc-proxy/proxy/examples_test.go4
-rw-r--r--internal/praefect/grpc-proxy/proxy/handler_ext_test.go6
-rw-r--r--internal/praefect/grpc-proxy/proxy/helper_test.go2
-rw-r--r--internal/praefect/middleware/errorhandler_test.go2
-rw-r--r--internal/praefect/server.go2
-rw-r--r--internal/praefect/server_test.go4
8 files changed, 19 insertions, 44 deletions
diff --git a/.golangci.yml b/.golangci.yml
index 68d9c5603..cdd60a5d8 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -738,9 +738,6 @@ issues:
text: "package github.com/golang/protobuf/ptypes is deprecated"
- linters:
- staticcheck
- text: "grpc.CustomCodec is deprecated"
- - linters:
- - staticcheck
text: "proto.MessageName is deprecated"
- linters:
- staticcheck
diff --git a/internal/praefect/grpc-proxy/proxy/codec.go b/internal/praefect/grpc-proxy/proxy/codec.go
index ef56ff2e3..d34a9fef4 100644
--- a/internal/praefect/grpc-proxy/proxy/codec.go
+++ b/internal/praefect/grpc-proxy/proxy/codec.go
@@ -5,22 +5,14 @@ import (
"github.com/golang/protobuf/proto"
"google.golang.org/grpc/encoding"
+ proto_codec "google.golang.org/grpc/encoding/proto"
)
-// Codec is an interface which is required to maintain compatibility with both
-// grpc.Codec and encoding.Codec.
-type Codec interface {
- Marshal(v interface{}) ([]byte, error)
- Unmarshal(data []byte, v interface{}) error
- Name() string
- String() string
-}
-
// NewCodec returns a proxying encoding.Codec with the default protobuf codec as parent.
//
// See CodecWithParent.
-func NewCodec() Codec {
- return CodecWithParent(&protoCodec{})
+func NewCodec() encoding.Codec {
+ return CodecWithParent(protoCodec{})
}
// CodecWithParent returns a proxying encoding.Codec with a user provided codec as parent.
@@ -29,8 +21,8 @@ func NewCodec() Codec {
// to the schema of the forwarded messages. It basically treats a gRPC message frame as raw bytes.
// However, if the server handler, or the client caller are not proxy-internal functions it will fall back
// to trying to decode the message using a fallback codec.
-func CodecWithParent(fallback encoding.Codec) Codec {
- return &rawCodec{fallback}
+func CodecWithParent(fallback encoding.Codec) encoding.Codec {
+ return rawCodec{fallback}
}
type rawCodec struct {
@@ -41,7 +33,7 @@ type frame struct {
payload []byte
}
-func (c *rawCodec) Marshal(v interface{}) ([]byte, error) {
+func (c rawCodec) Marshal(v interface{}) ([]byte, error) {
out, ok := v.(*frame)
if !ok {
return c.parentCodec.Marshal(v)
@@ -49,7 +41,7 @@ func (c *rawCodec) Marshal(v interface{}) ([]byte, error) {
return out.payload, nil
}
-func (c *rawCodec) Unmarshal(data []byte, v interface{}) error {
+func (c rawCodec) Unmarshal(data []byte, v interface{}) error {
dst, ok := v.(*frame)
if !ok {
return c.parentCodec.Unmarshal(data, v)
@@ -58,17 +50,10 @@ func (c *rawCodec) Unmarshal(data []byte, v interface{}) error {
return nil
}
-func (c *rawCodec) Name() string {
+func (c rawCodec) Name() string {
return fmt.Sprintf("proxy>%s", c.parentCodec.Name())
}
-// NOTE: this is required to satisfy the old grpc.Codec interface and can be
-// removed as soon as it is possible to create a grpc.ServerOption with
-// encoding.Codec.
-func (c *rawCodec) String() string {
- return c.Name()
-}
-
// protoCodec is a Codec implementation with protobuf. It is the default rawCodec for gRPC.
type protoCodec struct{}
@@ -81,12 +66,5 @@ func (protoCodec) Unmarshal(data []byte, v interface{}) error {
}
func (protoCodec) Name() string {
- return "proto"
-}
-
-// NOTE: this is required to satisfy the old grpc.Codec interface and can be
-// removed as soon as it is possible to create a grpc.ServerOption with
-// encoding.Codec.
-func (c protoCodec) String() string {
- return c.Name()
+ return proto_codec.Name
}
diff --git a/internal/praefect/grpc-proxy/proxy/examples_test.go b/internal/praefect/grpc-proxy/proxy/examples_test.go
index 8c49777bf..7090de83d 100644
--- a/internal/praefect/grpc-proxy/proxy/examples_test.go
+++ b/internal/praefect/grpc-proxy/proxy/examples_test.go
@@ -25,7 +25,7 @@ var (
func ExampleRegisterService() {
// A gRPC server with the proxying codec enabled.
- server := grpc.NewServer(grpc.CustomCodec(proxy.NewCodec()))
+ server := grpc.NewServer(grpc.ForceServerCodec(proxy.NewCodec()))
// Register a TestService with 4 of its methods explicitly.
proxy.RegisterService(server, director,
"mwitkow.testproto.TestService",
@@ -34,7 +34,7 @@ func ExampleRegisterService() {
func ExampleTransparentHandler() {
grpc.NewServer(
- grpc.CustomCodec(proxy.NewCodec()),
+ grpc.ForceServerCodec(proxy.NewCodec()),
grpc.UnknownServiceHandler(proxy.TransparentHandler(director)))
}
diff --git a/internal/praefect/grpc-proxy/proxy/handler_ext_test.go b/internal/praefect/grpc-proxy/proxy/handler_ext_test.go
index eae61c388..9565c71d9 100644
--- a/internal/praefect/grpc-proxy/proxy/handler_ext_test.go
+++ b/internal/praefect/grpc-proxy/proxy/handler_ext_test.go
@@ -261,7 +261,7 @@ func (s *ProxyHappySuite) SetupSuite() {
}
s.proxy = grpc.NewServer(
- grpc.CustomCodec(proxy.NewCodec()),
+ grpc.ForceServerCodec(proxy.NewCodec()),
grpc.StreamInterceptor(
grpc_middleware.ChainStreamServer(
// context tags usage is required by sentryhandler.StreamLogHandler
@@ -416,7 +416,7 @@ func TestProxyErrorPropagation(t *testing.T) {
require.NoError(t, err)
proxyServer := grpc.NewServer(
- grpc.CustomCodec(proxy.NewCodec()),
+ grpc.ForceServerCodec(proxy.NewCodec()),
grpc.UnknownServiceHandler(proxy.TransparentHandler(func(ctx context.Context, fullMethodName string, peeker proxy.StreamPeeker) (*proxy.StreamParameters, error) {
return proxy.NewStreamParameters(
proxy.Destination{
@@ -451,7 +451,7 @@ func TestRegisterStreamHandlers(t *testing.T) {
directorCalledError := errors.New("director was called")
server := grpc.NewServer(
- grpc.CustomCodec(proxy.NewCodec()),
+ grpc.ForceServerCodec(proxy.NewCodec()),
grpc.UnknownServiceHandler(proxy.TransparentHandler(func(ctx context.Context, fullMethodName string, peeker proxy.StreamPeeker) (*proxy.StreamParameters, error) {
return nil, directorCalledError
})),
diff --git a/internal/praefect/grpc-proxy/proxy/helper_test.go b/internal/praefect/grpc-proxy/proxy/helper_test.go
index c899198e1..5cf60d7d8 100644
--- a/internal/praefect/grpc-proxy/proxy/helper_test.go
+++ b/internal/praefect/grpc-proxy/proxy/helper_test.go
@@ -54,7 +54,7 @@ func newBackendPinger(tb testing.TB, ctx context.Context) (*grpc.ClientConn, *in
func newProxy(tb testing.TB, ctx context.Context, director proxy.StreamDirector, svc, method string) (*grpc.ClientConn, func()) {
proxySrvr := grpc.NewServer(
- grpc.CustomCodec(proxy.NewCodec()),
+ grpc.ForceServerCodec(proxy.NewCodec()),
grpc.UnknownServiceHandler(proxy.TransparentHandler(director)),
)
diff --git a/internal/praefect/middleware/errorhandler_test.go b/internal/praefect/middleware/errorhandler_test.go
index 3b5d12312..51fbcd457 100644
--- a/internal/praefect/middleware/errorhandler_test.go
+++ b/internal/praefect/middleware/errorhandler_test.go
@@ -70,7 +70,7 @@ func TestStreamInterceptor(t *testing.T) {
defer internalSrv.Stop()
srvOptions := []grpc.ServerOption{
- grpc.CustomCodec(proxy.NewCodec()),
+ grpc.ForceServerCodec(proxy.NewCodec()),
grpc.UnknownServiceHandler(proxy.TransparentHandler(func(ctx context.Context,
fullMethodName string,
peeker proxy.StreamPeeker,
diff --git a/internal/praefect/server.go b/internal/praefect/server.go
index 9fa63057a..42166a07b 100644
--- a/internal/praefect/server.go
+++ b/internal/praefect/server.go
@@ -135,7 +135,7 @@ func NewGRPCServer(
func proxyRequiredOpts(director proxy.StreamDirector) []grpc.ServerOption {
return []grpc.ServerOption{
- grpc.CustomCodec(proxy.NewCodec()),
+ grpc.ForceServerCodec(proxy.NewCodec()),
grpc.UnknownServiceHandler(proxy.TransparentHandler(director)),
}
}
diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go
index 4ce342ee0..a7fb0a1ec 100644
--- a/internal/praefect/server_test.go
+++ b/internal/praefect/server_test.go
@@ -771,7 +771,7 @@ func TestProxyWrites(t *testing.T) {
)
server := grpc.NewServer(
- grpc.CustomCodec(proxy.NewCodec()),
+ grpc.ForceServerCodec(proxy.NewCodec()),
grpc.UnknownServiceHandler(proxy.TransparentHandler(coordinator.StreamDirector)),
)
@@ -929,7 +929,7 @@ func TestErrorThreshold(t *testing.T) {
)
server := grpc.NewServer(
- grpc.CustomCodec(proxy.NewCodec()),
+ grpc.ForceServerCodec(proxy.NewCodec()),
grpc.UnknownServiceHandler(proxy.TransparentHandler(coordinator.StreamDirector)),
)