mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-13 00:24:31 +08:00
NET-1920: Add disconnected node status (#3300)
* create peer ack table * add restricted status * add disconnected status
This commit is contained in:
parent
a899544104
commit
c02ec193db
4 changed files with 36 additions and 5 deletions
|
@ -71,6 +71,8 @@ const (
|
||||||
USER_INVITES_TABLE_NAME = "user_invites"
|
USER_INVITES_TABLE_NAME = "user_invites"
|
||||||
// TAG_TABLE_NAME - table for tags
|
// TAG_TABLE_NAME - table for tags
|
||||||
TAG_TABLE_NAME = "tags"
|
TAG_TABLE_NAME = "tags"
|
||||||
|
// PEER_ACK_TABLE - table for failover peer ack
|
||||||
|
PEER_ACK_TABLE = "peer_ack"
|
||||||
// == ERROR CONSTS ==
|
// == ERROR CONSTS ==
|
||||||
// NO_RECORD - no singular result found
|
// NO_RECORD - no singular result found
|
||||||
NO_RECORD = "no result found"
|
NO_RECORD = "no result found"
|
||||||
|
@ -158,6 +160,7 @@ func createTables() {
|
||||||
CreateTable(USER_INVITES_TABLE_NAME)
|
CreateTable(USER_INVITES_TABLE_NAME)
|
||||||
CreateTable(TAG_TABLE_NAME)
|
CreateTable(TAG_TABLE_NAME)
|
||||||
CreateTable(ACLS_TABLE_NAME)
|
CreateTable(ACLS_TABLE_NAME)
|
||||||
|
CreateTable(PEER_ACK_TABLE)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateTable(tableName string) error {
|
func CreateTable(tableName string) error {
|
||||||
|
|
|
@ -18,6 +18,10 @@ func getNodeStatus(node *models.Node, t bool) {
|
||||||
node.Status = models.OnlineSt
|
node.Status = models.OnlineSt
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !node.Connected {
|
||||||
|
node.Status = models.Disconnected
|
||||||
|
return
|
||||||
|
}
|
||||||
if time.Since(node.LastCheckIn) > time.Minute*10 {
|
if time.Since(node.LastCheckIn) > time.Minute*10 {
|
||||||
node.Status = models.OfflineSt
|
node.Status = models.OfflineSt
|
||||||
return
|
return
|
||||||
|
|
|
@ -14,11 +14,12 @@ import (
|
||||||
type NodeStatus string
|
type NodeStatus string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
OnlineSt NodeStatus = "online"
|
OnlineSt NodeStatus = "online"
|
||||||
OfflineSt NodeStatus = "offline"
|
OfflineSt NodeStatus = "offline"
|
||||||
WarningSt NodeStatus = "warning"
|
WarningSt NodeStatus = "warning"
|
||||||
ErrorSt NodeStatus = "error"
|
ErrorSt NodeStatus = "error"
|
||||||
UnKnown NodeStatus = "unknown"
|
UnKnown NodeStatus = "unknown"
|
||||||
|
Disconnected NodeStatus = "disconnected"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LastCheckInThreshold - if node's checkin more than this threshold,then node is declared as offline
|
// 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
|
node.Status = models.OnlineSt
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !node.Connected {
|
||||||
|
node.Status = models.Disconnected
|
||||||
|
return
|
||||||
|
}
|
||||||
if time.Since(node.LastCheckIn) > time.Minute*10 {
|
if time.Since(node.LastCheckIn) > time.Minute*10 {
|
||||||
node.Status = models.OfflineSt
|
node.Status = models.OfflineSt
|
||||||
return
|
return
|
||||||
|
@ -31,12 +35,25 @@ func GetNodeStatus(node *models.Node, defaultEnabledPolicy bool) {
|
||||||
node.Status = models.OfflineSt
|
node.Status = models.OfflineSt
|
||||||
return
|
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
|
// check extclient connection from metrics
|
||||||
ingressMetrics, err := GetMetrics(node.StaticNode.IngressGatewayID)
|
ingressMetrics, err := GetMetrics(node.StaticNode.IngressGatewayID)
|
||||||
if err != nil || ingressMetrics == nil || ingressMetrics.Connectivity == nil {
|
if err != nil || ingressMetrics == nil || ingressMetrics.Connectivity == nil {
|
||||||
node.Status = models.UnKnown
|
node.Status = models.UnKnown
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if metric, ok := ingressMetrics.Connectivity[node.StaticNode.ClientID]; ok {
|
if metric, ok := ingressMetrics.Connectivity[node.StaticNode.ClientID]; ok {
|
||||||
if metric.Connected {
|
if metric.Connected {
|
||||||
node.Status = models.OnlineSt
|
node.Status = models.OnlineSt
|
||||||
|
@ -46,9 +63,14 @@ func GetNodeStatus(node *models.Node, defaultEnabledPolicy bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
node.Status = models.UnKnown
|
node.Status = models.UnKnown
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !node.Connected {
|
||||||
|
node.Status = models.Disconnected
|
||||||
|
return
|
||||||
|
}
|
||||||
if time.Since(node.LastCheckIn) > models.LastCheckInThreshold {
|
if time.Since(node.LastCheckIn) > models.LastCheckInThreshold {
|
||||||
node.Status = models.OfflineSt
|
node.Status = models.OfflineSt
|
||||||
return
|
return
|
||||||
|
@ -197,6 +219,7 @@ func checkPeerConnectivity(node *models.Node, metrics *models.Metrics, defaultAc
|
||||||
peerNotConnectedCnt++
|
peerNotConnectedCnt++
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if peerNotConnectedCnt > len(metrics.Connectivity)/2 {
|
if peerNotConnectedCnt > len(metrics.Connectivity)/2 {
|
||||||
node.Status = models.WarningSt
|
node.Status = models.WarningSt
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Reference in a new issue