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-04-25 10:55:42 +0300
committerMikhail Mazurskiy <mmazurskiy@gitlab.com>2021-05-01 03:33:44 +0300
commit11040e34367d0c3e579a0e2b08a84312d95075cd (patch)
treeeeca51c7c5dc67b18b8d478327e707b00731289a
parent72ed7402e2a3bfc52df85b344e5c5a967774b5f5 (diff)
Remove deprecated proto.FileDescriptor()ash2k/upgrade-proto-backup
-rw-r--r--internal/middleware/cache/cache_test.go7
-rw-r--r--internal/praefect/auth_test.go13
-rw-r--r--internal/praefect/helper_test.go7
-rw-r--r--internal/praefect/middleware/errorhandler_test.go8
-rw-r--r--internal/praefect/protoregistry/protoregistry.go35
-rw-r--r--internal/praefect/server_test.go7
-rw-r--r--proto/go/internal/filedescriptor.go34
-rw-r--r--proto/go/internal/linter/lint_test.go15
8 files changed, 35 insertions, 91 deletions
diff --git a/internal/middleware/cache/cache_test.go b/internal/middleware/cache/cache_test.go
index 5897d0c93..bf00d7ec4 100644
--- a/internal/middleware/cache/cache_test.go
+++ b/internal/middleware/cache/cache_test.go
@@ -8,7 +8,6 @@ import (
"testing"
"time"
- "github.com/golang/protobuf/proto"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -24,6 +23,8 @@ import (
"google.golang.org/grpc/health"
"google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/status"
+ "google.golang.org/protobuf/reflect/protodesc"
+ protoreg "google.golang.org/protobuf/reflect/protoregistry"
)
//go:generate make testdata/stream.pb.go
@@ -164,9 +165,9 @@ func (mc *mockCache) StartLease(repo *gitalypb.Repository) (diskcache.LeaseEnder
}
func streamFileDesc(t testing.TB) *descriptor.FileDescriptorProto {
- fdp, err := protoregistry.ExtractFileDescriptor(proto.FileDescriptor("middleware/cache/testdata/stream.proto"))
+ fd, err := protoreg.GlobalFiles.FindFileByPath("middleware/cache/testdata/stream.proto")
require.NoError(t, err)
- return fdp
+ return protodesc.ToFileDescriptorProto(fd)
}
func newTestSvc(t testing.TB, ctx context.Context, srvr *grpc.Server, svc testdata.TestServiceServer) (testdata.TestServiceClient, *grpc.ClientConn, func()) {
diff --git a/internal/praefect/auth_test.go b/internal/praefect/auth_test.go
index 4824d4e37..a5b4bc2b2 100644
--- a/internal/praefect/auth_test.go
+++ b/internal/praefect/auth_test.go
@@ -5,7 +5,6 @@ import (
"net"
"testing"
- "github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
gitalyauth "gitlab.com/gitlab-org/gitaly/auth"
@@ -21,6 +20,8 @@ import (
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
+ "google.golang.org/protobuf/reflect/protodesc"
+ protoreg "google.golang.org/protobuf/reflect/protoregistry"
)
func TestAuthFailures(t *testing.T) {
@@ -148,12 +149,8 @@ func runServer(t *testing.T, token string, required bool) (*grpc.Server, string,
},
},
}
-
- gz := proto.FileDescriptor("praefect/mock/mock.proto")
- fd, err := protoregistry.ExtractFileDescriptor(gz)
- if err != nil {
- t.Fatal(err)
- }
+ fd, err := protoreg.GlobalFiles.FindFileByPath("praefect/mock/mock.proto")
+ require.NoError(t, err)
logEntry := testhelper.DiscardTestEntry(t)
queue := datastore.NewMemoryReplicationEventQueue(conf)
@@ -163,7 +160,7 @@ func runServer(t *testing.T, token string, required bool) (*grpc.Server, string,
txMgr := transactions.NewManager(conf)
- registry, err := protoregistry.New(fd)
+ registry, err := protoregistry.New(protodesc.ToFileDescriptorProto(fd))
require.NoError(t, err)
coordinator := NewCoordinator(queue, nil, NewNodeManagerRouter(nodeMgr, nil), txMgr, conf, registry)
diff --git a/internal/praefect/helper_test.go b/internal/praefect/helper_test.go
index b9ee12476..95949b5a6 100644
--- a/internal/praefect/helper_test.go
+++ b/internal/praefect/helper_test.go
@@ -7,7 +7,6 @@ import (
"testing"
"time"
- "github.com/golang/protobuf/proto"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
@@ -28,6 +27,8 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/health"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
+ "google.golang.org/protobuf/reflect/protodesc"
+ protoreg "google.golang.org/protobuf/reflect/protoregistry"
)
// generates a praefect configuration with the specified number of backend
@@ -222,9 +223,9 @@ func runPraefectServer(t testing.TB, conf config.Config, opt buildOptions) (*grp
}
func mustLoadProtoReg(t testing.TB) *descriptor.FileDescriptorProto {
- fd, err := protoregistry.ExtractFileDescriptor(proto.FileDescriptor("praefect/mock/mock.proto"))
+ fd, err := protoreg.GlobalFiles.FindFileByPath("praefect/mock/mock.proto")
require.NoError(t, err)
- return fd
+ return protodesc.ToFileDescriptorProto(fd)
}
func listenAvailPort(tb testing.TB) (net.Listener, int) {
diff --git a/internal/praefect/middleware/errorhandler_test.go b/internal/praefect/middleware/errorhandler_test.go
index 1f0081cff..b179ee0d2 100644
--- a/internal/praefect/middleware/errorhandler_test.go
+++ b/internal/praefect/middleware/errorhandler_test.go
@@ -6,7 +6,6 @@ import (
"testing"
"time"
- "github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/empty"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -18,6 +17,8 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/praefect/protoregistry"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"google.golang.org/grpc"
+ "google.golang.org/protobuf/reflect/protodesc"
+ protoreg "google.golang.org/protobuf/reflect/protoregistry"
)
type simpleService struct {
@@ -56,11 +57,10 @@ func TestStreamInterceptor(t *testing.T) {
lis, err := net.Listen("unix", internalServerSocketPath)
require.NoError(t, err)
- gz := proto.FileDescriptor("praefect/mock/mock.proto")
- fd, err := protoregistry.ExtractFileDescriptor(gz)
+ fd, err := protoreg.GlobalFiles.FindFileByPath("praefect/mock/mock.proto")
require.NoError(t, err)
- registry, err := protoregistry.New(fd)
+ registry, err := protoregistry.New(protodesc.ToFileDescriptorProto(fd))
require.NoError(t, err)
require.NoError(t, err)
diff --git a/internal/praefect/protoregistry/protoregistry.go b/internal/praefect/protoregistry/protoregistry.go
index 3d6bf8699..4a1e3b7cd 100644
--- a/internal/praefect/protoregistry/protoregistry.go
+++ b/internal/praefect/protoregistry/protoregistry.go
@@ -1,10 +1,7 @@
package protoregistry
import (
- "bytes"
- "compress/gzip"
"fmt"
- "io/ioutil"
"reflect"
"strings"
@@ -12,6 +9,8 @@ import (
"github.com/golang/protobuf/protoc-gen-go/descriptor"
"gitlab.com/gitlab-org/gitaly/internal/protoutil"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+ "google.golang.org/protobuf/reflect/protodesc"
+ protoreg "google.golang.org/protobuf/reflect/protoregistry"
)
// GitalyProtoFileDescriptors is a slice of all gitaly registered file descriptors
@@ -26,13 +25,12 @@ var (
func init() {
for _, protoName := range gitalypb.GitalyProtos {
- gz := proto.FileDescriptor(protoName)
- fd, err := ExtractFileDescriptor(gz)
+ fd, err := protoreg.GlobalFiles.FindFileByPath(protoName)
if err != nil {
panic(err)
}
- GitalyProtoFileDescriptors = append(GitalyProtoFileDescriptors, fd)
+ GitalyProtoFileDescriptors = append(GitalyProtoFileDescriptors, protodesc.ToFileDescriptorProto(fd))
}
var err error
@@ -336,10 +334,11 @@ func parseMethodInfo(
}
func getFileTypes(filename string) ([]*descriptor.DescriptorProto, error) {
- sharedFD, err := ExtractFileDescriptor(proto.FileDescriptor(filename))
+ fd, err := protoreg.GlobalFiles.FindFileByPath(filename)
if err != nil {
return nil, err
}
+ sharedFD := protodesc.ToFileDescriptorProto(fd)
types := sharedFD.GetMessageType()
@@ -470,25 +469,3 @@ func (pr *Registry) IsInterceptedMethod(fullMethodName string) bool {
_, ok := pr.interceptedMethods[fullMethodName]
return ok
}
-
-// ExtractFileDescriptor extracts a FileDescriptorProto from a gzip'd buffer.
-// https://github.com/golang/protobuf/blob/9eb2c01ac278a5d89ce4b2be68fe4500955d8179/descriptor/descriptor.go#L50
-func ExtractFileDescriptor(gz []byte) (*descriptor.FileDescriptorProto, error) {
- r, err := gzip.NewReader(bytes.NewReader(gz))
- if err != nil {
- return nil, fmt.Errorf("failed to open gzip reader: %v", err)
- }
- defer r.Close()
-
- b, err := ioutil.ReadAll(r)
- if err != nil {
- return nil, fmt.Errorf("failed to uncompress descriptor: %v", err)
- }
-
- fd := &descriptor.FileDescriptorProto{}
- if err := proto.Unmarshal(b, fd); err != nil {
- return nil, fmt.Errorf("malformed FileDescriptorProto: %v", err)
- }
-
- return fd, nil
-}
diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go
index 595bbc4a3..a6eb62521 100644
--- a/internal/praefect/server_test.go
+++ b/internal/praefect/server_test.go
@@ -50,6 +50,8 @@ import (
"google.golang.org/grpc/health/grpc_health_v1"
grpc_metadata "google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
+ "google.golang.org/protobuf/reflect/protodesc"
+ protoreg "google.golang.org/protobuf/reflect/protoregistry"
)
func TestNewBackchannelServerFactory(t *testing.T) {
@@ -904,11 +906,10 @@ func TestErrorThreshold(t *testing.T) {
},
}
- gz := proto.FileDescriptor("praefect/mock/mock.proto")
- fd, err := protoregistry.ExtractFileDescriptor(gz)
+ fd, err := protoreg.GlobalFiles.FindFileByPath("praefect/mock/mock.proto")
require.NoError(t, err)
- registry, err := protoregistry.New(fd)
+ registry, err := protoregistry.New(protodesc.ToFileDescriptorProto(fd))
require.NoError(t, err)
for _, tc := range testCases {
diff --git a/proto/go/internal/filedescriptor.go b/proto/go/internal/filedescriptor.go
deleted file mode 100644
index cf0a1862c..000000000
--- a/proto/go/internal/filedescriptor.go
+++ /dev/null
@@ -1,34 +0,0 @@
-package internal
-
-import (
- "bytes"
- "compress/gzip"
- "fmt"
- "io/ioutil"
-
- "github.com/golang/protobuf/proto"
- "github.com/golang/protobuf/protoc-gen-go/descriptor"
-)
-
-// ExtractFile extracts a FileDescriptorProto from a gzip'd buffer.
-// Note: function is copied from the github.com/golang/protobuf dependency:
-// https://github.com/golang/protobuf/blob/9eb2c01ac278a5d89ce4b2be68fe4500955d8179/descriptor/descriptor.go#L50
-func ExtractFile(gz []byte) (*descriptor.FileDescriptorProto, error) {
- r, err := gzip.NewReader(bytes.NewReader(gz))
- if err != nil {
- return nil, fmt.Errorf("failed to open gzip reader: %v", err)
- }
- defer r.Close()
-
- b, err := ioutil.ReadAll(r)
- if err != nil {
- return nil, fmt.Errorf("failed to uncompress descriptor: %v", err)
- }
-
- fd := &descriptor.FileDescriptorProto{}
- if err := proto.Unmarshal(b, fd); err != nil {
- return nil, fmt.Errorf("malformed FileDescriptorProto: %v", err)
- }
-
- return fd, nil
-}
diff --git a/proto/go/internal/linter/lint_test.go b/proto/go/internal/linter/lint_test.go
index 0d4e0a129..b883398f1 100644
--- a/proto/go/internal/linter/lint_test.go
+++ b/proto/go/internal/linter/lint_test.go
@@ -4,12 +4,12 @@ import (
"errors"
"testing"
- "github.com/golang/protobuf/proto"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/gitaly/proto/go/internal"
_ "gitlab.com/gitlab-org/gitaly/proto/go/internal/linter/testdata"
+ "google.golang.org/protobuf/reflect/protodesc"
+ protoreg "google.golang.org/protobuf/reflect/protoregistry"
)
func TestLintFile(t *testing.T) {
@@ -42,11 +42,12 @@ func TestLintFile(t *testing.T) {
},
} {
t.Run(tt.protoPath, func(t *testing.T) {
- fdToCheck, err := internal.ExtractFile(proto.FileDescriptor(tt.protoPath))
+ fdToCheck, err := protoreg.GlobalFiles.FindFileByPath(tt.protoPath)
require.NoError(t, err)
+ fdToCheckProto := protodesc.ToFileDescriptorProto(fdToCheck)
req := &plugin.CodeGeneratorRequest{
- ProtoFile: []*descriptor.FileDescriptorProto{fdToCheck},
+ ProtoFile: []*descriptor.FileDescriptorProto{fdToCheckProto},
}
for _, protoPath := range []string{
@@ -57,12 +58,12 @@ func TestLintFile(t *testing.T) {
"lint.proto",
"shared.proto",
} {
- fd, err := internal.ExtractFile(proto.FileDescriptor(protoPath))
+ fd, err := protoreg.GlobalFiles.FindFileByPath(protoPath)
require.NoError(t, err)
- req.ProtoFile = append(req.ProtoFile, fd)
+ req.ProtoFile = append(req.ProtoFile, protodesc.ToFileDescriptorProto(fd))
}
- errs := LintFile(fdToCheck, req)
+ errs := LintFile(fdToCheckProto, req)
require.Equal(t, tt.errs, errs)
})
}