Skip to content

Commit 2ace989

Browse files
authored
Merge pull request #133 from yashsinghcodes/health-api
Workflow validation in health api, also run_status check
2 parents b7b52d2 + 1f6a9fa commit 2ace989

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

health.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ func deleteJunkOpsWorkflow(ctx context.Context, workflowHealth WorkflowHealth) e
399399
return err
400400
}
401401

402-
403402
if len(workflows) == 0 {
404403
//log.Printf("[DEBUG] Couldn't find any workflow named SHUFFLE_INTERNAL_OPS_WORKFLOW")
405404
return errors.New("Failed finding workflow named SHUFFLE_INTERNAL_OPS_WORKFLOW")
@@ -539,7 +538,7 @@ func RunOpsHealthCheck(resp http.ResponseWriter, request *http.Request) {
539538
resp.WriteHeader(200)
540539
resp.Write(platformData)
541540
return
542-
}
541+
}
543542

544543
log.Printf("[WARNING] Failed getting platform health from database: %s", err)
545544
resp.WriteHeader(500)
@@ -552,7 +551,7 @@ func RunOpsHealthCheck(resp http.ResponseWriter, request *http.Request) {
552551
var err error
553552
userInfo := User{
554553
ApiKey: apiKey,
555-
Role: "admin",
554+
Role: "admin",
556555
}
557556

558557
if project.Environment != "onprem" {
@@ -618,7 +617,7 @@ func RunOpsHealthCheck(resp http.ResponseWriter, request *http.Request) {
618617
}
619618
}
620619

621-
if platformHealth.Workflows.Create == true && platformHealth.Workflows.Delete == true && platformHealth.Workflows.Run == true && platformHealth.Workflows.RunFinished == true {
620+
if platformHealth.Workflows.Create == true && platformHealth.Workflows.Delete == true && platformHealth.Workflows.Run == true && platformHealth.Workflows.RunFinished == true && platformHealth.Workflows.RunStatus == "FINISHED" {
622621
log.Printf("[DEBUG] Platform health check successful! All necessary values are true.")
623622
platformHealth.Success = true
624623
}
@@ -692,7 +691,7 @@ func GetOpsDashboardStats(resp http.ResponseWriter, request *http.Request) {
692691

693692
healthChecks, err := GetPlatformHealth(ctx, afterInt, beforeInt, limitInt)
694693
if err != nil && strings.Contains(err.Error(), "Bad statuscode: 404") && project.Environment == "onprem" {
695-
log.Printf("[WARNING] Failed getting platform health from database: %s. Probably because no workflowexecutions have been done",err)
694+
log.Printf("[WARNING] Failed getting platform health from database: %s. Probably because no workflowexecutions have been done", err)
696695
resp.WriteHeader(200)
697696
resp.Write([]byte(`[]`))
698697
return
@@ -859,7 +858,7 @@ func fixOpensearch() error {
859858
// Create a new HTTP client
860859
client := &http.Client{}
861860

862-
// Send the request in a loop until a 200 status code is received
861+
// Send the request in a loop until a 200 status code is received
863862
res, err := client.Do(req)
864863
if err != nil {
865864
log.Printf("Error sending the request while fixing execution body: %s", err)
@@ -962,7 +961,7 @@ func RunOpsWorkflow(apiKey string, orgId string) (WorkflowHealth, error) {
962961
resp, err := client.Do(req)
963962
if err != nil {
964963
log.Printf("[ERROR] Failed sending health check HTTP request: %s", err)
965-
return workflowHealth, err
964+
return workflowHealth, err
966965
}
967966

968967
defer resp.Body.Close()
@@ -1002,6 +1001,7 @@ func RunOpsWorkflow(apiKey string, orgId string) (WorkflowHealth, error) {
10021001
if resp.StatusCode == 200 {
10031002
workflowHealth.Run = true
10041003
workflowHealth.ExecutionId = execution.ExecutionId
1004+
workflowHealth.WorkflowValidation = execution.Workflow.Validation.Valid
10051005
}
10061006

10071007
updateOpsCache(workflowHealth)
@@ -1146,13 +1146,12 @@ func InitOpsWorkflow(apiKey string, OrgId string) (string, error) {
11461146

11471147
log.Printf("[DEBUG] Ops dashboard user found. Setting up ops workflow")
11481148

1149-
11501149
client := &http.Client{}
11511150
body := GetWorkflowTest()
11521151
if project.Environment == "cloud" {
11531152
// url := "https://shuffler.io/api/v1/workflows/602c7cf5-500e-4bd1-8a97-aa5bc8a554e6"
11541153
// url := "https://shuffler.io/api/v1/workflows/7b729319-b395-4ba3-b497-d8246da67b1c"
1155-
url := "https://shuffler.io/api/v1/workflows/412256ca-ce62-4d20-9e55-1491548349e1"
1154+
url := "https://shuffler.io/api/v1/workflows/412256ca-ce62-4d20-9e55-1491548349e1"
11561155
req, err := http.NewRequest("GET", url, nil)
11571156
if err != nil {
11581157
log.Println("[ERROR] creating HTTP request:", err)

structs.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3963,13 +3963,14 @@ type AppHealth struct {
39633963
}
39643964

39653965
type WorkflowHealth struct {
3966-
Create bool `json:"create"`
3967-
Run bool `json:"run"`
3968-
RunFinished bool `json:"run_finished"`
3969-
RunStatus string `json:"run_status"`
3970-
Delete bool `json:"delete"`
3971-
ExecutionId string `json:"execution_id"`
3972-
WorkflowId string `json:"workflow_id"`
3966+
Create bool `json:"create"`
3967+
Run bool `json:"run"`
3968+
RunFinished bool `json:"run_finished"`
3969+
RunStatus string `json:"run_status"`
3970+
Delete bool `json:"delete"`
3971+
ExecutionId string `json:"execution_id"`
3972+
WorkflowId string `json:"workflow_id"`
3973+
WorkflowValidation bool `json:"workflow_validation"`
39733974
}
39743975

39753976
type HealthCheck struct {

0 commit comments

Comments
 (0)