mirror of
https://github.com/gravitl/netmaker.git
synced 2026-04-22 16:07:11 +08:00
NET-1920: Add disconnected node status (#3300)
* create peer ack table * add restricted status * add disconnected status
This commit is contained in:
@@ -71,6 +71,8 @@ const (
|
||||
USER_INVITES_TABLE_NAME = "user_invites"
|
||||
// TAG_TABLE_NAME - table for tags
|
||||
TAG_TABLE_NAME = "tags"
|
||||
// PEER_ACK_TABLE - table for failover peer ack
|
||||
PEER_ACK_TABLE = "peer_ack"
|
||||
// == ERROR CONSTS ==
|
||||
// NO_RECORD - no singular result found
|
||||
NO_RECORD = "no result found"
|
||||
@@ -158,6 +160,7 @@ func createTables() {
|
||||
CreateTable(USER_INVITES_TABLE_NAME)
|
||||
CreateTable(TAG_TABLE_NAME)
|
||||
CreateTable(ACLS_TABLE_NAME)
|
||||
CreateTable(PEER_ACK_TABLE)
|
||||
}
|
||||
|
||||
func CreateTable(tableName string) error {
|
||||
|
||||
@@ -18,6 +18,10 @@ func getNodeStatus(node *models.Node, t bool) {
|
||||
node.Status = models.OnlineSt
|
||||
return
|
||||
}
|
||||
if !node.Connected {
|
||||
node.Status = models.Disconnected
|
||||
return
|
||||
}
|
||||
if time.Since(node.LastCheckIn) > time.Minute*10 {
|
||||
node.Status = models.OfflineSt
|
||||
return
|
||||
|
||||
+6
-5
@@ -14,11 +14,12 @@ import (
|
||||
type NodeStatus string
|
||||
|
||||
const (
|
||||
OnlineSt NodeStatus = "online"
|
||||
OfflineSt NodeStatus = "offline"
|
||||
WarningSt NodeStatus = "warning"
|
||||
ErrorSt NodeStatus = "error"
|
||||
UnKnown NodeStatus = "unknown"
|
||||
OnlineSt NodeStatus = "online"
|
||||
OfflineSt NodeStatus = "offline"
|
||||
WarningSt NodeStatus = "warning"
|
||||
ErrorSt NodeStatus = "error"
|
||||
UnKnown NodeStatus = "unknown"
|
||||
Disconnected NodeStatus = "disconnected"
|
||||
)
|
||||
|
||||
// LastCheckInThreshold - if node's checkin more than this threshold,then node is declared as offline
|
||||
|
||||
@@ -17,6 +17,10 @@ func getNodeStatusOld(node *models.Node) {
|
||||
node.Status = models.OnlineSt
|
||||
return
|
||||
}
|
||||
if !node.Connected {
|
||||
node.Status = models.Disconnected
|
||||
return
|
||||
}
|
||||
if time.Since(node.LastCheckIn) > time.Minute*10 {
|
||||
node.Status = models.OfflineSt
|
||||
return
|
||||
@@ -31,12 +35,25 @@ func GetNodeStatus(node *models.Node, defaultEnabledPolicy bool) {
|
||||
node.Status = models.OfflineSt
|
||||
return
|
||||
}
|
||||
ingNode, err := logic.GetNodeByID(node.StaticNode.IngressGatewayID)
|
||||
if err != nil {
|
||||
node.Status = models.OfflineSt
|
||||
return
|
||||
}
|
||||
if !defaultEnabledPolicy {
|
||||
allowed, _ := logic.IsNodeAllowedToCommunicate(*node, ingNode, false)
|
||||
if !allowed {
|
||||
node.Status = models.OnlineSt
|
||||
return
|
||||
}
|
||||
}
|
||||
// check extclient connection from metrics
|
||||
ingressMetrics, err := GetMetrics(node.StaticNode.IngressGatewayID)
|
||||
if err != nil || ingressMetrics == nil || ingressMetrics.Connectivity == nil {
|
||||
node.Status = models.UnKnown
|
||||
return
|
||||
}
|
||||
|
||||
if metric, ok := ingressMetrics.Connectivity[node.StaticNode.ClientID]; ok {
|
||||
if metric.Connected {
|
||||
node.Status = models.OnlineSt
|
||||
@@ -46,9 +63,14 @@ func GetNodeStatus(node *models.Node, defaultEnabledPolicy bool) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
node.Status = models.UnKnown
|
||||
return
|
||||
}
|
||||
if !node.Connected {
|
||||
node.Status = models.Disconnected
|
||||
return
|
||||
}
|
||||
if time.Since(node.LastCheckIn) > models.LastCheckInThreshold {
|
||||
node.Status = models.OfflineSt
|
||||
return
|
||||
@@ -197,6 +219,7 @@ func checkPeerConnectivity(node *models.Node, metrics *models.Metrics, defaultAc
|
||||
peerNotConnectedCnt++
|
||||
|
||||
}
|
||||
|
||||
if peerNotConnectedCnt > len(metrics.Connectivity)/2 {
|
||||
node.Status = models.WarningSt
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user