mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-11 14:43:40 +00:00
feat: enable grpc server reflection (#5689)
This change enables [gRPC server reflection](https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md). It allows for easier setting up of dev-tools like [gRPCurl](https://github.com/fullstorydev/grpcurl) and [gRPCui](https://github.com/fullstorydev/grpcui). To see it in action, after you start zitadel on the localhost: ``` go install github.com/fullstorydev/grpcui/cmd/grpcui@latest grpcui -plaintext localhost:8080 ```` ![image](https://user-images.githubusercontent.com/5411563/232060184-1a114640-e87a-48da-866f-ff8d597e790f.png)
This commit is contained in:
commit
e4427380f3
@ -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"
|
||||
@ -71,6 +72,7 @@ func New(
|
||||
api.RegisterHandlerOnPrefix("/debug", api.healthHandler())
|
||||
api.router.Handle("/", http.RedirectHandler(login.HandlerPrefix, http.StatusFound))
|
||||
|
||||
reflection.Register(api.grpcServer)
|
||||
return api, nil
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
32
internal/api/grpc/probes_test.go
Normal file
32
internal/api/grpc/probes_test.go
Normal file
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user