Skip to content

Commit

Permalink
feat: Add fdb metadata version read in health check
Browse files Browse the repository at this point in the history
  • Loading branch information
garrensmith authored and efirs committed Oct 24, 2022
1 parent 8874aad commit 3a132a7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 6 additions & 0 deletions errors/errors.go
Expand Up @@ -80,6 +80,12 @@ func Aborted(format string, args ...any) error {
format, args...)
}

// Unavailable constructs service unavailable error (HTTP: 503)
func Unavailable(format string, args ...any) error {
return api.Errorf(api.Code_UNAVAILABLE,
format, args...)
}

// Unknown constructs internal server error (HTTP: 500).
func Unknown(format string, args ...any) error {
return api.Errorf(api.Code_UNKNOWN,
Expand Down
21 changes: 18 additions & 3 deletions server/services/v1/health.go
Expand Up @@ -22,6 +22,9 @@ import (
"github.com/go-chi/chi/v5"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
api "github.com/tigrisdata/tigris/api/server/v1"
"github.com/tigrisdata/tigris/errors"
"github.com/tigrisdata/tigris/server/metadata"
"github.com/tigrisdata/tigris/server/transaction"
"google.golang.org/grpc"
)

Expand All @@ -31,13 +34,25 @@ const (

type healthService struct {
api.UnimplementedHealthAPIServer

versionH *metadata.VersionHandler
txMgr *transaction.Manager
}

func newHealthService() *healthService {
return &healthService{}
func newHealthService(txMgr *transaction.Manager) *healthService {
return &healthService{
versionH: &metadata.VersionHandler{},
txMgr: txMgr,
}
}

func (h *healthService) Health(_ context.Context, _ *api.HealthCheckInput) (*api.HealthCheckResponse, error) {
func (h *healthService) Health(ctx context.Context, _ *api.HealthCheckInput) (*api.HealthCheckResponse, error) {
_, err := h.versionH.ReadInOwnTxn(ctx, h.txMgr, false)

if err != nil {
return nil, errors.Unavailable("Could not read metadata version")
}

return &api.HealthCheckResponse{
Response: "OK",
}, nil
Expand Down
2 changes: 1 addition & 1 deletion server/services/v1/service.go
Expand Up @@ -40,7 +40,7 @@ type Service interface {
func GetRegisteredServices(kvStore kv.KeyValueStore, searchStore search.Store, tenantMgr *metadata.TenantManager, txMgr *transaction.Manager) []Service {
var v1Services []Service
v1Services = append(v1Services, newApiService(kvStore, searchStore, tenantMgr, txMgr))
v1Services = append(v1Services, newHealthService())
v1Services = append(v1Services, newHealthService(txMgr))

userstore := metadata.NewUserStore(&metadata.DefaultMDNameRegistry{})
authProvider := getAuthProvider(userstore, txMgr)
Expand Down

0 comments on commit 3a132a7

Please sign in to comment.