Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

fix: 🐛 API response of api/status #1434

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion go/process/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package process

import (
"encoding/json"
"fmt"
"sync"
"sync/atomic"
"time"
Expand All @@ -25,7 +27,7 @@ import (
"github.com/openark/orchestrator/go/util"

"github.com/openark/golib/log"
"github.com/openark/orchestrator/go/raft"
orcraft "github.com/openark/orchestrator/go/raft"
"github.com/patrickmn/go-cache"
)

Expand Down Expand Up @@ -121,6 +123,8 @@ func HealthTest() (health *HealthStatus, err error) {
health.Healthy = healthy
}

orcraft.IsLeader()

if orcraft.IsRaftEnabled() {
health.ActiveNode.Hostname = orcraft.GetLeader()
health.IsActiveNode = orcraft.IsLeader()
Expand All @@ -137,6 +141,32 @@ func HealthTest() (health *HealthStatus, err error) {
}
health.AvailableNodes, err = ReadAvailableNodes(true)

if !orcraft.IsLeader() {
resBytes, err := orcraft.HttpGetLeader("status")
if err != nil {
health.Error = err
return health, log.Errore(err)
}
type LeaderResp struct {
Code string
Message string
Details interface{}
}
var apiResp LeaderResp
if err = json.Unmarshal(resBytes, &apiResp); err != nil {
health.Error = err
return health, log.Errore(err)
}
healthOfLeader, ok := apiResp.Details.(map[string]interface{})
if ok {
var rhm []string
for _, v := range healthOfLeader["RaftHealthyMembers"].([]interface{}) {
rhm = append(rhm, fmt.Sprint(v))
}
health.RaftHealthyMembers = rhm
}
}

return health, nil
}

Expand Down