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: add Health Proto and Update gRPC/HTTP Health Registration #1632

Merged
merged 2 commits into from
Sep 26, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions docs/api-reference/apidocs.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/HealthResponse"
"$ref": "#/definitions/HealthCheckResponse"
}
},
"default": {
Expand All @@ -65,6 +65,14 @@
}
}
},
"parameters": [
{
"name": "service",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
"Health"
],
Expand Down Expand Up @@ -1371,7 +1379,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/WatchBody"
"$ref": "#/definitions/Watch.WatchBody"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Issue: Watch.WatchBody definition not found

The referenced definition #/definitions/Watch.WatchBody does not exist in apidocs.swagger.json. Please verify the definition name or update the reference accordingly.

🔗 Analysis chain

LGTM: Updated Watch method request body reference

The change in the request body reference for the Watch method from WatchBody to Watch.WatchBody appears to be part of a definition restructuring. This update is in line with the PR objectives of improving the API documentation.

Please ensure that the #/definitions/Watch.WatchBody definition exists and is correctly defined in the schema. Run the following command to verify:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the existence of the Watch.WatchBody definition
jq '.definitions["Watch.WatchBody"]' docs/api-reference/apidocs.swagger.json

Length of output: 277

}
}
],
Expand Down Expand Up @@ -2197,11 +2205,11 @@
},
"description": "Function type with result and arg types."
},
"HealthResponse": {
"HealthCheckResponse": {
"type": "object",
"properties": {
"status": {
"type": "string"
"$ref": "#/definitions/ServingStatus"
}
}
},
Expand Down Expand Up @@ -3088,6 +3096,17 @@
},
"description": "A field selection expression. e.g. `request.auth`."
},
"ServingStatus": {
"type": "string",
"enum": [
"UNKNOWN",
"SERVING",
"NOT_SERVING",
"SERVICE_UNKNOWN"
],
"default": "UNKNOWN",
"description": " - SERVICE_UNKNOWN: Used only by the Watch method."
},
"SourceInfo": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -3379,7 +3398,7 @@
}
}
},
"WatchBody": {
"Watch.WatchBody": {
"type": "object",
"properties": {
"snap_token": {
Expand Down
27 changes: 22 additions & 5 deletions docs/api-reference/openapiv2/apidocs.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/HealthResponse"
"$ref": "#/definitions/HealthCheckResponse"
}
},
"default": {
Expand All @@ -65,6 +65,14 @@
}
}
},
"parameters": [
{
"name": "service",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
"Health"
],
Expand Down Expand Up @@ -1371,7 +1379,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/WatchBody"
"$ref": "#/definitions/Watch.WatchBody"
}
}
],
Expand Down Expand Up @@ -2187,11 +2195,11 @@
},
"description": "Function type with result and arg types."
},
"HealthResponse": {
"HealthCheckResponse": {
"type": "object",
"properties": {
"status": {
"type": "string"
"$ref": "#/definitions/ServingStatus"
}
}
},
Expand Down Expand Up @@ -3068,6 +3076,15 @@
},
"description": "A field selection expression. e.g. `request.auth`."
},
"ServingStatus": {
"type": "string",
"enum": [
"SERVING",
"NOT_SERVING",
"SERVICE_UNKNOWN"
],
"description": " - SERVICE_UNKNOWN: Used only by the Watch method."
},
"SourceInfo": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -3359,7 +3376,7 @@
}
}
},
"WatchBody": {
"Watch.WatchBody": {
"type": "object",
"properties": {
"snap_token": {
Expand Down
10 changes: 5 additions & 5 deletions internal/servers/healthServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package servers
import (
"context"

v1 "github.com/Permify/permify/pkg/pb/base/v1"
"google.golang.org/grpc/codes"
health "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/status"
)

// HealthServer - Structure for Health Server
type HealthServer struct {
health.UnimplementedHealthServer
v1.UnimplementedHealthServer
}

// NewHealthServer - Creates new HealthServer Server
Expand All @@ -19,12 +19,12 @@ func NewHealthServer() *HealthServer {
}

// Check - Return health check status response
func (s *HealthServer) Check(_ context.Context, _ *health.HealthCheckRequest) (*health.HealthCheckResponse, error) {
return &health.HealthCheckResponse{Status: health.HealthCheckResponse_SERVING}, nil
func (s *HealthServer) Check(_ context.Context, _ *v1.HealthCheckRequest) (*v1.HealthCheckResponse, error) {
return &v1.HealthCheckResponse{Status: v1.HealthCheckResponse_SERVING}, nil
}

// Watch - TO:DO
func (s *HealthServer) Watch(_ *health.HealthCheckRequest, _ health.Health_WatchServer) error {
func (s *HealthServer) Watch(_ *v1.HealthCheckRequest, _ v1.Health_WatchServer) error {
// Example of how to register both methods but only implement the Check method.
return status.Error(codes.Unimplemented, "unimplemented")
}
Expand Down
13 changes: 5 additions & 8 deletions internal/servers/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import (
"google.golang.org/grpc/reflection"
"google.golang.org/protobuf/encoding/protojson"

health "google.golang.org/grpc/health/grpc_health_v1"

"github.com/Permify/permify/internal/authn/oidc"
"github.com/Permify/permify/internal/authn/preshared"
"github.com/Permify/permify/internal/config"
Expand Down Expand Up @@ -183,17 +181,15 @@ func (s *Container) Run(
grpcV1.RegisterBundleServer(grpcServer, NewBundleServer(s.BR, s.BW))
grpcV1.RegisterTenancyServer(grpcServer, NewTenancyServer(s.TR, s.TW))
grpcV1.RegisterWatchServer(grpcServer, NewWatchServer(s.W, s.DR))
grpcV1.RegisterHealthServer(grpcServer, NewHealthServer())

// Register health check and reflection services for gRPC.
health.RegisterHealthServer(grpcServer, NewHealthServer())
reflection.Register(grpcServer)

// Create another gRPC server, presumably for invoking permissions.
invokeServer := grpc.NewServer(opts...)
grpcV1.RegisterPermissionServer(invokeServer, NewPermissionServer(localInvoker))
grpcV1.RegisterHealthServer(invokeServer, NewHealthServer())

// Register health check and reflection services for the invokeServer.
health.RegisterHealthServer(invokeServer, NewHealthServer())
reflection.Register(invokeServer)

// If profiling is enabled, set up the profiler using the net/http package.
Expand Down Expand Up @@ -290,9 +286,7 @@ func (s *Container) Run(
}
}()

healthClient := health.NewHealthClient(conn)
muxOpts := []runtime.ServeMuxOption{
runtime.WithHealthzEndpoint(healthClient),
runtime.WithMarshalerOption(runtime.MIMEWildcard, &runtime.HTTPBodyMarshaler{
Marshaler: &runtime.JSONPb{
MarshalOptions: protojson.MarshalOptions{
Expand All @@ -308,6 +302,9 @@ func (s *Container) Run(

mux := runtime.NewServeMux(muxOpts...)

if err = grpcV1.RegisterHealthHandler(ctx, mux, conn); err != nil {
return err
}
if err = grpcV1.RegisterPermissionHandler(ctx, mux, conn); err != nil {
return err
}
Expand Down
Loading
Loading