Skip to content

Commit

Permalink
feat(api): add healthcheck routes (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen authored Mar 1, 2024
1 parent 9b79459 commit 4bd1b6f
Show file tree
Hide file tree
Showing 6 changed files with 338 additions and 103 deletions.
4 changes: 4 additions & 0 deletions api-contracts/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ components:
schemas:
$ref: "./components/schemas/_index.yaml"
paths:
/api/ready:
$ref: "./paths/metadata/metadata.yaml#/readiness"
/api/live:
$ref: "./paths/metadata/metadata.yaml#/liveness"
/api/v1/meta:
$ref: "./paths/metadata/metadata.yaml#/metadata"
/api/v1/meta/integrations:
Expand Down
26 changes: 26 additions & 0 deletions api-contracts/openapi/paths/metadata/metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
readiness:
get:
description: Gets the readiness status
operationId: readiness:get
responses:
"200":
description: Healthy
"500":
description: Not ready to accept traffic
security: []
summary: Get readiness
tags:
- Healthcheck
liveness:
get:
description: Gets the liveness status
operationId: liveness:get
responses:
"200":
description: Healthy
"500":
description: Not liveness
security: []
summary: Get liveness
tags:
- Healthcheck
metadata:
get:
description: Gets metadata for the Hatchet instance
Expand Down
25 changes: 25 additions & 0 deletions api/v1/server/handlers/metadata/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package metadata

import (
"fmt"

"github.com/labstack/echo/v4"

"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
)

func (u *MetadataService) LivenessGet(ctx echo.Context, request gen.LivenessGetRequestObject) (gen.LivenessGetResponseObject, error) {
return gen.LivenessGet200Response{}, nil
}

func (u *MetadataService) ReadinessGet(ctx echo.Context, request gen.ReadinessGetRequestObject) (gen.ReadinessGetResponseObject, error) {
if !u.config.Repository.Health().IsHealthy() {
return nil, fmt.Errorf("repository is not healthy")
}

if !u.config.TaskQueue.IsReady() {
return nil, fmt.Errorf("task queue is not healthy")
}

return gen.ReadinessGet200Response{}, nil
}
Loading

0 comments on commit 4bd1b6f

Please sign in to comment.