Skip to content

Commit 696223a

Browse files
authored
Added HealthInfo (#327)
1 parent 577c59d commit 696223a

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

service/api/handler.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ func (h *handler) apiV1WorkflowRpc(c *gin.Context) {
159159
return
160160
}
161161

162+
func (h *handler) infoHealthCheck(c *gin.Context) {
163+
h.logger.Debug("received Health check request")
164+
165+
resp := h.svc.ApiInfoHealth(c.Request.Context())
166+
c.JSON(http.StatusOK, resp)
167+
168+
return
169+
}
170+
162171
func (h *handler) apiV1WorkflowGetDataObjects(c *gin.Context) {
163172
var req iwfidl.WorkflowGetDataObjectsRequest
164173
if err := c.ShouldBindJSON(&req); err != nil {

service/api/interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type ApiService interface {
2323
ApiV1WorkflowResetPost(ctx context.Context, request iwfidl.WorkflowResetRequest) (*iwfidl.WorkflowResetResponse, *errors.ErrorAndStatus)
2424
ApiV1WorkflowSkipTimerPost(ctx context.Context, request iwfidl.WorkflowSkipTimerRequest) *errors.ErrorAndStatus
2525
ApiV1WorkflowDumpPost(ctx context.Context, request iwfidl.WorkflowDumpRequest) (*iwfidl.WorkflowDumpResponse, *errors.ErrorAndStatus)
26+
ApiInfoHealth(ctx context.Context) *iwfidl.HealthInfo
2627
Close()
2728
}
2829

service/api/routers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const WorkflowStopApiPath = "/api/v1/workflow/stop"
1919
const WorkflowInternalDumpApiPath = "/api/v1/workflow/internal/dump"
2020
const WorkflowConfigUpdateApiPath = "/api/v1/workflow/config/update"
2121
const WorkflowRpcApiPath = "/api/v1/workflow/rpc"
22+
const InfoHealthCheck = "/info/healthcheck"
2223

2324
// NewService returns a new router.
2425
func NewService(config config.Config, client UnifiedClient, logger log.Logger) *gin.Engine {
@@ -40,6 +41,7 @@ func NewService(config config.Config, client UnifiedClient, logger log.Logger) *
4041
router.POST(WorkflowInternalDumpApiPath, handler.apiV1WorkflowInternalDump)
4142
router.POST(WorkflowConfigUpdateApiPath, handler.apiV1WorkflowConfigUpdate)
4243
router.POST(WorkflowRpcApiPath, handler.apiV1WorkflowRpc)
44+
router.GET(InfoHealthCheck, handler.infoHealthCheck)
4345

4446
return router
4547
}

service/api/service.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"io/ioutil"
1212
"math"
1313
"net/http"
14+
"os"
1415
"strings"
1516
"time"
1617

@@ -683,6 +684,18 @@ func (s *serviceImpl) ApiV1WorkflowDumpPost(ctx context.Context, request iwfidl.
683684
}, nil
684685
}
685686

687+
func (s *serviceImpl) ApiInfoHealth(ctx context.Context) *iwfidl.HealthInfo {
688+
hostName, err := os.Hostname()
689+
if err != nil {
690+
hostName = "Hostname Not Available"
691+
}
692+
return &iwfidl.HealthInfo{
693+
Condition: iwfidl.PtrString("OK"),
694+
Hostname: iwfidl.PtrString(hostName),
695+
Duration: iwfidl.PtrInt32(0),
696+
}
697+
}
698+
686699
func makeInvalidRequestError(msg string) *errors.ErrorAndStatus {
687700
return errors.NewErrorAndStatus(http.StatusBadRequest,
688701
iwfidl.UNCATEGORIZED_SUB_STATUS,

0 commit comments

Comments
 (0)