Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable grpc server reflection #5689

Merged
merged 5 commits into from May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/api/api.go
Expand Up @@ -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"
Expand Down Expand Up @@ -71,6 +72,7 @@ func New(
api.RegisterHandlerOnPrefix("/debug", api.healthHandler())
api.router.Handle("/", http.RedirectHandler(login.HandlerPrefix, http.StatusFound))

reflection.Register(api.grpcServer)
livio-a marked this conversation as resolved.
Show resolved Hide resolved
return api, nil
}

Expand Down
22 changes: 22 additions & 0 deletions 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"
Expand All @@ -9,3 +16,18 @@
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))
}

Check warning on line 28 in internal/api/grpc/probes.go

View check run for this annotation

Codecov / codecov/patch

internal/api/grpc/probes.go#L27-L28

Added lines #L27 - L28 were not covered by tests
for _, stream := range sd.Streams {
paths = append(paths, path.Join("/", sd.ServiceName, stream.StreamName))
}
return paths
}
32 changes: 32 additions & 0 deletions 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)
})
}
}