Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix orchestrator showing as disconnected #4567

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 1 addition & 5 deletions cmd/cli/node/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ var alwaysColumns = []output.TableColumn[*models.NodeState]{
{
ColumnConfig: table.ColumnConfig{Name: "status"},
Value: func(ni *models.NodeState) string {
if ni.Info.ComputeNodeInfo != nil {
return ni.Connection.String()
}

return "" // nothing for requester nodes
return ni.Connection.String()
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/node_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func stringToConnection(s string) connection {
}

func (t connection) IsValid() bool {
return t >= connection(1) && t <= connection(len(strConnectionArray))
return t >= connection(0) && t <= connection(len(strConnectionArray))
}

type livenessContainer struct {
Expand Down
63 changes: 63 additions & 0 deletions pkg/node/heartbeat/heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (s *HeartbeatTestSuite) SetupTest() {

// Setup heartbeat server
s.heartbeatServer, err = NewServer(HeartbeatServerParams{
NodeID: "server-node",
Clock: s.clock,
Client: s.natsConn,
CheckFrequency: 1 * time.Second,
Expand Down Expand Up @@ -86,6 +87,56 @@ func (s *HeartbeatTestSuite) TearDownTest() {
}
}

func (s *HeartbeatTestSuite) TestUpdateNodeInfo() {
testCases := []struct {
name string
nodeID string
initialLiveness models.NodeConnectionState
expectedState models.NodeConnectionState
hasInitialState bool
}{
{
name: "Own node",
nodeID: s.heartbeatServer.nodeID,
expectedState: models.NodeStates.CONNECTED,
hasInitialState: false,
},
{
name: "Known node connected",
nodeID: "another-node",
initialLiveness: models.NodeStates.CONNECTED,
expectedState: models.NodeStates.CONNECTED,
hasInitialState: true,
},
{
name: "Known node unhealthy",
nodeID: "another-node",
initialLiveness: models.NodeStates.DISCONNECTED,
expectedState: models.NodeStates.DISCONNECTED,
hasInitialState: true,
},
{
name: "Unknown node no state",
nodeID: "another-node",
expectedState: models.NodeStates.DISCONNECTED,
hasInitialState: false,
},
}

for _, tc := range testCases {
s.T().Run(tc.name, func(t *testing.T) {
if tc.hasInitialState {
s.heartbeatServer.markNodeAs(tc.nodeID, tc.initialLiveness)
}

nodeState := &models.NodeState{Info: models.NodeInfo{NodeID: tc.nodeID}}
s.heartbeatServer.UpdateNodeInfo(nodeState)

s.Equal(tc.expectedState, nodeState.Connection, "expected %s, got %s", tc.expectedState, nodeState.Connection)
})
}
}

func (s *HeartbeatTestSuite) TestHeartbeatScenarios() {
ctx := context.Background()

Expand All @@ -95,6 +146,7 @@ func (s *HeartbeatTestSuite) TestHeartbeatScenarios() {
heartbeats []time.Duration
expectedState models.NodeConnectionState
waitUntil time.Duration
isOwnNode bool
}

testcases := []testcase{
Expand All @@ -120,10 +172,21 @@ func (s *HeartbeatTestSuite) TestHeartbeatScenarios() {
expectedState: models.NodeStates.DISCONNECTED,
waitUntil: time.Duration(10 * time.Second),
},
{
name: "own node",
includeInitial: true,
heartbeats: []time.Duration{time.Duration(30 * time.Second)},
expectedState: models.NodeStates.HEALTHY,
waitUntil: time.Duration(30 * time.Second),
isOwnNode: true,
},
}

for i, tc := range testcases {
nodeID := "node-" + strconv.Itoa(i)
if tc.isOwnNode {
nodeID = s.heartbeatServer.nodeID
}
client, err := NewClient(s.natsConn, nodeID, s.publisher)
s.Require().NoError(err)

Expand Down
13 changes: 12 additions & 1 deletion pkg/node/heartbeat/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import (
)

type HeartbeatServerParams struct {
NodeID string
Client *nats.Conn
Clock clock.Clock
CheckFrequency time.Duration
NodeDisconnectedAfter time.Duration
}

type HeartbeatServer struct {
nodeID string
clock clock.Clock
legacySubscriber *natsPubSub.PubSub[Heartbeat]
pqueue *collections.HashedPriorityQueue[string, TimestampedHeartbeat]
Expand Down Expand Up @@ -60,6 +62,7 @@ func NewServer(params HeartbeatServerParams) (*HeartbeatServer, error) {
}

return &HeartbeatServer{
nodeID: params.NodeID,
clock: clk,
legacySubscriber: legacySubscriber,
pqueue: pqueue,
Expand Down Expand Up @@ -126,6 +129,11 @@ func (h *HeartbeatServer) CheckQueue(ctx context.Context) {
break
}

if item.Value.NodeID == h.nodeID {
// We don't want to mark ourselves as disconnected
continue
}

if item.Value.Timestamp < disconnectedUnder {
h.markNodeAs(item.Value.NodeID, models.NodeStates.DISCONNECTED)
}
Expand All @@ -140,7 +148,10 @@ func (h *HeartbeatServer) markNodeAs(nodeID string, state models.NodeConnectionS

// UpdateNode will add the liveness for specific nodes to their NodeInfo
func (h *HeartbeatServer) UpdateNodeInfo(state *models.NodeState) {
if liveness, ok := h.livenessMap.Get(state.Info.NodeID); ok {
if state.Info.NodeID == h.nodeID {
// We don't want to mark ourselves as disconnected
state.Connection = models.NodeStates.CONNECTED
} else if liveness, ok := h.livenessMap.Get(state.Info.NodeID); ok {
state.Connection = liveness
} else {
// We've never seen this, so we'll mark it as unknown
Expand Down
4 changes: 3 additions & 1 deletion pkg/node/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewRequesterNode(
messageSerDeRegistry *ncl.MessageSerDeRegistry,
fsr *repo.FsRepo,
) (*Requester, error) {
nodeManager, heartbeatServer, err := createNodeManager(ctx, transportLayer, requesterConfig)
nodeManager, heartbeatServer, err := createNodeManager(ctx, nodeID, transportLayer, requesterConfig)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -374,6 +374,7 @@ func createNodeRanker(requesterConfig RequesterConfig, jobStore jobstore.Store)
}

func createNodeManager(ctx context.Context,
nodeId string,
transportLayer *nats_transport.NATSTransport,
requesterConfig RequesterConfig) (*manager.NodeManager, *heartbeat.HeartbeatServer, error) {
nodeInfoStore, err := createNodeInfoStore(ctx, transportLayer)
Expand All @@ -383,6 +384,7 @@ func createNodeManager(ctx context.Context,

// heartbeat service
heartbeatParams := heartbeat.HeartbeatServerParams{
NodeID: nodeId,
Client: transportLayer.Client(),
CheckFrequency: requesterConfig.ControlPlaneSettings.HeartbeatCheckFrequency.AsTimeDuration(),
NodeDisconnectedAfter: requesterConfig.ControlPlaneSettings.NodeDisconnectedAfter.AsTimeDuration(),
Expand Down
11 changes: 8 additions & 3 deletions webui/components/nodes/list/NodesOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ export function NodesOverview() {

const allNodes = response.data.Nodes ?? []
setNodes(allNodes)
const connected = allNodes.filter(node => getNodeConnectionStatus(node) == "CONNECTED").length
const connected = allNodes.filter(
(node) => getNodeConnectionStatus(node) == 'CONNECTED'
).length
setConnectedNodes(connected)
setNextToken(response.data.NextToken)
} catch (error) {
console.error('Error fetching nodes:', error)
setNodes([])
setConnectedNodes(0)
}
}, [isInitialized, pageSize, pageIndex, nextToken])
}, [isInitialized, pageIndex, nextToken])

useEffect(() => {
fetchNodes()
Expand Down Expand Up @@ -106,7 +108,10 @@ export function NodesOverview() {
<RefreshCw className="h-4 w-4" />
</Button>
</div>
<Badge variant="secondary" className="text-sm px-3 py-1 flex items-center gap-2">
<Badge
variant="outline"
className="text-sm px-3 py-1 flex items-center gap-2"
>
<Server className="h-4 w-4" />
<span>{connectedNodes} Connected</span>
</Badge>
Expand Down
Loading