You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2022/01/13 21:09:14 UTC

[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #6511: Updates the trafficcontrol-health-client with the following.

zrhoffman commented on a change in pull request #6511:
URL: https://github.com/apache/trafficcontrol/pull/6511#discussion_r784324618



##########
File path: tc-health-client/tmagent/tmagent.go
##########
@@ -472,27 +476,81 @@ func (c *ParentInfo) markParent(fqdn string, available bool) error {
 	if err != nil {
 		return errors.New("marking " + fqdn + " " + status + ": " + TrafficCtl + " error: " + err.Error())
 	}
+
+	return nil
+}
+
+// used to mark a parent as up or down in the trafficserver HostStatus
+// subsystem.
+//
+// TODO see issue #6448, add cacheStatus back when available in CrStates
+//func (c *ParentInfo) markParent(fqdn string, cacheStatus string, available bool) error {
+func (c *ParentInfo) markParent(fqdn string, available bool) error {
+	var hostAvailable bool
+	var err error
+	hostName := parseFqdn(fqdn)
+
+	log.Debugf("fqdn: %s, available: %v", fqdn, available)
+
 	pv, ok := c.Parents[hostName]
 	if ok {
-		switch reason {
-		case "active":
-			pv.ActiveReason = available
-		case "local":
-			pv.LocalReason = available
+		activeReason := pv.ActiveReason
+		localReason := pv.LocalReason
+		unavailablePollCount := pv.UnavailablePollCount
+
+		log.Debugf("hostName: %s, UnavailablePollCount: %d, available: %v", hostName, unavailablePollCount, available)
+
+		if !available { // unavailable
+			unavailablePollCount += 1
+			if unavailablePollCount < c.Cfg.UnavailablePollThreshold {
+				log.Infof("TM indicates %s is unavailable but the UnavailablePollThreshold has not been reached", hostName)
+				hostAvailable = true
+			} else {
+				// marking the host down
+				err = c.execTrafficCtl(fqdn, available)
+				if err != nil {
+					log.Errorln(err.Error())
+				}
+				if err == nil {
+					// TODO see issue 6448, add cacheStatus back when available in CrStates
+					// log.Infof("marked parent %s DOWN, cache status was: %s\n", hostName, cacheStatus)
+					hostAvailable = false
+					log.Infof("marked parent %s DOWN", hostName)
+				}
+			}
+		} else { // available
+			// marking the host up
+			err = c.execTrafficCtl(fqdn, available)
+			if err == nil {
+				hostAvailable = true
+				// reset the unavilable poll count
+				unavailablePollCount = 0
+				// TODO see issue #6448, add cacheStatus back when available in CrStates
+				//log.Infof("marked parent %s UP, cache status was: %s\n", hostName, cacheStatus)

Review comment:
       This commented line should be removed.

##########
File path: tc-health-client/tmagent/tmagent.go
##########
@@ -472,27 +476,81 @@ func (c *ParentInfo) markParent(fqdn string, available bool) error {
 	if err != nil {
 		return errors.New("marking " + fqdn + " " + status + ": " + TrafficCtl + " error: " + err.Error())
 	}
+
+	return nil
+}
+
+// used to mark a parent as up or down in the trafficserver HostStatus
+// subsystem.
+//
+// TODO see issue #6448, add cacheStatus back when available in CrStates
+//func (c *ParentInfo) markParent(fqdn string, cacheStatus string, available bool) error {
+func (c *ParentInfo) markParent(fqdn string, available bool) error {
+	var hostAvailable bool
+	var err error
+	hostName := parseFqdn(fqdn)
+
+	log.Debugf("fqdn: %s, available: %v", fqdn, available)
+
 	pv, ok := c.Parents[hostName]
 	if ok {
-		switch reason {
-		case "active":
-			pv.ActiveReason = available
-		case "local":
-			pv.LocalReason = available
+		activeReason := pv.ActiveReason
+		localReason := pv.LocalReason
+		unavailablePollCount := pv.UnavailablePollCount
+
+		log.Debugf("hostName: %s, UnavailablePollCount: %d, available: %v", hostName, unavailablePollCount, available)
+
+		if !available { // unavailable
+			unavailablePollCount += 1
+			if unavailablePollCount < c.Cfg.UnavailablePollThreshold {
+				log.Infof("TM indicates %s is unavailable but the UnavailablePollThreshold has not been reached", hostName)
+				hostAvailable = true
+			} else {
+				// marking the host down
+				err = c.execTrafficCtl(fqdn, available)
+				if err != nil {
+					log.Errorln(err.Error())
+				}
+				if err == nil {
+					// TODO see issue 6448, add cacheStatus back when available in CrStates
+					// log.Infof("marked parent %s DOWN, cache status was: %s\n", hostName, cacheStatus)

Review comment:
       This commented line should be removed.

##########
File path: tc-health-client/tmagent/tmagent.go
##########
@@ -472,27 +476,81 @@ func (c *ParentInfo) markParent(fqdn string, available bool) error {
 	if err != nil {
 		return errors.New("marking " + fqdn + " " + status + ": " + TrafficCtl + " error: " + err.Error())
 	}
+
+	return nil
+}
+
+// used to mark a parent as up or down in the trafficserver HostStatus
+// subsystem.
+//
+// TODO see issue #6448, add cacheStatus back when available in CrStates
+//func (c *ParentInfo) markParent(fqdn string, cacheStatus string, available bool) error {

Review comment:
       This commented line should be removed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org