Skip to content

Commit

Permalink
fix: health endpoint init is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ucatbas committed Sep 25, 2024
1 parent 1f1063c commit 9a3df44
Show file tree
Hide file tree
Showing 14 changed files with 4,643 additions and 3,820 deletions.
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"
}
}
],
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

0 comments on commit 9a3df44

Please sign in to comment.