Skip to content

Commit b5ab4bf

Browse files
committed
2 parents a10661b + 9719d85 commit b5ab4bf

File tree

3 files changed

+77
-5
lines changed

3 files changed

+77
-5
lines changed

db-connector.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,9 @@ func GetExecutionVariables(ctx context.Context, executionId string) (string, int
15831583
}
15841584

15851585
func getExecutionFileValue(ctx context.Context, workflowExecution WorkflowExecution, action ActionResult) (string, error) {
1586+
projectName := os.Getenv("SHUFFLE_GCEPROJECT")
1587+
bucketName := project.BucketName
1588+
15861589
fullParsedPath := fmt.Sprintf("large_executions/%s/%s_%s", workflowExecution.ExecutionOrg, workflowExecution.ExecutionId, action.Action.ID)
15871590

15881591
cacheKey := fmt.Sprintf("%s_%s_action_replace", workflowExecution.ExecutionId, action.Action.ID)
@@ -1594,11 +1597,24 @@ func getExecutionFileValue(ctx context.Context, workflowExecution WorkflowExecut
15941597
}
15951598
}
15961599

1597-
bucket := project.StorageClient.Bucket(project.BucketName)
1600+
bucket := project.StorageClient.Bucket(bucketName)
15981601
obj := bucket.Object(fullParsedPath)
15991602
fileReader, err := obj.NewReader(ctx)
16001603
if err != nil {
1601-
return "", err
1604+
log.Printf("[ERROR] Failed reading file from bucket %s: %s. Will try with alternative solution.", bucketName, err)
1605+
1606+
if projectName != "shuffler" {
1607+
bucketName = fmt.Sprintf("%s.appspot.com", projectName)
1608+
bucket = project.StorageClient.Bucket(bucketName)
1609+
obj = bucket.Object(fullParsedPath)
1610+
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
1617+
}
16021618
}
16031619

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

health.go

Lines changed: 58 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,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+
11111166
func InitOpsWorkflow(apiKey string, OrgId string) (string, error) {
11121167
opsDashboardApikey := apiKey
11131168
opsDashboardOrgId := OrgId

shared.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7748,6 +7748,7 @@ func SaveWorkflow(resp http.ResponseWriter, request *http.Request) {
77487748
log.Printf("[AUDIT] Letting verified support admin %s access workflow %s (save workflow)", user.Username, workflow.ID)
77497749

77507750
workflow.ID = tmpworkflow.ID
7751+
77517752
} else if tmpworkflow.OrgId == user.ActiveOrg.Id && user.Role != "org-reader" {
77527753
log.Printf("[AUDIT] User %s is accessing workflow %s (save workflow)", user.Username, tmpworkflow.ID)
77537754
workflow.ID = tmpworkflow.ID

0 commit comments

Comments
 (0)