Skip to content

Commit 90dfb1d

Browse files
authored
Merge pull request #141 from yashsinghcodes/quick-fixes
Fixes for the bucket issue and some health API improvements.
2 parents 08a46f5 + 968f370 commit 90dfb1d

File tree

2 files changed

+62
-9
lines changed

2 files changed

+62
-9
lines changed

db-connector.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,13 +1608,13 @@ func getExecutionFileValue(ctx context.Context, workflowExecution WorkflowExecut
16081608
bucket = project.StorageClient.Bucket(bucketName)
16091609
obj = bucket.Object(fullParsedPath)
16101610
fileReader, err = obj.NewReader(ctx)
1611+
if err != nil {
1612+
log.Printf("[ERROR] Failed reading file again from bucket %s: %s", bucketName, err)
1613+
return "", err
1614+
}
1615+
} else {
1616+
return "", err
16111617
}
1612-
1613-
if err != nil {
1614-
log.Printf("[ERROR] Failed reading file again from bucket %s: %s", bucketName, err)
1615-
}
1616-
1617-
return "", err
16181618
}
16191619

16201620
data, err := ioutil.ReadAll(fileReader)

health.go

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
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+
3945
func 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,17 @@ 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+
for _, r := range executionResults.Results {
1097+
if r.Status != "SUCCESS" {
1098+
workflowHealth.RunStatus = "FAILED"
1099+
break
1100+
}
1101+
}
1102+
}
1103+
1104+
10841105
updateOpsCache(workflowHealth)
10851106

10861107
//log.Printf("[DEBUG] Workflow Health execution Result Status: %#v for executionID: %s", executionResults.Status, workflowHealth.ExecutionId)
@@ -1108,6 +1129,38 @@ func RunOpsWorkflow(apiKey string, orgId string) (WorkflowHealth, error) {
11081129
return workflowHealth, nil
11091130
}
11101131

1132+
func RunHealthTest(resp http.ResponseWriter, req *http.Request) {
1133+
response, err := io.ReadAll(req.Body)
1134+
if err != nil {
1135+
log.Printf("[ERROR] Failed to read body of the health test case: %s", err)
1136+
resp.WriteHeader(500)
1137+
resp.Write([]byte(`{"success": false, "reason": "failed to read the body"}`))
1138+
return
1139+
}
1140+
1141+
var execData testRun
1142+
err = json.Unmarshal(response, &execData)
1143+
if err != nil {
1144+
log.Printf("[ERROR] Error unmarshaling test data: %s", err)
1145+
resp.WriteHeader(500)
1146+
resp.Write([]byte(`{"success": false, "reason": "failed to unmarshal the data"}`))
1147+
return
1148+
}
1149+
1150+
apiKey := os.Getenv("SHUFFLE_OPS_DASHBOARD_APIKEY")
1151+
orgId := os.Getenv("SHUFFLE_OPS_DASHBOARD_ORG")
1152+
1153+
1154+
health, err := RunOpsWorkflow(apiKey, orgId, execData.CRUrl)
1155+
if err != nil {
1156+
log.Printf("[ERROR] Health test failed %v", err)
1157+
}
1158+
1159+
jsonHealth, err := json.Marshal(health)
1160+
resp.WriteHeader(200)
1161+
resp.Write(jsonHealth)
1162+
}
1163+
11111164
func InitOpsWorkflow(apiKey string, OrgId string) (string, error) {
11121165
opsDashboardApikey := apiKey
11131166
opsDashboardOrgId := OrgId

0 commit comments

Comments
 (0)