Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added HealthInfo #327

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s swallow this error here and put a default message like host name not available. Because it’s not worth returning error here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I did 🤔
You mean changing "Hostname Not Available" to "host name not available"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh sorry i misread it on my phone

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