Skip to content

Commit b45d1f1

Browse files
authored
Merge pull request #3283 from gravitl/NET-1894
NET-1894: check peer status
2 parents 8d4b2d5 + 4b41e86 commit b45d1f1

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

pro/logic/status.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ func getNodeStatusOld(node *models.Node) {
2626

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

29-
if time.Since(node.LastCheckIn) > models.LastCheckInThreshold {
30-
node.Status = models.OfflineSt
31-
return
32-
}
3329
if node.IsStatic {
3430
if !node.StaticNode.Enabled {
3531
node.Status = models.OfflineSt
@@ -53,6 +49,10 @@ func GetNodeStatus(node *models.Node, defaultEnabledPolicy bool) {
5349
node.Status = models.UnKnown
5450
return
5551
}
52+
if time.Since(node.LastCheckIn) > models.LastCheckInThreshold {
53+
node.Status = models.OfflineSt
54+
return
55+
}
5656
host, err := logic.GetHost(node.HostID.String())
5757
if err != nil {
5858
node.Status = models.UnKnown
@@ -168,9 +168,12 @@ func checkPeerConnectivity(node *models.Node, metrics *models.Metrics, defaultAc
168168
if err != nil {
169169
continue
170170
}
171-
allowed, _ := logic.IsNodeAllowedToCommunicate(*node, peer, false)
172-
if !defaultAclPolicy && !allowed {
173-
continue
171+
172+
if !defaultAclPolicy {
173+
allowed, _ := logic.IsNodeAllowedToCommunicate(*node, peer, false)
174+
if !allowed {
175+
continue
176+
}
174177
}
175178

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

189192
}
190-
if peerNotConnectedCnt == 0 {
191-
node.Status = models.OnlineSt
193+
if peerNotConnectedCnt > len(metrics.Connectivity)/2 {
194+
node.Status = models.WarningSt
192195
return
193196
}
197+
194198
if peerNotConnectedCnt == len(metrics.Connectivity) {
195199
node.Status = models.ErrorSt
196200
return
197201
}
198-
node.Status = models.WarningSt
202+
203+
node.Status = models.OnlineSt
204+
199205
}

servercfg/serverconf.go

+15
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,21 @@ func GetMqUserName() string {
654654
return password
655655
}
656656

657+
// GetMetricInterval - get the publish metric interval
658+
func GetMetricIntervalInMinutes() time.Duration {
659+
//default 15 minutes
660+
mi := "15"
661+
if os.Getenv("PUBLISH_METRIC_INTERVAL") != "" {
662+
mi = os.Getenv("PUBLISH_METRIC_INTERVAL")
663+
}
664+
interval, err := strconv.Atoi(mi)
665+
if err != nil {
666+
interval = 15
667+
}
668+
669+
return time.Duration(interval) * time.Minute
670+
}
671+
657672
// GetMetricInterval - get the publish metric interval
658673
func GetMetricInterval() string {
659674
//default 15 minutes

0 commit comments

Comments
 (0)