You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ne...@apache.org on 2016/11/07 19:29:53 UTC

[07/21] incubator-trafficcontrol git commit: Fix TM2 to get poll intervals from TO

Fix TM2 to get poll intervals from TO


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/cc2eae51
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/cc2eae51
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/cc2eae51

Branch: refs/heads/master
Commit: cc2eae51d8bc669fae69cc5839e51c5b651869b3
Parents: 57b17e0
Author: Robert Butts <ro...@gmail.com>
Authored: Fri Oct 28 13:42:44 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 .../traffic_monitor/manager/monitorconfig.go    | 75 +++++++++++++++++++-
 1 file changed, 72 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/cc2eae51/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go b/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
index e3ba337..352f8e6 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
@@ -100,6 +100,70 @@ func trafficOpsHealthConnectionTimeoutToDuration(t int) time.Duration {
 	return time.Duration(t) * time.Millisecond
 }
 
+// trafficOpsPeerPollIntervalToDuration takes the int from Traffic Ops, which is in milliseconds, and returns a time.Duration
+// TODO change Traffic Ops Client API to a time.Duration
+func trafficOpsPeerPollIntervalToDuration(t int) time.Duration {
+	return time.Duration(t) * time.Millisecond
+}
+
+// trafficOpsStatPollIntervalToDuration takes the int from Traffic Ops, which is in milliseconds, and returns a time.Duration
+// TODO change Traffic Ops Client API to a time.Duration
+func trafficOpsStatPollIntervalToDuration(t int) time.Duration {
+	return time.Duration(t) * time.Millisecond
+}
+
+// trafficOpsHealthPollIntervalToDuration takes the int from Traffic Ops, which is in milliseconds, and returns a time.Duration
+// TODO change Traffic Ops Client API to a time.Duration
+func trafficOpsHealthPollIntervalToDuration(t int) time.Duration {
+	return time.Duration(t) * time.Millisecond
+}
+
+// getPollIntervals reads the Traffic Ops Client monitorConfig structure, and parses and returns the health, peer, and stat poll intervals
+func getHealthPeerStatPollIntervals(monitorConfig to.TrafficMonitorConfigMap) (time.Duration, time.Duration, time.Duration, error) {
+	healthPollIntervalI, healthPollIntervalExists := monitorConfig.Config["health.polling.interval"]
+	if !healthPollIntervalExists {
+		return 0, 0, 0, fmt.Errorf("Traffic Ops Monitor config missing 'health.polling.interval', not setting config changes.\n")
+	}
+	healthPollIntervalInt, healthPollIntervalIsInt := healthPollIntervalI.(float64)
+	if !healthPollIntervalIsInt {
+		return 0, 0, 0, fmt.Errorf("Traffic Ops Monitor config 'health.polling.interval' value '%v' type %T is not an integer, not setting config changes.\n", healthPollIntervalI, healthPollIntervalI)
+	}
+	healthPollInterval := trafficOpsHealthPollIntervalToDuration(int(healthPollIntervalInt))
+
+	peerPollIntervalI, peerPollIntervalExists := monitorConfig.Config["peers.polling.interval"]
+	if !peerPollIntervalExists {
+		return 0, 0, 0, fmt.Errorf("Traffic Ops Monitor config missing 'peers.polling.interval', not setting config changes.\n")
+	}
+	peerPollIntervalInt, peerPollIntervalIsInt := peerPollIntervalI.(float64)
+	if !peerPollIntervalIsInt {
+		return 0, 0, 0, fmt.Errorf("Traffic Ops Monitor config 'peers.polling.interval' value '%v' type %T is not an integer, not setting config changes.\n", peerPollIntervalI, peerPollIntervalI)
+	}
+	peerPollInterval := trafficOpsHealthPollIntervalToDuration(int(peerPollIntervalInt))
+
+	statPollIntervalI, statPollIntervalExists := monitorConfig.Config["stat.polling.interval"]
+	if !statPollIntervalExists {
+		log.Warnf("Traffic Ops Monitor config missing 'stat.polling.interval', using health for stat.\n")
+		statPollIntervalI = healthPollIntervalI
+	}
+	statPollIntervalInt, statPollIntervalIsInt := statPollIntervalI.(float64)
+	if !statPollIntervalIsInt {
+		log.Warnf("Traffic Ops Monitor config 'stat.polling.interval' value '%v' type %T is not an integer, using health for stat\n", statPollIntervalI, statPollIntervalI)
+		statPollIntervalI = healthPollIntervalI
+	}
+	statPollInterval := trafficOpsHealthPollIntervalToDuration(int(statPollIntervalInt))
+
+	// Formerly, only 'health' polling existed. If TO still has old configuration and doesn't have a 'stat' parameter, this allows us to assume the 'health' poll is slow, and sets it to the stat poll (which used to be the only poll, getting all astats data) to the given presumed-slow health poll, and set the now-fast-and-small health poll to a short fraction of that.
+	// TODO make config?
+	healthIsQuarterStatIfStatNotExist := true
+	if healthIsQuarterStatIfStatNotExist {
+		if healthPollIntervalExists && !statPollIntervalExists {
+			healthPollInterval = healthPollInterval / 4
+		}
+	}
+
+	return healthPollInterval, peerPollInterval, statPollInterval, nil
+}
+
 // TODO timing, and determine if the case, or its internal `for`, should be put in a goroutine
 // TODO determine if subscribers take action on change, and change to mutexed objects if not.
 func monitorConfigListen(
@@ -120,6 +184,11 @@ func monitorConfigListen(
 		peerUrls := map[string]poller.PollConfig{}
 		caches := map[string]string{}
 
+		healthPollInterval, peerPollInterval, statPollInterval, err := getHealthPeerStatPollIntervals(monitorConfig)
+		if err != nil {
+			continue
+		}
+
 		for _, srv := range monitorConfig.TrafficServer {
 			caches[srv.HostName] = srv.Status
 
@@ -165,9 +234,9 @@ func monitorConfigListen(
 			peerUrls[srv.HostName] = poller.PollConfig{URL: url} // TODO determine timeout.
 		}
 
-		statURLSubscriber <- poller.HttpPollerConfig{Urls: statUrls, Interval: cfg.CacheStatPollingInterval}
-		healthURLSubscriber <- poller.HttpPollerConfig{Urls: healthUrls, Interval: cfg.CacheHealthPollingInterval}
-		peerURLSubscriber <- poller.HttpPollerConfig{Urls: peerUrls, Interval: cfg.PeerPollingInterval}
+		statURLSubscriber <- poller.HttpPollerConfig{Urls: statUrls, Interval: statPollInterval}
+		healthURLSubscriber <- poller.HttpPollerConfig{Urls: healthUrls, Interval: healthPollInterval}
+		peerURLSubscriber <- poller.HttpPollerConfig{Urls: peerUrls, Interval: peerPollInterval}
 
 		for cacheName := range localStates.GetCaches() {
 			if _, exists := monitorConfig.TrafficServer[string(cacheName)]; !exists {