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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2020-11-18 15:34:11 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-11-18 16:33:15 +0300
commit2fc33c11817c52623812d39ad2258cb0edf7eccc (patch)
tree704c45484919fa907265c7b97f851c7e84909a45 /internal/praefect/protoregistry
parentf4648a1a4f0409532de2cc8d8348d5c326fe3d3b (diff)
protoregistry: Expose full method names of all registered RPCs
While the protoregistry knows about full method names for its registered MethodInfos, it doesn't expose them currently. This is required though in order to maintain our list of all transactional RPCs. Add two new functions to solve this: `Methods()` will return all existing registered methods, while `FullMethodName()` returns the full method name for such a MethodInfo.
Diffstat (limited to 'internal/praefect/protoregistry')
-rw-r--r--internal/praefect/protoregistry/protoregistry.go23
-rw-r--r--internal/praefect/protoregistry/protoregistry_test.go6
2 files changed, 25 insertions, 4 deletions
diff --git a/internal/praefect/protoregistry/protoregistry.go b/internal/praefect/protoregistry/protoregistry.go
index 62fc906f9..2dd6870f4 100644
--- a/internal/praefect/protoregistry/protoregistry.go
+++ b/internal/praefect/protoregistry/protoregistry.go
@@ -98,6 +98,7 @@ type MethodInfo struct {
requestName string // protobuf message name for input type
requestFactory protoFactory
storage []int
+ fullMethodName string
}
// TargetRepo returns the target repository for a protobuf message if it exists
@@ -117,6 +118,10 @@ func (mi MethodInfo) AdditionalRepo(msg proto.Message) (*gitalypb.Repository, bo
return repo, true, err
}
+func (mi MethodInfo) FullMethodName() string {
+ return mi.fullMethodName
+}
+
func (mi MethodInfo) getRepo(msg proto.Message, targetOid []int) (*gitalypb.Repository, error) {
if mi.requestName != proto.MessageName(msg) {
return nil, fmt.Errorf(
@@ -196,7 +201,7 @@ func New(protos ...*descriptor.FileDescriptorProto) (*Registry, error) {
continue
}
- mi, err := parseMethodInfo(p, method)
+ mi, err := parseMethodInfo(p, method, fullMethodName)
if err != nil {
return nil, err
}
@@ -240,7 +245,11 @@ func methodReqFactory(method *descriptor.MethodDescriptorProto) (protoFactory, e
return f, nil
}
-func parseMethodInfo(p *descriptor.FileDescriptorProto, methodDesc *descriptor.MethodDescriptorProto) (MethodInfo, error) {
+func parseMethodInfo(
+ p *descriptor.FileDescriptorProto,
+ methodDesc *descriptor.MethodDescriptorProto,
+ fullMethodName string,
+) (MethodInfo, error) {
opMsg, err := protoutil.GetOpExtension(methodDesc)
if err != nil {
return MethodInfo{}, err
@@ -277,6 +286,7 @@ func parseMethodInfo(p *descriptor.FileDescriptorProto, methodDesc *descriptor.M
Scope: scope,
requestName: requestName,
requestFactory: reqFactory,
+ fullMethodName: fullMethodName,
}
topLevelMsgs, err := getTopLevelMsgs(p)
@@ -451,6 +461,15 @@ func (pr *Registry) LookupMethod(fullMethodName string) (MethodInfo, error) {
return methodInfo, nil
}
+// Methods returns all registered methods
+func (pr *Registry) Methods() []MethodInfo {
+ methods := make([]MethodInfo, 0, len(pr.protos))
+ for _, proto := range pr.protos {
+ methods = append(methods, proto)
+ }
+ return methods
+}
+
// IsInterceptedMethod returns whether Praefect intercepts the method call instead of proxying it.
func (pr *Registry) IsInterceptedMethod(fullMethodName string) bool {
_, ok := pr.interceptedMethods[fullMethodName]
diff --git a/internal/praefect/protoregistry/protoregistry_test.go b/internal/praefect/protoregistry/protoregistry_test.go
index 8c5c56e2e..795ab3df9 100644
--- a/internal/praefect/protoregistry/protoregistry_test.go
+++ b/internal/praefect/protoregistry/protoregistry_test.go
@@ -4,7 +4,6 @@ import (
"fmt"
"testing"
- "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/praefect/protoregistry"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
@@ -176,9 +175,12 @@ func TestNewProtoRegistry(t *testing.T) {
for serviceName, methods := range expectedResults {
for methodName, opType := range methods {
method := fmt.Sprintf("/gitaly.%s/%s", serviceName, methodName)
+
methodInfo, err := r.LookupMethod(method)
require.NoError(t, err)
- assert.Equalf(t, opType, methodInfo.Operation, "expect %s:%s to have the correct op type", serviceName, methodName)
+
+ require.Equalf(t, opType, methodInfo.Operation, "expect %s:%s to have the correct op type", serviceName, methodName)
+ require.Equal(t, method, methodInfo.FullMethodName())
require.False(t, r.IsInterceptedMethod(method), method)
}
}