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 2017/03/02 03:39:44 UTC

[5/7] incubator-trafficcontrol git commit: Fix TM2 global variable to be a safe local

Fix TM2 global variable to be a safe local

This wasn't technically a thread safety issue, because the integer was
only ever checked as a boolean. But it's a dangerous precedent, as in
most cases this design pattern would be unsafe. Changing it to a local
variable, and making the function 'pure', is generally safer, easier
to understand, and doesn't give anyone the idea that pattern is okay.


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

Branch: refs/heads/master
Commit: fc667c8c0ff4b1a34327cc28b5f0e3f6544dc786
Parents: 391dc6f
Author: Robert Butts <ro...@gmail.com>
Authored: Mon Feb 27 16:14:37 2017 -0700
Committer: David Neuman <da...@gmail.com>
Committed: Wed Mar 1 20:39:10 2017 -0700

----------------------------------------------------------------------
 .../traffic_monitor/manager/monitorconfig.go          | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/fc667c8c/traffic_monitor_golang/traffic_monitor/manager/monitorconfig.go
----------------------------------------------------------------------
diff --git a/traffic_monitor_golang/traffic_monitor/manager/monitorconfig.go b/traffic_monitor_golang/traffic_monitor/manager/monitorconfig.go
index f8e2f87..6d5748a 100644
--- a/traffic_monitor_golang/traffic_monitor/manager/monitorconfig.go
+++ b/traffic_monitor_golang/traffic_monitor/manager/monitorconfig.go
@@ -138,13 +138,11 @@ func trafficOpsHealthPollIntervalToDuration(t int) time.Duration {
 	return time.Duration(t) * time.Millisecond
 }
 
-var healthPollCount int
-
 // PollIntervalRatio is the ratio of the configuration interval to poll. The configured intervals are 'target' times, so we actually poll at some small fraction less, in attempt to make the actual poll marginally less than the target.
 const PollIntervalRatio = float64(0.97) // TODO make config?
 
 // getPollIntervals reads the Traffic Ops Client monitorConfig structure, and parses and returns the health, peer, and stat poll intervals
-func getHealthPeerStatPollIntervals(monitorConfig to.TrafficMonitorConfigMap, cfg config.Config) (time.Duration, time.Duration, time.Duration, error) {
+func getHealthPeerStatPollIntervals(monitorConfig to.TrafficMonitorConfigMap, cfg config.Config, logMissingHeartbeatParam bool) (time.Duration, time.Duration, time.Duration, error) {
 	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")
@@ -168,9 +166,8 @@ func getHealthPeerStatPollIntervals(monitorConfig to.TrafficMonitorConfigMap, cf
 	healthPollIntervalI, healthPollIntervalExists := monitorConfig.Config["heartbeat.polling.interval"]
 	healthPollIntervalInt, healthPollIntervalIsInt := healthPollIntervalI.(float64)
 	if !healthPollIntervalExists {
-		if healthPollCount == 0 { //only log this once
+		if logMissingHeartbeatParam {
 			log.Warnln("Traffic Ops Monitor config missing 'heartbeat.polling.interval', using health for heartbeat.")
-			healthPollCount++
 		}
 		healthPollIntervalInt = statPollIntervalInt
 	} else if !healthPollIntervalIsInt {
@@ -206,6 +203,9 @@ func monitorConfigListen(
 		}
 		os.Exit(1) // The Monitor can't run without a MonitorConfigManager
 	}()
+
+	logMissingHeartbeatParam := true
+
 	for monitorConfig := range monitorConfigPollChan {
 		monitorConfigTS.Set(monitorConfig)
 		healthURLs := map[string]poller.PollConfig{}
@@ -213,7 +213,9 @@ func monitorConfigListen(
 		peerURLs := map[string]poller.PollConfig{}
 		caches := map[string]string{}
 
-		healthPollInterval, peerPollInterval, statPollInterval, err := getHealthPeerStatPollIntervals(monitorConfig, cfg)
+		healthPollInterval, peerPollInterval, statPollInterval, err := getHealthPeerStatPollIntervals(monitorConfig, cfg, logMissingHeartbeatParam)
+		logMissingHeartbeatParam = false // only log the heartbeat parameter missing once
+
 		if err != nil {
 			log.Errorf("monitor config error getting polling intervals, can't poll: %v", err)
 			continue