77 "encoding/json"
88 "errors"
99 "fmt"
10+ "io"
1011 "io/ioutil"
1112 "log"
1213 "net/http"
@@ -36,6 +37,11 @@ type executionResult struct {
3637 ID string `json:"id"`
3738}
3839
40+ type testRun struct {
41+ CRUrl string `json:"cloudrun_url"`
42+ Region string `json:"region"`
43+ }
44+
3945func updateOpsCache (workflowHealth WorkflowHealth ) {
4046 cacheKey := fmt .Sprintf ("ops-health-check" )
4147 ctx := context .Background ()
@@ -587,7 +593,7 @@ func RunOpsHealthCheck(resp http.ResponseWriter, request *http.Request) {
587593 errorChannel := make (chan error )
588594 go func () {
589595 log .Printf ("[DEBUG] Running workflowHealthChannel goroutine" )
590- workflowHealth , err := RunOpsWorkflow (apiKey , orgId )
596+ workflowHealth , err := RunOpsWorkflow (apiKey , orgId , "" )
591597 if err != nil {
592598 log .Printf ("[ERROR] Failed workflow health check: %s" , err )
593599 }
@@ -887,7 +893,7 @@ func fixOpensearch() error {
887893 return nil
888894}
889895
890- func RunOpsWorkflow (apiKey string , orgId string ) (WorkflowHealth , error ) {
896+ func RunOpsWorkflow (apiKey string , orgId string , cloudRunUrl string ) (WorkflowHealth , error ) {
891897 // run workflow with id 602c7cf5-500e-4bd1-8a97-aa5bc8a554e6
892898 ctx := context .Background ()
893899
@@ -902,11 +908,15 @@ func RunOpsWorkflow(apiKey string, orgId string) (WorkflowHealth, error) {
902908 }
903909
904910 baseUrl := os .Getenv ("SHUFFLE_CLOUDRUN_URL" )
905- if len (baseUrl ) == 0 {
911+ if len (baseUrl ) == 0 && ( cloudRunUrl == "" || len ( cloudRunUrl ) == 0 ) {
906912 log .Printf ("[DEBUG] Base url not set. Setting to default" )
907913 baseUrl = "https://shuffler.io"
908914 }
909915
916+ if len (baseUrl ) == 0 {
917+ baseUrl = cloudRunUrl
918+ }
919+
910920 if project .Environment == "onprem" {
911921 log .Printf ("[DEBUG] Onprem environment. Setting base url to localhost" )
912922 baseUrl = "http://localhost:5001"
@@ -1081,6 +1091,19 @@ func RunOpsWorkflow(apiKey string, orgId string) (WorkflowHealth, error) {
10811091 workflowHealth .RunStatus = executionResults .Status
10821092 }
10831093
1094+ if executionResults .Status == "FINISHED" {
1095+ log .Printf ("[DEBUG] Workflow Health exeution is finished, checking it's results" )
1096+
1097+ // yash asked to comment these out
1098+ // for _, r := range executionResults.Results {
1099+ // if r.Status != "SUCCESS" {
1100+ // workflowHealth.RunStatus = "FAILED"
1101+ // break
1102+ // }
1103+ // }
1104+ }
1105+
1106+
10841107 updateOpsCache (workflowHealth )
10851108
10861109 //log.Printf("[DEBUG] Workflow Health execution Result Status: %#v for executionID: %s", executionResults.Status, workflowHealth.ExecutionId)
@@ -1108,6 +1131,38 @@ func RunOpsWorkflow(apiKey string, orgId string) (WorkflowHealth, error) {
11081131 return workflowHealth , nil
11091132}
11101133
1134+ func RunHealthTest (resp http.ResponseWriter , req * http.Request ) {
1135+ response , err := io .ReadAll (req .Body )
1136+ if err != nil {
1137+ log .Printf ("[ERROR] Failed to read body of the health test case: %s" , err )
1138+ resp .WriteHeader (500 )
1139+ resp .Write ([]byte (`{"success": false, "reason": "failed to read the body"}` ))
1140+ return
1141+ }
1142+
1143+ var execData testRun
1144+ err = json .Unmarshal (response , & execData )
1145+ if err != nil {
1146+ log .Printf ("[ERROR] Error unmarshaling test data: %s" , err )
1147+ resp .WriteHeader (500 )
1148+ resp .Write ([]byte (`{"success": false, "reason": "failed to unmarshal the data"}` ))
1149+ return
1150+ }
1151+
1152+ apiKey := os .Getenv ("SHUFFLE_OPS_DASHBOARD_APIKEY" )
1153+ orgId := os .Getenv ("SHUFFLE_OPS_DASHBOARD_ORG" )
1154+
1155+
1156+ health , err := RunOpsWorkflow (apiKey , orgId , execData .CRUrl )
1157+ if err != nil {
1158+ log .Printf ("[ERROR] Health test failed %v" , err )
1159+ }
1160+
1161+ jsonHealth , err := json .Marshal (health )
1162+ resp .WriteHeader (200 )
1163+ resp .Write (jsonHealth )
1164+ }
1165+
11111166func InitOpsWorkflow (apiKey string , OrgId string ) (string , error ) {
11121167 opsDashboardApikey := apiKey
11131168 opsDashboardOrgId := OrgId
0 commit comments