Skip to content

Commit 488244f

Browse files
authored
Merge pull request #260 from yashsinghcodes/quick
added opensearch health status
2 parents 607b32c + efbf0a8 commit 488244f

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

health.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/Masterminds/semver"
2121
"github.com/frikky/kin-openapi/openapi3"
2222
uuid "github.com/satori/go.uuid"
23+
"github.com/shuffle/opensearch-go/v4/opensearchapi"
2324
)
2425

2526
type appConfig struct {
@@ -723,6 +724,21 @@ func RunOpsHealthCheck(resp http.ResponseWriter, request *http.Request) {
723724
errorChannel <- err
724725
}()
725726

727+
if project.Environment != "cloud" {
728+
opensearchHealthChannel := make(chan opensearchapi.ClusterHealthResp)
729+
go func() {
730+
opensearchHealth, err := RunOpensearchOps(ctx)
731+
if err != nil {
732+
log.Printf("[ERROR] Failed running opensearch health check: %s", err)
733+
}
734+
735+
opensearchHealthChannel <- *opensearchHealth
736+
errorChannel <- err
737+
}()
738+
739+
platformHealth.OpensearchOps = <-opensearchHealthChannel
740+
}
741+
726742
// TODO: More testing for onprem health checks
727743
if project.Environment == "cloud" {
728744
openapiAppHealthChannel := make(chan AppHealth)
@@ -3431,6 +3447,20 @@ func HandleRerunExecutions(resp http.ResponseWriter, request *http.Request) {
34313447
resp.Write([]byte(fmt.Sprintf(`{"success": true, "reason": "Successfully RERAN %d executions"}`, total)))
34323448
}
34333449

3450+
func RunOpensearchOps(ctx context.Context) (*opensearchapi.ClusterHealthResp, error) {
3451+
if project.Environment == "cloud" {
3452+
return nil, errors.New("Not running opensearch health check")
3453+
}
3454+
req := opensearchapi.ClusterHealthReq{}
3455+
resp, err := project.Es.Cluster.Health(ctx, &req)
3456+
if err != nil {
3457+
log.Printf("[ERROR] Failed to query cluster health: %s", err)
3458+
return nil, err
3459+
}
3460+
3461+
return resp, nil
3462+
}
3463+
34343464
// Send in deleteall=true to delete ALL executions for the environment ID
34353465
func HandleStopExecutions(resp http.ResponseWriter, request *http.Request) {
34363466
cors := HandleCors(resp, request)

structs.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"encoding/xml"
55
"sync"
66
"time"
7+
8+
"github.com/shuffle/opensearch-go/v4/opensearchapi"
79
)
810

911
type AppContext struct {
@@ -4288,13 +4290,14 @@ type LiveExecutionStatus struct {
42884290
}
42894291

42904292
type HealthCheck struct {
4291-
Success bool `json:"success"`
4292-
Updated int64 `json:"updated"`
4293-
Apps AppHealth `json:"apps"`
4294-
Workflows WorkflowHealth `json:"workflows"`
4295-
PythonApps AppHealth `json:"python_apps"`
4296-
Datastore DatastoreHealth `json:"datastore"`
4297-
FileOps FileHealth `json:"fileops"`
4293+
Success bool `json:"success"`
4294+
Updated int64 `json:"updated"`
4295+
Apps AppHealth `json:"apps"`
4296+
Workflows WorkflowHealth `json:"workflows"`
4297+
PythonApps AppHealth `json:"python_apps"`
4298+
Datastore DatastoreHealth `json:"datastore"`
4299+
FileOps FileHealth `json:"fileops"`
4300+
OpensearchOps opensearchapi.ClusterHealthResp `json:"opensearch"`
42984301
}
42994302

43004303
type HealthCheckDB struct {

0 commit comments

Comments
 (0)