You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ma...@apache.org on 2022/02/25 17:55:59 UTC

[trafficcontrol] branch master updated: TMs peer with other TMs of the same status, not just ONLINE (#6581)

This is an automated email from the ASF dual-hosted git repository.

mattjackson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 6cfee92  TMs peer with other TMs of the same status, not just ONLINE (#6581)
6cfee92 is described below

commit 6cfee92e1e6a4a88ac91e9d41ccb434adaa73db6
Author: Rawlin Peters <ra...@apache.org>
AuthorDate: Fri Feb 25 10:55:48 2022 -0700

    TMs peer with other TMs of the same status, not just ONLINE (#6581)
    
    Instead of every TM peering with every other ONLINE TM, make TMs peer
    with other TMs of the same status. I.e. ONLINE TMs will peer with other
    ONLINE TMs (like normal), but OFFLINE TMs will peer with other OFFLINE
    TMs (instead of peering w/ ONLINE TMs). The same goes for TMs of any
    other status.
---
 CHANGELOG.md                                  |  1 +
 traffic_monitor/manager/monitorconfig.go      | 32 +++++++++++++++++----------
 traffic_monitor/manager/monitorconfig_test.go |  5 ++++-
 3 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index bbe69a5..2e006dc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 
 ### Changed
 - Added Rocky Linux 8 support
+- Traffic Monitors now peer with other Traffic Monitors of the same status (e.g. ONLINE with ONLINE, OFFLINE with OFFLINE), instead of all peering with ONLINE.
 - Added permissions to the role form in traffic portal
 
 ## [6.1.0] - 2022-01-18
diff --git a/traffic_monitor/manager/monitorconfig.go b/traffic_monitor/manager/monitorconfig.go
index 29d82e9..c2103de 100644
--- a/traffic_monitor/manager/monitorconfig.go
+++ b/traffic_monitor/manager/monitorconfig.go
@@ -240,7 +240,7 @@ func monitorConfigListen(
 			continue
 		}
 
-		thisTMGroup, cacheGroupsToPoll, err := getCacheGroupsToPoll(
+		thisTMGroup, thisTMStatus, cacheGroupsToPoll, err := getCacheGroupsToPoll(
 			cfg.DistributedPolling,
 			staticAppData.Hostname,
 			monitorConfig.TrafficMonitor,
@@ -309,7 +309,7 @@ func monitorConfigListen(
 		peerSet := map[tc.TrafficMonitorName]struct{}{}
 		tmsByGroup := make(map[string][]tc.TrafficMonitor)
 		for _, srv := range monitorConfig.TrafficMonitor {
-			if tc.CacheStatusFromString(srv.ServerStatus) != tc.CacheStatusOnline {
+			if srv.ServerStatus != thisTMStatus {
 				continue
 			}
 			tmsByGroup[srv.Location] = append(tmsByGroup[srv.Location], srv)
@@ -319,7 +319,7 @@ func monitorConfigListen(
 			if srv.HostName == staticAppData.Hostname || (cfg.DistributedPolling && srv.Location != thisTMGroup) {
 				continue
 			}
-			if tc.CacheStatusFromString(srv.ServerStatus) != tc.CacheStatusOnline {
+			if srv.ServerStatus != thisTMStatus {
 				continue
 			}
 			// TODO: the URL should be config driven. -jse
@@ -379,29 +379,37 @@ func monitorConfigListen(
 	}
 }
 
-// getCacheGroupsToPoll returns the name of this Traffic Monitor's cache group
-// and the set of cache groups it needs to poll.
+// getCacheGroupsToPoll returns the name of this Traffic Monitor's cache group,
+// the status of this Traffic Monitor, and the set of cache groups it needs to poll.
 func getCacheGroupsToPoll(distributedPolling bool, hostname string, monitors map[string]tc.TrafficMonitor,
-	caches map[string]tc.TrafficServer, allCacheGroups map[string]tc.TMCacheGroup) (string, map[string]tc.TMCacheGroup, error) {
+	caches map[string]tc.TrafficServer, allCacheGroups map[string]tc.TMCacheGroup) (string, string, map[string]tc.TMCacheGroup, error) {
 	tmGroupSet := make(map[string]tc.TMCacheGroup)
 	cacheGroupSet := make(map[string]tc.TMCacheGroup)
 	tmGroupToPolledCacheGroups := make(map[string]map[string]tc.TMCacheGroup)
 	thisTMGroup := ""
+	thisTMStatus := ""
 
 	for _, tm := range monitors {
 		if tm.HostName == hostname {
+			thisTMStatus = tm.ServerStatus
 			thisTMGroup = tm.Location
+			break
 		}
-		if tc.CacheStatusFromString(tm.ServerStatus) == tc.CacheStatusOnline {
+	}
+	if thisTMStatus == "" {
+		return "", "", nil, fmt.Errorf("unable to find status for this Traffic Monitor (%s) in monitoring config snapshot", hostname)
+	}
+	if thisTMGroup == "" {
+		return "", "", nil, fmt.Errorf("unable to find cache group for this Traffic Monitor (%s) in monitoring config snapshot", hostname)
+	}
+	for _, tm := range monitors {
+		if tm.ServerStatus == thisTMStatus {
 			tmGroupSet[tm.Location] = allCacheGroups[tm.Location]
 			if _, ok := tmGroupToPolledCacheGroups[tm.Location]; !ok {
 				tmGroupToPolledCacheGroups[tm.Location] = make(map[string]tc.TMCacheGroup)
 			}
 		}
 	}
-	if thisTMGroup == "" {
-		return "", nil, fmt.Errorf("unable to find cache group for this Traffic Monitor (%s) in monitoring config snapshot", hostname)
-	}
 
 	for _, c := range caches {
 		status := tc.CacheStatusFromString(c.ServerStatus)
@@ -411,7 +419,7 @@ func getCacheGroupsToPoll(distributedPolling bool, hostname string, monitors map
 	}
 
 	if !distributedPolling {
-		return thisTMGroup, cacheGroupSet, nil
+		return thisTMGroup, thisTMStatus, cacheGroupSet, nil
 	}
 
 	tmGroups := make([]string, 0, len(tmGroupSet))
@@ -431,7 +439,7 @@ func getCacheGroupsToPoll(distributedPolling bool, hostname string, monitors map
 		closest, cgs = findAndRemoveClosestCachegroup(cgs, allCacheGroups[tmGroup], allCacheGroups)
 		tmGroupToPolledCacheGroups[tmGroup][closest] = allCacheGroups[closest]
 	}
-	return thisTMGroup, tmGroupToPolledCacheGroups[thisTMGroup], nil
+	return thisTMGroup, thisTMStatus, tmGroupToPolledCacheGroups[thisTMGroup], nil
 }
 
 func findAndRemoveClosestCachegroup(remainingCacheGroups []string, target tc.TMCacheGroup, allCacheGroups map[string]tc.TMCacheGroup) (string, []string) {
diff --git a/traffic_monitor/manager/monitorconfig_test.go b/traffic_monitor/manager/monitorconfig_test.go
index 2ad9803..50e95fd 100644
--- a/traffic_monitor/manager/monitorconfig_test.go
+++ b/traffic_monitor/manager/monitorconfig_test.go
@@ -392,13 +392,16 @@ func TestGetCacheGroupsToPoll(t *testing.T) {
 			ExpectErr: false,
 		},
 	} {
-		tmGroup, toPoll, err := getCacheGroupsToPoll(tc.DistributedPolling, tc.TMName, monitors, caches, cacheGroups)
+		tmGroup, tmStatus, toPoll, err := getCacheGroupsToPoll(tc.DistributedPolling, tc.TMName, monitors, caches, cacheGroups)
 		if tc.ExpectErr != (err != nil) {
 			t.Errorf("getting cachegroups to poll -- expect error: %t, actual error: %v", tc.ExpectErr, err)
 		}
 		if tc.ExpectedTMGroup != tmGroup {
 			t.Errorf("getting TM group -- expected: %s, actual: %s", tc.ExpectedTMGroup, tmGroup)
 		}
+		if tmStatus != "ONLINE" {
+			t.Errorf("expected TM status: ONLINE, actual: %s", tmStatus)
+		}
 		if !reflect.DeepEqual(tc.ExpectedToPoll, toPoll) {
 			t.Errorf("getting cachegroups to poll -- expected: %+v, actual: %+v", tc.ExpectedToPoll, toPoll)
 		}