rawlinp commented on a change in pull request #6527:
URL: https://github.com/apache/trafficcontrol/pull/6527#discussion_r804123740
##########
File path: traffic_monitor/manager/monitorconfig.go
##########
@@ -337,6 +379,103 @@ func monitorConfigListen(
}
}
+// getCacheGroupsToPoll returns the name of this Traffic Monitor's cache group
+// 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) {
+ tmGroupSet := make(map[string]tc.TMCacheGroup)
+ cacheGroupSet := make(map[string]tc.TMCacheGroup)
+ tmGroupToPolledCacheGroups :=
make(map[string]map[string]tc.TMCacheGroup)
+ thisTMGroup := ""
+
+ for _, tm := range monitors {
+ if tm.HostName == hostname {
+ thisTMGroup = tm.Location
+ }
+ if tc.CacheStatusFromString(tm.ServerStatus) ==
tc.CacheStatusOnline {
+ 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)
+ if status == tc.CacheStatusOnline || status ==
tc.CacheStatusReported || status == tc.CacheStatusAdminDown {
+ cacheGroupSet[c.CacheGroup] =
allCacheGroups[c.CacheGroup]
+ }
+ }
+
+ if !distributedPolling {
+ return thisTMGroup, cacheGroupSet, nil
+ }
+
+ tmGroups := make([]string, 0, len(tmGroupSet))
+ for tg := range tmGroupSet {
+ tmGroups = append(tmGroups, tg)
+ }
+ sort.Strings(tmGroups)
+ cgs := make([]string, 0, len(cacheGroupSet))
+ for cg := range cacheGroupSet {
+ cgs = append(cgs, cg)
+ }
+ sort.Strings(cgs)
Review comment:
Yes, for determinism. Map iteration isn't sorted, so we need to sort the
keys and iterate over them instead. Otherwise, order wouldn't be guaranteed,
and TMs wouldn't all agree on which cachegroups they're supposed to poll.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]