Skip to content

Commit

Permalink
Added HealthInfo (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajan-226 authored Aug 18, 2023
1 parent 577c59d commit 696223a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions service/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ func (h *handler) apiV1WorkflowRpc(c *gin.Context) {
return
}

func (h *handler) infoHealthCheck(c *gin.Context) {
h.logger.Debug("received Health check request")

resp := h.svc.ApiInfoHealth(c.Request.Context())
c.JSON(http.StatusOK, resp)

return
}

func (h *handler) apiV1WorkflowGetDataObjects(c *gin.Context) {
var req iwfidl.WorkflowGetDataObjectsRequest
if err := c.ShouldBindJSON(&req); err != nil {
Expand Down
1 change: 1 addition & 0 deletions service/api/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type ApiService interface {
ApiV1WorkflowResetPost(ctx context.Context, request iwfidl.WorkflowResetRequest) (*iwfidl.WorkflowResetResponse, *errors.ErrorAndStatus)
ApiV1WorkflowSkipTimerPost(ctx context.Context, request iwfidl.WorkflowSkipTimerRequest) *errors.ErrorAndStatus
ApiV1WorkflowDumpPost(ctx context.Context, request iwfidl.WorkflowDumpRequest) (*iwfidl.WorkflowDumpResponse, *errors.ErrorAndStatus)
ApiInfoHealth(ctx context.Context) *iwfidl.HealthInfo
Close()
}

Expand Down
2 changes: 2 additions & 0 deletions service/api/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const WorkflowStopApiPath = "/api/v1/workflow/stop"
const WorkflowInternalDumpApiPath = "/api/v1/workflow/internal/dump"
const WorkflowConfigUpdateApiPath = "/api/v1/workflow/config/update"
const WorkflowRpcApiPath = "/api/v1/workflow/rpc"
const InfoHealthCheck = "/info/healthcheck"

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

return router
}
13 changes: 13 additions & 0 deletions service/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io/ioutil"
"math"
"net/http"
"os"
"strings"
"time"

Expand Down Expand Up @@ -683,6 +684,18 @@ func (s *serviceImpl) ApiV1WorkflowDumpPost(ctx context.Context, request iwfidl.
}, nil
}

func (s *serviceImpl) ApiInfoHealth(ctx context.Context) *iwfidl.HealthInfo {
hostName, err := os.Hostname()
if err != nil {
hostName = "Hostname Not Available"
}
return &iwfidl.HealthInfo{
Condition: iwfidl.PtrString("OK"),
Hostname: iwfidl.PtrString(hostName),
Duration: iwfidl.PtrInt32(0),
}
}

func makeInvalidRequestError(msg string) *errors.ErrorAndStatus {
return errors.NewErrorAndStatus(http.StatusBadRequest,
iwfidl.UNCATEGORIZED_SUB_STATUS,
Expand Down

0 comments on commit 696223a

Please sign in to comment.