Skip to content

Commit

Permalink
Merge pull request #3283 from gravitl/NET-1894
Browse files Browse the repository at this point in the history
NET-1894: check peer status
  • Loading branch information
abhishek9686 authored Jan 9, 2025
2 parents 8d4b2d5 + 4b41e86 commit b45d1f1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
28 changes: 17 additions & 11 deletions pro/logic/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ func getNodeStatusOld(node *models.Node) {

func GetNodeStatus(node *models.Node, defaultEnabledPolicy bool) {

if time.Since(node.LastCheckIn) > models.LastCheckInThreshold {
node.Status = models.OfflineSt
return
}
if node.IsStatic {
if !node.StaticNode.Enabled {
node.Status = models.OfflineSt
Expand All @@ -53,6 +49,10 @@ func GetNodeStatus(node *models.Node, defaultEnabledPolicy bool) {
node.Status = models.UnKnown
return
}
if time.Since(node.LastCheckIn) > models.LastCheckInThreshold {
node.Status = models.OfflineSt
return
}
host, err := logic.GetHost(node.HostID.String())
if err != nil {
node.Status = models.UnKnown
Expand Down Expand Up @@ -168,9 +168,12 @@ func checkPeerConnectivity(node *models.Node, metrics *models.Metrics, defaultAc
if err != nil {
continue
}
allowed, _ := logic.IsNodeAllowedToCommunicate(*node, peer, false)
if !defaultAclPolicy && !allowed {
continue

if !defaultAclPolicy {
allowed, _ := logic.IsNodeAllowedToCommunicate(*node, peer, false)
if !allowed {
continue
}
}

if time.Since(peer.LastCheckIn) > models.LastCheckInThreshold {
Expand All @@ -181,19 +184,22 @@ func checkPeerConnectivity(node *models.Node, metrics *models.Metrics, defaultAc
}
// check if peer is in error state
checkPeerStatus(&peer, defaultAclPolicy)
if peer.Status == models.ErrorSt {
if peer.Status == models.ErrorSt || peer.Status == models.WarningSt {
continue
}
peerNotConnectedCnt++

}
if peerNotConnectedCnt == 0 {
node.Status = models.OnlineSt
if peerNotConnectedCnt > len(metrics.Connectivity)/2 {
node.Status = models.WarningSt
return
}

if peerNotConnectedCnt == len(metrics.Connectivity) {
node.Status = models.ErrorSt
return
}
node.Status = models.WarningSt

node.Status = models.OnlineSt

}
15 changes: 15 additions & 0 deletions servercfg/serverconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,21 @@ func GetMqUserName() string {
return password
}

// GetMetricInterval - get the publish metric interval
func GetMetricIntervalInMinutes() time.Duration {
//default 15 minutes
mi := "15"
if os.Getenv("PUBLISH_METRIC_INTERVAL") != "" {
mi = os.Getenv("PUBLISH_METRIC_INTERVAL")
}
interval, err := strconv.Atoi(mi)
if err != nil {
interval = 15
}

return time.Duration(interval) * time.Minute
}

// GetMetricInterval - get the publish metric interval
func GetMetricInterval() string {
//default 15 minutes
Expand Down

0 comments on commit b45d1f1

Please sign in to comment.