From 27e98523679b392e7e8f33fa91df7f214c891e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Fri, 14 Apr 2023 16:34:12 +0300 Subject: [PATCH 1/2] feat: enable grpc server reflection --- internal/api/api.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/api/api.go b/internal/api/api.go index 3cb851e3d0..d636867f7e 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -12,6 +12,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/health" healthpb "google.golang.org/grpc/health/grpc_health_v1" + "google.golang.org/grpc/reflection" internal_authz "github.com/zitadel/zitadel/internal/api/authz" "github.com/zitadel/zitadel/internal/api/grpc/server" @@ -67,6 +68,7 @@ func New( api.RegisterHandlerOnPrefix("/debug", api.healthHandler()) api.router.Handle("/", http.RedirectHandler(login.HandlerPrefix, http.StatusFound)) + reflection.Register(api.grpcServer) return api, nil } From 62b4c31834f0855e3fa531af189dc4296e0190c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Sun, 7 May 2023 16:47:43 +0200 Subject: [PATCH 2/2] add server reflection to Probes list --- internal/api/grpc/probes.go | 22 ++++++++++++++++++++++ internal/api/grpc/probes_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 internal/api/grpc/probes_test.go diff --git a/internal/api/grpc/probes.go b/internal/api/grpc/probes.go index 21106cf885..8c1c57608f 100644 --- a/internal/api/grpc/probes.go +++ b/internal/api/grpc/probes.go @@ -1,5 +1,12 @@ package grpc +import ( + "path" + + "google.golang.org/grpc" + "google.golang.org/grpc/reflection/grpc_reflection_v1alpha" +) + const ( Healthz = "/Healthz" Readiness = "/Ready" @@ -9,3 +16,18 @@ const ( var ( Probes = []string{Healthz, Readiness, Validation} ) + +func init() { + Probes = append(Probes, AllPaths(grpc_reflection_v1alpha.ServerReflection_ServiceDesc)...) +} + +func AllPaths(sd grpc.ServiceDesc) []string { + paths := make([]string, 0, len(sd.Methods)+len(sd.Streams)) + for _, method := range sd.Methods { + paths = append(paths, path.Join("/", sd.ServiceName, method.MethodName)) + } + for _, stream := range sd.Streams { + paths = append(paths, path.Join("/", sd.ServiceName, stream.StreamName)) + } + return paths +} diff --git a/internal/api/grpc/probes_test.go b/internal/api/grpc/probes_test.go new file mode 100644 index 0000000000..96ff0e57e3 --- /dev/null +++ b/internal/api/grpc/probes_test.go @@ -0,0 +1,32 @@ +package grpc + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "google.golang.org/grpc" + "google.golang.org/grpc/reflection/grpc_reflection_v1alpha" +) + +func TestAllPaths(t *testing.T) { + type args struct { + sd grpc.ServiceDesc + } + tests := []struct { + name string + args args + want []string + }{ + { + name: "server reflection", + args: args{grpc_reflection_v1alpha.ServerReflection_ServiceDesc}, + want: []string{"/grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo"}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := AllPaths(tt.args.sd) + assert.Equal(t, tt.want, got) + }) + } +}