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:47 UTC

[01/21] incubator-trafficcontrol git commit: Fix TM2 monitorconfig 'Url' to idiomatic 'URL'

Repository: incubator-trafficcontrol
Updated Branches:
  refs/heads/master 31a17aa5d -> 7e34e01de


Fix TM2 monitorconfig 'Url' to idiomatic 'URL'


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

Branch: refs/heads/master
Commit: 5edd95c208844962389c9afc394a6a6a2acf9204
Parents: 0bf2afd
Author: Robert Butts <ro...@gmail.com>
Authored: Thu Nov 3 14:27:43 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 .../traffic_monitor/manager/monitorconfig.go    | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5edd95c2/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 0a7c657..58d5ab7 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
@@ -175,9 +175,9 @@ func monitorConfigListen(
 ) {
 	for monitorConfig := range monitorConfigPollChan {
 		monitorConfigTS.Set(monitorConfig)
-		healthUrls := map[string]poller.PollConfig{}
-		statUrls := map[string]poller.PollConfig{}
-		peerUrls := map[string]poller.PollConfig{}
+		healthURLs := map[string]poller.PollConfig{}
+		statURLs := map[string]poller.PollConfig{}
+		peerURLs := map[string]poller.PollConfig{}
 		caches := map[string]string{}
 
 		healthPollInterval, peerPollInterval, statPollInterval, err := getHealthPeerStatPollIntervals(monitorConfig, cfg)
@@ -213,10 +213,10 @@ func monitorConfigListen(
 			url = r.Replace(url)
 
 			connTimeout := trafficOpsHealthConnectionTimeoutToDuration(monitorConfig.Profile[srv.Profile].Parameters.HealthConnectionTimeout)
-			healthUrls[srv.HostName] = poller.PollConfig{URL: url, Timeout: connTimeout}
+			healthURLs[srv.HostName] = poller.PollConfig{URL: url, Timeout: connTimeout}
 			r = strings.NewReplacer("application=plugin.remap", "application=")
-			statUrl := r.Replace(url)
-			statUrls[srv.HostName] = poller.PollConfig{URL: statUrl, Timeout: connTimeout}
+			statURL := r.Replace(url)
+			statURLs[srv.HostName] = poller.PollConfig{URL: statURL, Timeout: connTimeout}
 		}
 
 		for _, srv := range monitorConfig.TrafficMonitor {
@@ -228,12 +228,12 @@ func monitorConfigListen(
 			}
 			// TODO: the URL should be config driven. -jse
 			url := fmt.Sprintf("http://%s:%d/publish/CrStates?raw", srv.IP, srv.Port)
-			peerUrls[srv.HostName] = poller.PollConfig{URL: url} // TODO determine timeout.
+			peerURLs[srv.HostName] = poller.PollConfig{URL: url} // TODO determine timeout.
 		}
 
-		statURLSubscriber <- poller.HttpPollerConfig{Urls: statUrls, Interval: statPollInterval}
-		healthURLSubscriber <- poller.HttpPollerConfig{Urls: healthUrls, Interval: healthPollInterval}
-		peerURLSubscriber <- poller.HttpPollerConfig{Urls: peerUrls, Interval: peerPollInterval}
+		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 {


[02/21] incubator-trafficcontrol git commit: Fix TM2 cache.Result to optimize struct size

Posted by ne...@apache.org.
Fix TM2 cache.Result to optimize struct size


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

Branch: refs/heads/master
Commit: 0bf2afd9102dc8ae3c7c2d8742031d10447bf1b7
Parents: 7401f7c
Author: Robert Butts <ro...@gmail.com>
Authored: Thu Nov 3 14:23:16 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 .../experimental/traffic_monitor/cache/cache.go     | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0bf2afd9/traffic_monitor/experimental/traffic_monitor/cache/cache.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/cache/cache.go b/traffic_monitor/experimental/traffic_monitor/cache/cache.go
index f282976..7f04e34 100644
--- a/traffic_monitor/experimental/traffic_monitor/cache/cache.go
+++ b/traffic_monitor/experimental/traffic_monitor/cache/cache.go
@@ -53,16 +53,16 @@ type PrecomputedData struct {
 
 // Result is the data result returned by a cache.
 type Result struct {
-	ID          enum.CacheName
-	Available   bool
-	Error       error
-	Astats      Astats
-	Time        time.Time
-	RequestTime time.Duration
-	Vitals      Vitals
-	PrecomputedData
+	ID           enum.CacheName
+	Error        error
+	Astats       Astats
+	Time         time.Time
+	RequestTime  time.Duration
+	Vitals       Vitals
 	PollID       uint64
 	PollFinished chan<- uint64
+	PrecomputedData
+	Available bool
 }
 
 // Vitals is the vitals data returned from a cache.


[09/21] incubator-trafficcontrol git commit: Fix TM2 down caches to exclude admin_down, offline

Posted by ne...@apache.org.
Fix TM2 down caches to exclude admin_down, offline


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

Branch: refs/heads/master
Commit: 10129f3fed1a1597ab206528bc7eb673166ffcb5
Parents: b29a5d5
Author: Robert Butts <ro...@gmail.com>
Authored: Mon Oct 31 16:08:42 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 .../experimental/traffic_monitor/enum/enum.go   | 51 ++++++++++++++++++++
 .../traffic_monitor/health/cache_health.go      | 19 +++++---
 .../traffic_monitor/manager/datarequest.go      | 21 ++++++--
 .../traffic_monitor/manager/manager.go          |  1 +
 .../traffic_monitor/manager/opsconfig.go        |  2 +
 5 files changed, 84 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/10129f3f/traffic_monitor/experimental/traffic_monitor/enum/enum.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/enum/enum.go b/traffic_monitor/experimental/traffic_monitor/enum/enum.go
index e028a74..c8389b9 100644
--- a/traffic_monitor/experimental/traffic_monitor/enum/enum.go
+++ b/traffic_monitor/experimental/traffic_monitor/enum/enum.go
@@ -91,3 +91,54 @@ func DSTypeFromString(s string) DSType {
 		return DSTypeInvalid
 	}
 }
+
+// CacheStatus represents the Traffic Server status set in Traffic Ops (online, offline, admin_down, reported). The string values of this type should match the Traffic Ops values.
+type CacheStatus string
+
+const (
+	// CacheStatusAdminDown represents a cache which has been administratively marked as down, but which should still appear in the CDN (Traffic Server, Traffic Monitor, Traffic Router).
+	CacheStatusAdminDown = CacheStatus("ADMIN_DOWN")
+	// CacheStatusOnline represents a cache which has been marked as Online in Traffic Ops, irrespective of monitoring. Traffic Monitor will always flag these caches as available.
+	CacheStatusOnline = CacheStatus("ONLINE")
+	// CacheStatusOffline represents a cache which has been marked as Offline in Traffic Ops. These caches will not be returned in any endpoint, and Traffic Monitor acts like they don't exist.
+	CacheStatusOffline = CacheStatus("OFFLINE")
+	// CacheStatusReported represents a cache which has been marked as Reported in Traffic Ops. These caches are polled for health and returned in endpoints as available or unavailable based on bandwidth, response time, and other factors. The vast majority of caches should be Reported.
+	CacheStatusReported = CacheStatus("REPORTED")
+	// CacheStatusInvalid represents an invalid status enumeration.
+	CacheStatusInvalid = CacheStatus("")
+)
+
+// String returns a string representation of this cache status
+func (t CacheStatus) String() string {
+	switch t {
+	case CacheStatusAdminDown:
+		fallthrough
+	case CacheStatusOnline:
+		fallthrough
+	case CacheStatusOffline:
+		fallthrough
+	case CacheStatusReported:
+		return string(t)
+	default:
+		return "INVALID"
+	}
+}
+
+// CacheStatusFromString returns a CacheStatus from its string representation, or CacheStatusInvalid if the string is not a valid type.
+func CacheStatusFromString(s string) CacheStatus {
+	s = strings.ToLower(s)
+	switch s {
+	case "admin_down":
+		fallthrough
+	case "admindown":
+		return CacheStatusAdminDown
+	case "offline":
+		return CacheStatusOffline
+	case "online":
+		return CacheStatusOnline
+	case "reported":
+		return CacheStatusReported
+	default:
+		return CacheStatusInvalid
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/10129f3f/traffic_monitor/experimental/traffic_monitor/health/cache_health.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/health/cache_health.go b/traffic_monitor/experimental/traffic_monitor/health/cache_health.go
index d4c7639..63cff4f 100644
--- a/traffic_monitor/experimental/traffic_monitor/health/cache_health.go
+++ b/traffic_monitor/experimental/traffic_monitor/health/cache_health.go
@@ -9,6 +9,7 @@ import (
 
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/common/log"
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/cache"
+	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/enum"
 	traffic_ops "github.com/apache/incubator-trafficcontrol/traffic_ops/client"
 )
 
@@ -106,15 +107,19 @@ func cacheCapacityKbps(result cache.Result) int64 {
 // EvalCache returns whether the given cache should be marked available, and a string describing why
 func EvalCache(result cache.Result, mc *traffic_ops.TrafficMonitorConfigMap) (bool, string) {
 	toServer := mc.TrafficServer[string(result.ID)]
-	status := toServer.Status
+	status := enum.CacheStatusFromString(toServer.Status)
+	if status == enum.CacheStatusInvalid {
+		log.Errorf("Cache %v got invalid status from Traffic Ops '%v' - treating as Reported\n", result.ID, toServer.Status)
+	}
 	params := mc.Profile[toServer.Profile].Parameters
 	switch {
-	case status == "ADMIN_DOWN":
-		return false, "set to ADMIN_DOWN"
-	case status == "OFFLINE":
-		return false, "set to OFFLINE"
-	case status == "ONLINE":
-		return true, "set to ONLINE"
+	case status == enum.CacheStatusAdminDown:
+		return false, "set to " + status.String()
+	case status == enum.CacheStatusOffline:
+		log.Errorf("Cache %v set to offline, but still polled\n", result.ID)
+		return false, "set to " + status.String()
+	case status == enum.CacheStatusOnline:
+		return true, "set to " + status.String()
 	case result.Error != nil:
 		return false, fmt.Sprintf("error: %v", result.Error)
 	case result.Vitals.LoadAvg > params.HealthThresholdLoadAvg:

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/10129f3f/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go b/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
index ccb7447..735c222 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
@@ -20,6 +20,7 @@ import (
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/srvhttp"
 	todata "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/trafficopsdata"
 	towrap "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/trafficopswrapper"
+	to "github.com/apache/incubator-trafficcontrol/traffic_ops/client"
 )
 
 // JSONEvents represents the structure we wish to serialize to JSON, for Events.
@@ -432,6 +433,7 @@ func DataRequest(
 	localCacheStatus CacheAvailableStatusThreadsafe,
 	lastStats LastStatsThreadsafe,
 	unpolledCaches UnpolledCachesThreadsafe,
+	monitorConfig TrafficMonitorConfigMapThreadsafe,
 ) (body []byte, responseCode int) {
 
 	// handleErr takes an error, and the request type it came from, and logs. It is ok to call with a nil error, in which case this is a no-op.
@@ -520,7 +522,7 @@ func DataRequest(
 	case srvhttp.APICacheAvailableCount:
 		return []byte(strconv.Itoa(cacheAvailableCount(localStates.Get().Caches))), http.StatusOK
 	case srvhttp.APICacheDownCount:
-		return []byte(strconv.Itoa(cacheDownCount(localStates.Get().Caches))), http.StatusOK
+		return []byte(strconv.Itoa(cacheDownCount(localStates.Get().Caches, monitorConfig.Get().TrafficServer))), http.StatusOK
 	case srvhttp.APIVersion:
 		s := "traffic_monitor-" + staticAppData.Version + "."
 		if len(staticAppData.GitRevision) > 6 {
@@ -670,7 +672,8 @@ func createCacheConnections(statHistory map[enum.CacheName][]cache.Result) map[e
 	return conns
 }
 
-func cacheDownCount(caches map[enum.CacheName]peer.IsAvailable) int {
+// cacheOfflineCount returns the total caches not available, including marked unavailable, status offline, and status admin_down
+func cacheOfflineCount(caches map[enum.CacheName]peer.IsAvailable) int {
 	count := 0
 	for _, available := range caches {
 		if !available.IsAvailable {
@@ -680,8 +683,20 @@ func cacheDownCount(caches map[enum.CacheName]peer.IsAvailable) int {
 	return count
 }
 
+// cacheAvailableCount returns the total caches available, including marked available and status online
 func cacheAvailableCount(caches map[enum.CacheName]peer.IsAvailable) int {
-	return len(caches) - cacheDownCount(caches)
+	return len(caches) - cacheOfflineCount(caches)
+}
+
+// cacheOfflineCount returns the total reported caches marked down, excluding status offline and admin_down.
+func cacheDownCount(caches map[enum.CacheName]peer.IsAvailable, toServers map[string]to.TrafficServer) int {
+	count := 0
+	for cache, available := range caches {
+		if !available.IsAvailable && enum.CacheStatusFromString(toServers[string(cache)].Status) == enum.CacheStatusReported {
+			count++
+		}
+	}
+	return count
 }
 
 func createAPIPeerStates(peerStates map[enum.TrafficMonitorName]peer.Crstates, filter *PeerStateFilter, params url.Values) APIPeerStates {

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/10129f3f/traffic_monitor/experimental/traffic_monitor/manager/manager.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/manager/manager.go b/traffic_monitor/experimental/traffic_monitor/manager/manager.go
index 36e47c6..70af942 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/manager.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/manager.go
@@ -130,6 +130,7 @@ func Start(opsConfigFile string, cfg config.Config, staticAppData StaticAppData)
 		errorCount,
 		localCacheStatus,
 		unpolledCaches,
+		monitorConfig,
 		cfg,
 	)
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/10129f3f/traffic_monitor/experimental/traffic_monitor/manager/opsconfig.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/manager/opsconfig.go b/traffic_monitor/experimental/traffic_monitor/manager/opsconfig.go
index cdb78eb..2ced120 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/opsconfig.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/opsconfig.go
@@ -65,6 +65,7 @@ func StartOpsConfigManager(
 	errorCount UintThreadsafe,
 	localCacheStatus CacheAvailableStatusThreadsafe,
 	unpolledCaches UnpolledCachesThreadsafe,
+	monitorConfig TrafficMonitorConfigMapThreadsafe,
 	cfg config.Config,
 ) OpsConfigThreadsafe {
 
@@ -125,6 +126,7 @@ func StartOpsConfigManager(
 					localCacheStatus,
 					lastStats,
 					unpolledCaches,
+					monitorConfig,
 				)
 			}, listenAddress, cfg.ServeReadTimeout, cfg.ServeWriteTimeout)
 			if err != nil {


[05/21] incubator-trafficcontrol git commit: Fix TM2 log params to be most-important-first

Posted by ne...@apache.org.
Fix TM2 log params to be most-important-first


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

Branch: refs/heads/master
Commit: 88566dacba38f767e8f79fad0da30b09e6567cce
Parents: 31a17aa
Author: Robert Butts <ro...@gmail.com>
Authored: Fri Oct 28 09:24:09 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 traffic_monitor/experimental/common/log/log.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/88566dac/traffic_monitor/experimental/common/log/log.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/common/log/log.go b/traffic_monitor/experimental/common/log/log.go
index a48362a..596c733 100644
--- a/traffic_monitor/experimental/common/log/log.go
+++ b/traffic_monitor/experimental/common/log/log.go
@@ -15,7 +15,7 @@ var (
 	Error   *log.Logger
 )
 
-func Init(debugW, infoW, warnW, errW io.Writer) {
+func Init(errW, warnW, infoW, debugW io.Writer) {
 	Debug = log.New(debugW, "DEBUG: ", log.Lshortfile)
 	Info = log.New(infoW, "INFO: ", log.Lshortfile)
 	Warning = log.New(warnW, "WARNING: ", log.Lshortfile)


[14/21] incubator-trafficcontrol git commit: Fix TM2 err shadowing

Posted by ne...@apache.org.
Fix TM2 err shadowing


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

Branch: refs/heads/master
Commit: fdb6dfb69adc5a42d9a6c47a135943bda38116f8
Parents: 2b2e90b
Author: Robert Butts <ro...@gmail.com>
Authored: Thu Nov 3 09:22:23 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 .../traffic_monitor/manager/datarequest.go      | 36 +++++++-------------
 1 file changed, 13 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/fdb6dfb6/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go b/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
index 735c222..6352553 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
@@ -434,7 +434,7 @@ func DataRequest(
 	lastStats LastStatsThreadsafe,
 	unpolledCaches UnpolledCachesThreadsafe,
 	monitorConfig TrafficMonitorConfigMapThreadsafe,
-) (body []byte, responseCode int) {
+) ([]byte, int) {
 
 	// handleErr takes an error, and the request type it came from, and logs. It is ok to call with a nil error, in which case this is a no-op.
 	handleErr := func(err error) {
@@ -459,7 +459,6 @@ func DataRequest(
 		return []byte("Service Unavailable"), http.StatusServiceUnavailable
 	}
 
-	var err error
 	switch req.Type {
 	case srvhttp.TRConfig:
 		cdnName := opsConfig.Get().CdnName
@@ -469,54 +468,46 @@ func DataRequest(
 		if cdnName == "" {
 			return commonReturn(nil, fmt.Errorf("No CDN Configured"))
 		}
-		return commonReturn(body, err)
+		return commonReturn(toSession.CRConfigRaw(cdnName))
 	case srvhttp.TRStateDerived:
-		body, err = peer.CrstatesMarshall(combinedStates.Get())
-		return commonReturn(body, err)
+		return commonReturn(peer.CrstatesMarshall(combinedStates.Get()))
 	case srvhttp.TRStateSelf:
-		body, err = peer.CrstatesMarshall(localStates.Get())
-		return commonReturn(body, err)
+		return commonReturn(peer.CrstatesMarshall(localStates.Get()))
 	case srvhttp.CacheStats:
 		filter, err := NewCacheStatFilter(req.Parameters, toData.Get().ServerTypes)
 		if err != nil {
 			handleErr(err)
 			return []byte(err.Error()), http.StatusBadRequest
 		}
-		body, err = cache.StatsMarshall(statHistory.Get(), filter, req.Parameters)
-		return commonReturn(body, err)
+		return commonReturn(cache.StatsMarshall(statHistory.Get(), filter, req.Parameters))
 	case srvhttp.DSStats:
 		filter, err := NewDSStatFilter(req.Parameters, toData.Get().DeliveryServiceTypes)
 		if err != nil {
 			handleErr(err)
 			return []byte(err.Error()), http.StatusBadRequest
 		}
-		body, err = json.Marshal(dsStats.Get().JSON(filter, req.Parameters)) // TODO marshall beforehand, for performance? (test to see how often requests are made)
-		return commonReturn(body, err)
+		// TODO marshall beforehand, for performance? (test to see how often requests are made)
+		return commonReturn(json.Marshal(dsStats.Get().JSON(filter, req.Parameters)))
 	case srvhttp.EventLog:
-		body, err = json.Marshal(JSONEvents{Events: events.Get()})
-		return commonReturn(body, err)
+		return commonReturn(json.Marshal(JSONEvents{Events: events.Get()}))
 	case srvhttp.PeerStates:
 		filter, err := NewPeerStateFilter(req.Parameters, toData.Get().ServerTypes)
 		if err != nil {
 			handleErr(err)
 			return []byte(err.Error()), http.StatusBadRequest
 		}
-
-		body, err = json.Marshal(createAPIPeerStates(peerStates.Get(), filter, req.Parameters))
-		return commonReturn(body, err)
+		return commonReturn(json.Marshal(createAPIPeerStates(peerStates.Get(), filter, req.Parameters)))
 	case srvhttp.StatSummary:
 		return nil, http.StatusNotImplemented
 	case srvhttp.Stats:
-		body, err = getStats(staticAppData, healthPollInterval, lastHealthDurations.Get(), fetchCount.Get(), healthIteration.Get(), errorCount.Get())
-		return commonReturn(body, err)
+		return commonReturn(getStats(staticAppData, healthPollInterval, lastHealthDurations.Get(), fetchCount.Get(), healthIteration.Get(), errorCount.Get()))
 	case srvhttp.ConfigDoc:
 		opsConfigCopy := opsConfig.Get()
 		// if the password is blank, leave it blank, so callers can see it's missing.
 		if opsConfigCopy.Password != "" {
 			opsConfigCopy.Password = "*****"
 		}
-		body, err = json.Marshal(opsConfigCopy)
-		return commonReturn(body, err)
+		return commonReturn(json.Marshal(opsConfigCopy))
 	case srvhttp.APICacheCount: // TODO determine if this should use peerStates
 		return []byte(strconv.Itoa(len(localStates.Get().Caches))), http.StatusOK
 	case srvhttp.APICacheAvailableCount:
@@ -534,9 +525,8 @@ func DataRequest(
 	case srvhttp.APITrafficOpsURI:
 		return []byte(opsConfig.Get().Url), http.StatusOK
 	case srvhttp.APICacheStates:
-		body, err = json.Marshal(createCacheStatuses(toData.Get().ServerTypes, statHistory.Get(),
-			lastHealthDurations.Get(), localStates.Get().Caches, lastStats.Get(), localCacheStatus))
-		return commonReturn(body, err)
+		return commonReturn(json.Marshal(createCacheStatuses(toData.Get().ServerTypes, statHistory.Get(),
+			lastHealthDurations.Get(), localStates.Get().Caches, lastStats.Get(), localCacheStatus)))
 	case srvhttp.APIBandwidthKbps:
 		serverTypes := toData.Get().ServerTypes
 		kbpsStats := lastStats.Get()


[12/21] incubator-trafficcontrol git commit: Fix TM2 cache/astats_test.go len on struct

Posted by ne...@apache.org.
Fix TM2 cache/astats_test.go len on struct


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

Branch: refs/heads/master
Commit: 2b2e90b4acf81fbbdb4818ccf7e896a084b783da
Parents: 25e80eb
Author: Robert Butts <ro...@gmail.com>
Authored: Thu Nov 3 09:00:37 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 traffic_monitor/experimental/traffic_monitor/cache/astats_test.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2b2e90b4/traffic_monitor/experimental/traffic_monitor/cache/astats_test.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/cache/astats_test.go b/traffic_monitor/experimental/traffic_monitor/cache/astats_test.go
index 14401c3..416663d 100644
--- a/traffic_monitor/experimental/traffic_monitor/cache/astats_test.go
+++ b/traffic_monitor/experimental/traffic_monitor/cache/astats_test.go
@@ -18,5 +18,5 @@ func TestAstats(t *testing.T) {
 	if err != nil {
 		t.Log(err)
 	}
-	fmt.Printf("Found %v key/val pairs in ats, and %v key/val pairs in system\n", len(aStats.Ats), len(aStats.System))
+	fmt.Printf("Found %v key/val pairs in ats\n", len(aStats.Ats))
 }


[03/21] incubator-trafficcontrol git commit: Fix TM2 shadowed error variable

Posted by ne...@apache.org.
Fix TM2 shadowed error variable


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

Branch: refs/heads/master
Commit: 690887ad9eefa774b4837d24cff3dc325e3a3a7b
Parents: f12f063
Author: Robert Butts <ro...@gmail.com>
Authored: Thu Nov 3 14:07:42 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 .../experimental/traffic_monitor/cache/cache.go | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/690887ad/traffic_monitor/experimental/traffic_monitor/cache/cache.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/cache/cache.go b/traffic_monitor/experimental/traffic_monitor/cache/cache.go
index 33792a9..f282976 100644
--- a/traffic_monitor/experimental/traffic_monitor/cache/cache.go
+++ b/traffic_monitor/experimental/traffic_monitor/cache/cache.go
@@ -137,7 +137,7 @@ func StatsMarshall(statHistory map[enum.CacheName][]Result, filter Filter, param
 }
 
 // Handle handles results fetched from a cache, parsing the raw Reader data and passing it along to a chan for further processing.
-func (handler Handler) Handle(id string, r io.Reader, reqTime time.Duration, err error, pollID uint64, pollFinished chan<- uint64) {
+func (handler Handler) Handle(id string, r io.Reader, reqTime time.Duration, reqErr error, pollID uint64, pollFinished chan<- uint64) {
 	log.Debugf("poll %v %v handle start\n", pollID, time.Now())
 	result := Result{
 		ID:           enum.CacheName(id),
@@ -147,9 +147,9 @@ func (handler Handler) Handle(id string, r io.Reader, reqTime time.Duration, err
 		PollFinished: pollFinished,
 	}
 
-	if err != nil {
-		log.Errorf("%v handler given error '%v'\n", id, err) // error here, in case the thing that called Handle didn't error
-		result.Error = err
+	if reqErr != nil {
+		log.Errorf("%v handler given error '%v'\n", id, reqErr) // error here, in case the thing that called Handle didn't error
+		result.Error = reqErr
 		handler.ResultChannel <- result
 		return
 	}
@@ -163,9 +163,9 @@ func (handler Handler) Handle(id string, r io.Reader, reqTime time.Duration, err
 
 	result.PrecomputedData.Reporting = true
 
-	if err := json.NewDecoder(r).Decode(&result.Astats); err != nil {
-		log.Errorf("%s procnetdev decode error '%v'\n", id, err)
-		result.Error = err
+	if decodeErr := json.NewDecoder(r).Decode(&result.Astats); decodeErr != nil {
+		log.Errorf("%s procnetdev decode error '%v'\n", id, decodeErr)
+		result.Error = decodeErr
 		handler.ResultChannel <- result
 		return
 	}
@@ -180,9 +180,9 @@ func (handler Handler) Handle(id string, r io.Reader, reqTime time.Duration, err
 
 	log.Debugf("poll %v %v handle decode end\n", pollID, time.Now())
 
-	if err != nil {
-		result.Error = err
-		log.Errorf("addkbps handle %s error '%v'\n", id, err)
+	if reqErr != nil {
+		result.Error = reqErr
+		log.Errorf("addkbps handle %s error '%v'\n", id, reqErr)
 	} else {
 		result.Available = true
 	}


[06/21] incubator-trafficcontrol git commit: Fix TM2 thresholds, max history from TO /health/

Posted by ne...@apache.org.
Fix TM2 thresholds, max history from TO /health/

Fixes Traffic Monitor 2.0 to get per-cache (profile) connection
timeout, max history; and threshold kbps, load average, and query
time from the Traffic Ops /health/{cdn-name} endpoint.


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

Branch: refs/heads/master
Commit: 57b17e08a1128740bc79449319518013e95cc23b
Parents: 88566da
Author: Robert Butts <ro...@gmail.com>
Authored: Fri Oct 28 10:56:26 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 .../experimental/common/fetcher/fetcher.go      |  6 +-
 .../experimental/common/handler/handler.go      |  3 +-
 .../experimental/common/poller/poller.go        | 60 +++++++++++++++-----
 .../experimental/traffic_monitor/cache/cache.go | 17 +++---
 .../traffic_monitor/health/cache_health.go      | 47 ++++++++++++---
 .../traffic_monitor/manager/healthresult.go     |  3 +-
 .../traffic_monitor/manager/manager.go          |  1 -
 .../traffic_monitor/manager/monitorconfig.go    | 28 ++++++---
 .../traffic_monitor/manager/stathistory.go      | 20 +++----
 .../experimental/traffic_monitor/peer/peer.go   |  3 +-
 10 files changed, 130 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/57b17e08/traffic_monitor/experimental/common/fetcher/fetcher.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/common/fetcher/fetcher.go b/traffic_monitor/experimental/common/fetcher/fetcher.go
index f1176ea..d7d7646 100644
--- a/traffic_monitor/experimental/common/fetcher/fetcher.go
+++ b/traffic_monitor/experimental/common/fetcher/fetcher.go
@@ -43,7 +43,9 @@ func (f HttpFetcher) Fetch(id string, url string, pollId uint64, pollFinishedCha
 	if f.Pending != nil {
 		f.Pending.Inc()
 	}
+	startReq := time.Now()
 	response, err := f.Client.Do(req)
+	reqTime := time.Now().Sub(startReq)
 	if f.Pending != nil {
 		f.Pending.Dec()
 	}
@@ -69,11 +71,11 @@ func (f HttpFetcher) Fetch(id string, url string, pollId uint64, pollFinishedCha
 			f.Success.Inc()
 		}
 		log.Debugf("poll %v %v fetch end\n", pollId, time.Now())
-		f.Handler.Handle(id, response.Body, err, pollId, pollFinishedChan)
+		f.Handler.Handle(id, response.Body, reqTime, err, pollId, pollFinishedChan)
 	} else {
 		if f.Fail != nil {
 			f.Fail.Inc()
 		}
-		f.Handler.Handle(id, nil, err, pollId, pollFinishedChan)
+		f.Handler.Handle(id, nil, reqTime, err, pollId, pollFinishedChan)
 	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/57b17e08/traffic_monitor/experimental/common/handler/handler.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/common/handler/handler.go b/traffic_monitor/experimental/common/handler/handler.go
index 0b5f838..e1a558a 100644
--- a/traffic_monitor/experimental/common/handler/handler.go
+++ b/traffic_monitor/experimental/common/handler/handler.go
@@ -3,6 +3,7 @@ package handler
 import (
 	"encoding/json"
 	"io"
+	"time"
 
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/common/log"
 )
@@ -14,7 +15,7 @@ const (
 )
 
 type Handler interface {
-	Handle(string, io.Reader, error, uint64, chan<- uint64)
+	Handle(string, io.Reader, time.Duration, error, uint64, chan<- uint64)
 }
 
 type OpsConfigFileHandler struct {

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/57b17e08/traffic_monitor/experimental/common/poller/poller.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/common/poller/poller.go b/traffic_monitor/experimental/common/poller/poller.go
index 9a7402f..a78d767 100644
--- a/traffic_monitor/experimental/common/poller/poller.go
+++ b/traffic_monitor/experimental/common/poller/poller.go
@@ -22,14 +22,20 @@ type Poller interface {
 }
 
 type HttpPoller struct {
-	Config        HttpPollerConfig
-	ConfigChannel chan HttpPollerConfig
-	Fetcher       fetcher.Fetcher
-	TickChan      chan uint64
+	Config          HttpPollerConfig
+	ConfigChannel   chan HttpPollerConfig
+	FetcherTemplate fetcher.HttpFetcher // FetcherTemplate has all the constant settings, and is copied to create fetchers with custom HTTP client timeouts.
+	TickChan        chan uint64
+}
+
+type PollConfig struct {
+	URL     string
+	Timeout time.Duration
+	Handler handler.Handler
 }
 
 type HttpPollerConfig struct {
-	Urls     map[string]string
+	Urls     map[string]PollConfig
 	Interval time.Duration
 }
 
@@ -46,7 +52,7 @@ func NewHTTP(interval time.Duration, tick bool, httpClient *http.Client, counter
 		Config: HttpPollerConfig{
 			Interval: interval,
 		},
-		Fetcher: fetcher.HttpFetcher{
+		FetcherTemplate: fetcher.HttpFetcher{
 			Handler:  fetchHandler,
 			Client:   httpClient,
 			Counters: counters,
@@ -124,7 +130,14 @@ func (p HttpPoller) Poll() {
 		for _, info := range additions {
 			kill := make(chan struct{})
 			killChans[info.ID] = kill
-			go pollHttp(info.Interval, info.ID, info.URL, p.Fetcher, kill)
+
+			fetcher := p.FetcherTemplate
+			if info.Timeout != 0 { // if the timeout isn't explicitly set, use the template value.
+				c := *fetcher.Client
+				fetcher.Client = &c // copy the client, so we don't change other fetchers.
+				fetcher.Client.Timeout = info.Timeout
+			}
+			go pollHttp(info.Interval, info.ID, info.URL, fetcher, kill)
 		}
 		p.Config = newConfig
 	}
@@ -132,8 +145,10 @@ func (p HttpPoller) Poll() {
 
 type HTTPPollInfo struct {
 	Interval time.Duration
+	Timeout  time.Duration
 	ID       string
 	URL      string
+	Handler  handler.Handler
 }
 
 // diffConfigs takes the old and new configs, and returns a list of deleted IDs, and a list of new polls to do
@@ -145,26 +160,41 @@ func diffConfigs(old HttpPollerConfig, new HttpPollerConfig) ([]string, []HTTPPo
 		for id, _ := range old.Urls {
 			deletions = append(deletions, id)
 		}
-		for id, url := range new.Urls {
-			additions = append(additions, HTTPPollInfo{Interval: new.Interval, ID: id, URL: url})
+		for id, pollCfg := range new.Urls {
+			additions = append(additions, HTTPPollInfo{
+				Interval: new.Interval,
+				ID:       id,
+				URL:      pollCfg.URL,
+				Timeout:  pollCfg.Timeout,
+			})
 		}
 		return deletions, additions
 	}
 
-	for id, oldUrl := range old.Urls {
-		newUrl, newIdExists := new.Urls[id]
+	for id, oldPollCfg := range old.Urls {
+		newPollCfg, newIdExists := new.Urls[id]
 		if !newIdExists {
 			deletions = append(deletions, id)
-		} else if newUrl != oldUrl {
+		} else if newPollCfg != oldPollCfg {
 			deletions = append(deletions, id)
-			additions = append(additions, HTTPPollInfo{Interval: new.Interval, ID: id, URL: newUrl})
+			additions = append(additions, HTTPPollInfo{
+				Interval: new.Interval,
+				ID:       id,
+				URL:      newPollCfg.URL,
+				Timeout:  newPollCfg.Timeout,
+			})
 		}
 	}
 
-	for id, newUrl := range new.Urls {
+	for id, newPollCfg := range new.Urls {
 		_, oldIdExists := old.Urls[id]
 		if !oldIdExists {
-			additions = append(additions, HTTPPollInfo{Interval: new.Interval, ID: id, URL: newUrl})
+			additions = append(additions, HTTPPollInfo{
+				Interval: new.Interval,
+				ID:       id,
+				URL:      newPollCfg.URL,
+				Timeout:  newPollCfg.Timeout,
+			})
 		}
 	}
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/57b17e08/traffic_monitor/experimental/traffic_monitor/cache/cache.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/cache/cache.go b/traffic_monitor/experimental/traffic_monitor/cache/cache.go
index 0d5a95c..52230d2 100644
--- a/traffic_monitor/experimental/traffic_monitor/cache/cache.go
+++ b/traffic_monitor/experimental/traffic_monitor/cache/cache.go
@@ -27,6 +27,7 @@ type Handler struct {
 }
 
 // NewHandler returns a new cache handler. Note this handler does NOT precomputes stat data before calling ResultChannel, and Result.Precomputed will be nil
+// TODO change this to take the ResultChan. It doesn't make sense for the Handler to 'own' the Result Chan.
 func NewHandler() Handler {
 	return Handler{ResultChannel: make(chan Result), MultipleSpaceRegex: regexp.MustCompile(" +")}
 }
@@ -52,12 +53,13 @@ type PrecomputedData struct {
 
 // Result is the data result returned by a cache.
 type Result struct {
-	ID        enum.CacheName
-	Available bool
-	Error     error
-	Astats    Astats
-	Time      time.Time
-	Vitals    Vitals
+	ID          enum.CacheName
+	Available   bool
+	Error       error
+	Astats      Astats
+	Time        time.Time
+	RequestTime time.Duration
+	Vitals      Vitals
 	PrecomputedData
 	PollID       uint64
 	PollFinished chan<- uint64
@@ -135,11 +137,12 @@ func StatsMarshall(statHistory map[enum.CacheName][]Result, filter Filter, param
 }
 
 // Handle handles results fetched from a cache, parsing the raw Reader data and passing it along to a chan for further processing.
-func (handler Handler) Handle(id string, r io.Reader, err error, pollID uint64, pollFinished chan<- uint64) {
+func (handler Handler) Handle(id string, r io.Reader, reqTime time.Duration, err error, pollID uint64, pollFinished chan<- uint64) {
 	log.Debugf("poll %v %v handle start\n", pollID, time.Now())
 	result := Result{
 		ID:           enum.CacheName(id),
 		Time:         time.Now(), // TODO change this to be computed the instant we get the result back, to minimise inaccuracy
+		RequestTime:  reqTime,
 		PollID:       pollID,
 		PollFinished: pollFinished,
 	}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/57b17e08/traffic_monitor/experimental/traffic_monitor/health/cache_health.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/health/cache_health.go b/traffic_monitor/experimental/traffic_monitor/health/cache_health.go
index 4147418..1106f62 100644
--- a/traffic_monitor/experimental/traffic_monitor/health/cache_health.go
+++ b/traffic_monitor/experimental/traffic_monitor/health/cache_health.go
@@ -1,13 +1,15 @@
 package health
 
 import (
-	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/common/log"
-	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/cache"
-	traffic_ops "github.com/apache/incubator-trafficcontrol/traffic_ops/client"
-
 	"fmt"
+	"math"
 	"strconv"
 	"strings"
+	"time"
+
+	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/common/log"
+	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/cache"
+	traffic_ops "github.com/apache/incubator-trafficcontrol/traffic_ops/client"
 )
 
 func setError(newResult *cache.Result, err error) {
@@ -73,9 +75,34 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *traffic_op
 	// log.Infoln(newResult.Id, "BytesOut", newResult.Vitals.BytesOut, "BytesIn", newResult.Vitals.BytesIn, "Kbps", newResult.Vitals.KbpsOut, "max", newResult.Vitals.MaxKbpsOut)
 }
 
+// getKbpsThreshold returns the numeric kbps threshold, from the Traffic Ops string value. If there is a parse error, it logs a warning and returns the max floating point number, signifying no limit
+// TODO add float64 to Traffic Ops Client interface
+func getKbpsThreshold(threshStr string) int64 {
+	if len(threshStr) == 0 {
+		log.Errorf("Empty Traffic Ops HealthThresholdAvailableBandwidthInKbps; setting no limit.\n")
+		return math.MaxInt64
+	}
+	if threshStr[0] == '>' {
+		threshStr = threshStr[1:]
+	}
+	thresh, err := strconv.ParseInt(threshStr, 10, 64)
+	if err != nil {
+		log.Errorf("Failed to parse Traffic Ops HealthThresholdAvailableBandwidthInKbps, setting no limit: '%v'\n", err)
+		return math.MaxInt64
+	}
+	return thresh
+}
+
+// TODO add time.Duration to Traffic Ops Client interface
+func getQueryThreshold(threshInt int64) time.Duration {
+	return time.Duration(threshInt) * time.Millisecond
+}
+
 // EvalCache returns whether the given cache should be marked available, and a string describing why
 func EvalCache(result cache.Result, mc *traffic_ops.TrafficMonitorConfigMap) (bool, string) {
-	status := mc.TrafficServer[string(result.ID)].Status
+	toServer := mc.TrafficServer[string(result.ID)]
+	status := toServer.Status
+	params := mc.Profile[toServer.Profile].Parameters
 	switch {
 	case status == "ADMIN_DOWN":
 		return false, "set to ADMIN_DOWN"
@@ -85,10 +112,12 @@ func EvalCache(result cache.Result, mc *traffic_ops.TrafficMonitorConfigMap) (bo
 		return true, "set to ONLINE"
 	case result.Error != nil:
 		return false, fmt.Sprintf("error: %v", result.Error)
-	case result.Vitals.LoadAvg > mc.Profile[mc.TrafficServer[string(result.ID)].Profile].Parameters.HealthThresholdLoadAvg:
-		return false, fmt.Sprintf("load average %f exceeds threshold %f", result.Vitals.LoadAvg, mc.Profile[mc.TrafficServer[string(result.ID)].Profile].Parameters.HealthThresholdLoadAvg)
-	case result.Vitals.MaxKbpsOut < result.Vitals.KbpsOut:
-		return false, fmt.Sprintf("%dkbps exceeds max %dkbps", result.Vitals.KbpsOut, result.Vitals.MaxKbpsOut)
+	case result.Vitals.LoadAvg > params.HealthThresholdLoadAvg:
+		return false, fmt.Sprintf("load average %f exceeds threshold %f", result.Vitals.LoadAvg, params.HealthThresholdLoadAvg)
+	case result.Vitals.KbpsOut >= getKbpsThreshold(params.HealthThresholdAvailableBandwidthInKbps):
+		return false, fmt.Sprintf("%dkbps exceeds max %dkbps", result.Vitals.KbpsOut, getKbpsThreshold(params.HealthThresholdAvailableBandwidthInKbps))
+	case result.RequestTime > getQueryThreshold(int64(params.HealthThresholdQueryTime)):
+		return false, fmt.Sprintf("request time %v exceeds max %v", result.RequestTime, getQueryThreshold(int64(params.HealthThresholdQueryTime)))
 	default:
 		return result.Available, "reported"
 	}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/57b17e08/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go b/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go
index de069b3..42fe82c 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go
@@ -203,7 +203,8 @@ func processHealthResult(
 			health.GetVitals(&healthResult, &prevResult, &monitorConfigCopy)
 		}
 
-		healthHistory[healthResult.ID] = pruneHistory(append(healthHistory[healthResult.ID], healthResult), cfg.MaxHealthHistory)
+		maxHistory := uint64(monitorConfigCopy.Profile[monitorConfigCopy.TrafficServer[string(healthResult.ID)].Profile].Parameters.HistoryCount)
+		healthHistory[healthResult.ID] = pruneHistory(append(healthHistory[healthResult.ID], healthResult), maxHistory)
 
 		isAvailable, whyAvailable := health.EvalCache(healthResult, &monitorConfigCopy)
 		if localStates.Get().Caches[healthResult.ID].IsAvailable != isAvailable {

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/57b17e08/traffic_monitor/experimental/traffic_monitor/manager/manager.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/manager/manager.go b/traffic_monitor/experimental/traffic_monitor/manager/manager.go
index c362b33..36e47c6 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/manager.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/manager.go
@@ -42,7 +42,6 @@ func Start(opsConfigFile string, cfg config.Config, staticAppData StaticAppData)
 
 	// TODO investigate whether a unique client per cache to be polled is faster
 	sharedClient := &http.Client{
-		Timeout:   cfg.HTTPTimeout,
 		Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}},
 	}
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/57b17e08/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 dc8ca41..e3ba337 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
@@ -2,14 +2,16 @@ package manager
 
 import (
 	"fmt"
+	"strings"
+	"sync"
+	"time"
+
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/common/log"
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/common/poller"
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/config"
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/enum"
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/peer"
 	to "github.com/apache/incubator-trafficcontrol/traffic_ops/client"
-	"strings"
-	"sync"
 )
 
 // CopyTrafficMonitorConfigMap returns a deep copy of the given TrafficMonitorConfigMap
@@ -92,6 +94,12 @@ func StartMonitorConfigManager(
 	return monitorConfig
 }
 
+// trafficOpsHealthConnectionTimeoutToDuration 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 trafficOpsHealthConnectionTimeoutToDuration(t int) time.Duration {
+	return time.Duration(t) * time.Millisecond
+}
+
 // 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(
@@ -107,9 +115,9 @@ func monitorConfigListen(
 ) {
 	for monitorConfig := range monitorConfigPollChan {
 		monitorConfigTS.Set(monitorConfig)
-		healthUrls := map[string]string{}
-		statUrls := map[string]string{}
-		peerUrls := map[string]string{}
+		healthUrls := map[string]poller.PollConfig{}
+		statUrls := map[string]poller.PollConfig{}
+		peerUrls := map[string]poller.PollConfig{}
 		caches := map[string]string{}
 
 		for _, srv := range monitorConfig.TrafficServer {
@@ -137,10 +145,12 @@ func monitorConfigListen(
 				"application=", "application=plugin.remap",
 			)
 			url = r.Replace(url)
-			healthUrls[srv.HostName] = url
+
+			connTimeout := trafficOpsHealthConnectionTimeoutToDuration(monitorConfig.Profile[srv.Profile].Parameters.HealthConnectionTimeout)
+			healthUrls[srv.HostName] = poller.PollConfig{URL: url, Timeout: connTimeout}
 			r = strings.NewReplacer("application=plugin.remap", "application=")
-			url = r.Replace(url)
-			statUrls[srv.HostName] = url
+			statUrl := r.Replace(url)
+			statUrls[srv.HostName] = poller.PollConfig{URL: statUrl, Timeout: connTimeout}
 		}
 
 		for _, srv := range monitorConfig.TrafficMonitor {
@@ -152,7 +162,7 @@ func monitorConfigListen(
 			}
 			// TODO: the URL should be config driven. -jse
 			url := fmt.Sprintf("http://%s:%d/publish/CrStates?raw", srv.IP, srv.Port)
-			peerUrls[srv.HostName] = url
+			peerUrls[srv.HostName] = poller.PollConfig{URL: url} // TODO determine timeout.
 		}
 
 		statURLSubscriber <- poller.HttpPollerConfig{Urls: statUrls, Interval: cfg.CacheStatPollingInterval}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/57b17e08/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go b/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go
index 7af7e2c..b3fc407 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go
@@ -11,6 +11,7 @@ import (
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/enum"
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/peer"
 	todata "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/trafficopsdata"
+	to "github.com/apache/incubator-trafficcontrol/traffic_ops/client"
 )
 
 // StatHistory is a map of cache names, to an array of result history from each cache.
@@ -37,18 +38,12 @@ func (a StatHistory) Copy() StatHistory {
 type StatHistoryThreadsafe struct {
 	statHistory *StatHistory
 	m           *sync.RWMutex
-	max         uint64
-}
-
-// Max returns the max history to be stored for any cache
-func (h StatHistoryThreadsafe) Max() uint64 {
-	return h.max
 }
 
 // NewStatHistoryThreadsafe returns a new StatHistory safe for multiple readers and a single writer.
-func NewStatHistoryThreadsafe(maxHistory uint64) StatHistoryThreadsafe {
+func NewStatHistoryThreadsafe() StatHistoryThreadsafe {
 	h := StatHistory{}
-	return StatHistoryThreadsafe{m: &sync.RWMutex{}, statHistory: &h, max: maxHistory}
+	return StatHistoryThreadsafe{m: &sync.RWMutex{}, statHistory: &h}
 }
 
 // Get returns the StatHistory. Callers MUST NOT modify. If mutation is necessary, call StatHistory.Copy()
@@ -99,7 +94,7 @@ func StartStatHistoryManager(
 	cfg config.Config,
 	monitorConfig TrafficMonitorConfigMapThreadsafe,
 ) (StatHistoryThreadsafe, DurationMapThreadsafe, LastStatsThreadsafe, DSStatsReader, UnpolledCachesThreadsafe) {
-	statHistory := NewStatHistoryThreadsafe(cfg.MaxStatHistory)
+	statHistory := NewStatHistoryThreadsafe()
 	lastStatDurations := NewDurationMapThreadsafe()
 	lastStatEndTimes := map[enum.CacheName]time.Time{}
 	lastStats := NewLastStatsThreadsafe()
@@ -122,14 +117,14 @@ func StartStatHistoryManager(
 					unpolledCaches.SetNewCaches(getNewCaches(localStates, monitorConfig))
 				case <-tick:
 					log.Warnf("StatHistoryManager flushing queued results\n")
-					processStatResults(results, statHistory, combinedStates.Get(), lastStats, toData.Get(), errorCount, dsStats, lastStatEndTimes, lastStatDurations, unpolledCaches)
+					processStatResults(results, statHistory, combinedStates.Get(), lastStats, toData.Get(), errorCount, dsStats, lastStatEndTimes, lastStatDurations, unpolledCaches, monitorConfig.Get())
 					break innerLoop
 				default:
 					select {
 					case r := <-cacheStatChan:
 						results = append(results, r)
 					default:
-						processStatResults(results, statHistory, combinedStates.Get(), lastStats, toData.Get(), errorCount, dsStats, lastStatEndTimes, lastStatDurations, unpolledCaches)
+						processStatResults(results, statHistory, combinedStates.Get(), lastStats, toData.Get(), errorCount, dsStats, lastStatEndTimes, lastStatDurations, unpolledCaches, monitorConfig.Get())
 						break innerLoop
 					}
 				}
@@ -151,10 +146,11 @@ func processStatResults(
 	lastStatEndTimes map[enum.CacheName]time.Time,
 	lastStatDurationsThreadsafe DurationMapThreadsafe,
 	unpolledCaches UnpolledCachesThreadsafe,
+	mc to.TrafficMonitorConfigMap,
 ) {
 	statHistory := statHistoryThreadsafe.Get().Copy()
-	maxStats := statHistoryThreadsafe.Max()
 	for _, result := range results {
+		maxStats := uint64(mc.Profile[mc.TrafficServer[string(result.ID)].Profile].Parameters.HistoryCount)
 		// TODO determine if we want to add results with errors, or just print the errors now and don't add them.
 		statHistory[result.ID] = pruneHistory(append(statHistory[result.ID], result), maxStats)
 	}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/57b17e08/traffic_monitor/experimental/traffic_monitor/peer/peer.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/peer/peer.go b/traffic_monitor/experimental/traffic_monitor/peer/peer.go
index b6e9873..01d5c52 100644
--- a/traffic_monitor/experimental/traffic_monitor/peer/peer.go
+++ b/traffic_monitor/experimental/traffic_monitor/peer/peer.go
@@ -3,6 +3,7 @@ package peer
 import (
 	"encoding/json"
 	"io"
+	"time"
 
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/enum"
 )
@@ -29,7 +30,7 @@ type Result struct {
 }
 
 // Handle handles a response from a polled Traffic Monitor peer, parsing the data and forwarding it to the ResultChannel.
-func (handler Handler) Handle(id string, r io.Reader, err error, pollID uint64, pollFinished chan<- uint64) {
+func (handler Handler) Handle(id string, r io.Reader, reqTime time.Duration, err error, pollID uint64, pollFinished chan<- uint64) {
 	result := Result{
 		ID:           enum.TrafficMonitorName(id),
 		Available:    false,


[19/21] incubator-trafficcontrol git commit: Add TM2 log.Close to log io.Closers

Posted by ne...@apache.org.
Add TM2 log.Close to log io.Closers

Adds `log.Close` and `log.Closef`, which call `Close` on a given
`io.Closer`, and log any error, along with given context. This allows
succinctly calling `defer log.Close(resp.Body` to log, while retaining
the convenience, brevity, and idiomaticy of `defer`.


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

Branch: refs/heads/master
Commit: f12f0639ce2b11248319dbabbef6abb31639db6e
Parents: 1aa0c0b
Author: Robert Butts <ro...@gmail.com>
Authored: Thu Nov 3 13:58:43 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 traffic_monitor/experimental/common/log/log.go | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/f12f0639/traffic_monitor/experimental/common/log/log.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/common/log/log.go b/traffic_monitor/experimental/common/log/log.go
index 596c733..cf5144f 100644
--- a/traffic_monitor/experimental/common/log/log.go
+++ b/traffic_monitor/experimental/common/log/log.go
@@ -48,3 +48,20 @@ func Debugf(format string, v ...interface{}) {
 func Debugln(v ...interface{}) {
 	Debug.Output(3, time.Now().Format(timeFormat)+": "+fmt.Sprintln(v...))
 }
+
+// Close calls `Close()` on the given Closer, and logs any error. On error, the context is logged, followed by a colon, the error message, and a newline. This is primarily designed to be used in `defer`, for example, `defer log.Close(resp.Body, "readData fetching /foo/bar")`.
+func Close(c io.Closer, context string) {
+	err := c.Close()
+	if err != nil {
+		Errorf("%v: %v", context, err)
+	}
+}
+
+// Closef acts like Close, with a given format string and values, followed by a colon, the error message, and a newline. The given values are not coerced, concatenated, or printed unless an error occurs, so this is more efficient than `Close()`.
+func Closef(c io.Closer, contextFormat string, v ...interface{}) {
+	err := c.Close()
+	if err != nil {
+		Errorf(contextFormat, v...)
+		Errorf(": %v", err)
+	}
+}


[04/21] incubator-trafficcontrol git commit: Change TM2 example config stat flush to 20ms.

Posted by ne...@apache.org.
Change TM2 example config stat flush to 20ms.

Changes the Traffic Monitor example config stat and health poll flush
intervals from 200ms to 20ms. This appears to be more reasonable, and
to do a better job of averaging new polls, preventing poll times from
'stacking up'.


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

Branch: refs/heads/master
Commit: a8dabc5b5045878584cadf7de599d9041ae93dd4
Parents: 80a417b
Author: Robert Butts <ro...@gmail.com>
Authored: Tue Nov 1 16:32:03 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 .../traffic_monitor/traffic_monitor-example-config.json          | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a8dabc5b/traffic_monitor/experimental/traffic_monitor/traffic_monitor-example-config.json
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/traffic_monitor-example-config.json b/traffic_monitor/experimental/traffic_monitor/traffic_monitor-example-config.json
index bf40325..d1b4613 100644
--- a/traffic_monitor/experimental/traffic_monitor/traffic_monitor-example-config.json
+++ b/traffic_monitor/experimental/traffic_monitor/traffic_monitor-example-config.json
@@ -7,8 +7,8 @@
 	"max_events": 200,
 	"max_stat_history": 5,
 	"max_health_history": 5,
-	"health_flush_interval_ms": 200,
-	"stat_flush_interval_ms": 200,
+	"health_flush_interval_ms": 20,
+	"stat_flush_interval_ms": 20,
 	"log_location_error": "stderr",
 	"log_location_warning": "stdout",
 	"log_location_info": "null",


[20/21] incubator-trafficcontrol git commit: Fix TM2 shadowing error

Posted by ne...@apache.org.
Fix TM2 shadowing error


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

Branch: refs/heads/master
Commit: 78c4c0ca67512562f3fcd918060096549d9260e5
Parents: 387cbed
Author: Robert Butts <ro...@gmail.com>
Authored: Thu Nov 3 14:17:18 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 .../experimental/traffic_monitor/trafficopsdata/trafficopsdata.go | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/78c4c0ca/traffic_monitor/experimental/traffic_monitor/trafficopsdata/trafficopsdata.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/trafficopsdata/trafficopsdata.go b/traffic_monitor/experimental/traffic_monitor/trafficopsdata/trafficopsdata.go
index 1659ae1..73b5343 100644
--- a/traffic_monitor/experimental/traffic_monitor/trafficopsdata/trafficopsdata.go
+++ b/traffic_monitor/experimental/traffic_monitor/trafficopsdata/trafficopsdata.go
@@ -123,7 +123,8 @@ func (d TODataThreadsafe) Fetch(to towrap.ITrafficOpsSession, cdn string) error
 		return fmt.Errorf("Error getting CRconfig from Traffic Ops: %v", err)
 	}
 	var crConfig CRConfig
-	if err := json.Unmarshal(crConfigBytes, &crConfig); err != nil {
+	err = json.Unmarshal(crConfigBytes, &crConfig)
+	if err != nil {
 		return fmt.Errorf("Error unmarshalling CRconfig: %v", err)
 	}
 


[16/21] incubator-trafficcontrol git commit: Fix TM2 duplicate strings to enums

Posted by ne...@apache.org.
Fix TM2 duplicate strings to enums


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

Branch: refs/heads/master
Commit: 1aa0c0ba41cbfb6637df76cd290130e6165087b6
Parents: 3a73422
Author: Robert Butts <ro...@gmail.com>
Authored: Thu Nov 3 09:55:03 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 .../experimental/traffic_monitor/manager/monitorconfig.go     | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/1aa0c0ba/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 4ff0cf4..2505b9b 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
@@ -190,11 +190,12 @@ func monitorConfigListen(
 
 			cacheName := enum.CacheName(srv.HostName)
 
-			if srv.Status == "ONLINE" {
+			srvStatus := enum.CacheStatusFromString(srv.Status)
+			if srvStatus == enum.CacheStatusOnline {
 				localStates.SetCache(cacheName, peer.IsAvailable{IsAvailable: true})
 				continue
 			}
-			if srv.Status == "OFFLINE" {
+			if srvStatus == enum.CacheStatusOffline {
 				continue
 			}
 			// seed states with available = false until our polling cycle picks up a result
@@ -222,7 +223,7 @@ func monitorConfigListen(
 			if srv.HostName == staticAppData.Hostname {
 				continue
 			}
-			if srv.Status != "ONLINE" {
+			if enum.CacheStatusFromString(srv.Status) != enum.CacheStatusOnline {
 				continue
 			}
 			// TODO: the URL should be config driven. -jse


[17/21] incubator-trafficcontrol git commit: Fix TM2 poll to randomize start, poll precisely.

Posted by ne...@apache.org.
Fix TM2 poll to randomize start, poll precisely.

Fixes Trafic Monitor 2.0 polling to sleep a random time between 0
and the poll interval. This prevents polling all caches at once
every tick.

Fixes to poll precisely on the interval, by recreating the ticker.
The Go `Ticker` attempts to 'smooth' polls, increasing or decreasing
poll times to compensate for slow poll processing. This fixes it to
poll at precisely the given interval.


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

Branch: refs/heads/master
Commit: 80a417b4ba09f0bf963e00cfb4bc15fa32aedc88
Parents: 10129f3
Author: Robert Butts <ro...@gmail.com>
Authored: Tue Nov 1 16:28:19 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 traffic_monitor/experimental/common/poller/poller.go | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/80a417b4/traffic_monitor/experimental/common/poller/poller.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/common/poller/poller.go b/traffic_monitor/experimental/common/poller/poller.go
index a78d767..4609f7a 100644
--- a/traffic_monitor/experimental/common/poller/poller.go
+++ b/traffic_monitor/experimental/common/poller/poller.go
@@ -2,6 +2,7 @@ package poller
 
 import (
 	"io/ioutil"
+	"math/rand"
 	"net/http"
 	"os"
 	"sync/atomic"
@@ -235,11 +236,14 @@ func (p FilePoller) Poll() {
 
 // TODO iterationCount and/or p.TickChan?
 func pollHttp(interval time.Duration, id string, url string, fetcher fetcher.Fetcher, die <-chan struct{}) {
+	pollSpread := time.Duration(rand.Float64()*float64(interval/time.Nanosecond)) * time.Nanosecond
+	time.Sleep(pollSpread)
 	tick := time.NewTicker(interval)
 	lastTime := time.Now()
 	for {
 		select {
 		case now := <-tick.C:
+			tick = time.NewTicker(interval) // recreate timer, to avoid Go's "smoothing" nonsense
 			realInterval := now.Sub(lastTime)
 			if realInterval > interval+(time.Millisecond*100) {
 				instr.TimerFail.Inc()


[10/21] incubator-trafficcontrol git commit: Add TM2 config for health-to-stat ratio.

Posted by ne...@apache.org.
Add TM2 config for health-to-stat ratio.

Adds Traffic Monitor 2.0 config setting for health-to-stat ration.
This is only used if a 'health' poll interval exists in Traffic Ops
but no 'stat' interval, which is the case for Traffic Monitor 2.0.

If both 'health' and 'stat' exist, they will be used appropriately
and this config setting will be ignored. If only 'health' exists, it
will be used for 'stat' (which is the big query, like the only query
in Traffic Monitor 1.0), and 'health' will be the given ratio. For
example, to set the health poll at a quarter the stat poll, set the
config value to 4. So, a stat poll of 8 becomes 8/4=2 seconds. To use
the same value for both, set the config to 1.

This only exists to make it possible to poll health at a faster
rate in an existing Traffic Control deployment with no parameter
changes. Once deployed, the parameters should be set appropriately
and this config will not be used.


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

Branch: refs/heads/master
Commit: 75a9581d8b00b29f3a686179d96f5a724e2b2cee
Parents: a8dabc5
Author: Robert Butts <ro...@gmail.com>
Authored: Wed Nov 2 14:42:01 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 .../experimental/traffic_monitor/config/config.go       |  2 ++
 .../traffic_monitor/manager/monitorconfig.go            | 12 ++++--------
 2 files changed, 6 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/75a9581d/traffic_monitor/experimental/traffic_monitor/config/config.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/config/config.go b/traffic_monitor/experimental/traffic_monitor/config/config.go
index 9e56f51..c7d53fb 100644
--- a/traffic_monitor/experimental/traffic_monitor/config/config.go
+++ b/traffic_monitor/experimental/traffic_monitor/config/config.go
@@ -36,6 +36,7 @@ type Config struct {
 	LogLocationDebug             string        `json:"log_location_debug"`
 	ServeReadTimeout             time.Duration `json:"-"`
 	ServeWriteTimeout            time.Duration `json:"-"`
+	HealthToStatRatio            uint64        `json:"health_to_stat_ratio"`
 }
 
 // DefaultConfig is the default configuration for the application, if no configuration file is given, or if a given config setting doesn't exist in the config file.
@@ -56,6 +57,7 @@ var DefaultConfig = Config{
 	LogLocationDebug:             LogLocationNull,
 	ServeReadTimeout:             10 * time.Second,
 	ServeWriteTimeout:            10 * time.Second,
+	HealthToStatRatio:            4,
 }
 
 // MarshalJSON marshals custom millisecond durations. Aliasing inspired by http://choly.ca/post/go-json-marshalling/

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/75a9581d/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 352f8e6..4ff0cf4 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
@@ -119,7 +119,7 @@ func trafficOpsHealthPollIntervalToDuration(t int) time.Duration {
 }
 
 // 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) {
+func getHealthPeerStatPollIntervals(monitorConfig to.TrafficMonitorConfigMap, cfg config.Config) (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")
@@ -153,12 +153,8 @@ func getHealthPeerStatPollIntervals(monitorConfig to.TrafficMonitorConfigMap) (t
 	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
-		}
+	if healthPollIntervalExists && !statPollIntervalExists {
+		healthPollInterval = time.Duration(float64(healthPollInterval) / float64(cfg.HealthToStatRatio))
 	}
 
 	return healthPollInterval, peerPollInterval, statPollInterval, nil
@@ -184,7 +180,7 @@ func monitorConfigListen(
 		peerUrls := map[string]poller.PollConfig{}
 		caches := map[string]string{}
 
-		healthPollInterval, peerPollInterval, statPollInterval, err := getHealthPeerStatPollIntervals(monitorConfig)
+		healthPollInterval, peerPollInterval, statPollInterval, err := getHealthPeerStatPollIntervals(monitorConfig, cfg)
 		if err != nil {
 			continue
 		}


[21/21] incubator-trafficcontrol git commit: This closes #21

Posted by ne...@apache.org.
This closes #21


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

Branch: refs/heads/master
Commit: 7e34e01de7f5a524032c2d12a11a52fac09b9183
Parents: 5edd95c
Author: Dave Neuman <ne...@apache.org>
Authored: Mon Nov 7 12:29:23 2016 -0700
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:23 2016 -0700

----------------------------------------------------------------------

----------------------------------------------------------------------



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

Posted by ne...@apache.org.
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 {


[18/21] incubator-trafficcontrol git commit: Fix TM2 monitorconfig to set statPollInterval

Posted by ne...@apache.org.
Fix TM2 monitorconfig to set statPollInterval


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

Branch: refs/heads/master
Commit: 7401f7c4dd9afdf520cbea904b7f8da7dfcacf42
Parents: 78c4c0c
Author: Robert Butts <ro...@gmail.com>
Authored: Thu Nov 3 14:19:29 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 .../experimental/traffic_monitor/manager/monitorconfig.go          | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7401f7c4/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 5f239bd..0a7c657 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
@@ -148,7 +148,7 @@ func getHealthPeerStatPollIntervals(monitorConfig to.TrafficMonitorConfigMap, cf
 	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
+		statPollIntervalInt = healthPollIntervalInt
 	}
 	statPollInterval := trafficOpsStatPollIntervalToDuration(int(statPollIntervalInt))
 


[11/21] incubator-trafficcontrol git commit: Fix TM2 monitorconfig to correct conversion funcs

Posted by ne...@apache.org.
Fix TM2 monitorconfig to correct conversion funcs


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

Branch: refs/heads/master
Commit: 387cbed295ec5ce8385f4283f2af0a147409e3ed
Parents: 690887a
Author: Robert Butts <ro...@gmail.com>
Authored: Thu Nov 3 14:09:26 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 .../experimental/traffic_monitor/manager/monitorconfig.go        | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/387cbed2/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 2505b9b..5f239bd 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go
@@ -138,7 +138,7 @@ func getHealthPeerStatPollIntervals(monitorConfig to.TrafficMonitorConfigMap, cf
 	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))
+	peerPollInterval := trafficOpsPeerPollIntervalToDuration(int(peerPollIntervalInt))
 
 	statPollIntervalI, statPollIntervalExists := monitorConfig.Config["stat.polling.interval"]
 	if !statPollIntervalExists {
@@ -150,7 +150,7 @@ func getHealthPeerStatPollIntervals(monitorConfig to.TrafficMonitorConfigMap, cf
 		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))
+	statPollInterval := trafficOpsStatPollIntervalToDuration(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.
 	if healthPollIntervalExists && !statPollIntervalExists {


[13/21] incubator-trafficcontrol git commit: Fix TM2 /publish/CacheStats values to be strings

Posted by ne...@apache.org.
Fix TM2 /publish/CacheStats values to be strings


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

Branch: refs/heads/master
Commit: 25e80eb7c45cda0a204559000915aa61ae86d2a1
Parents: 75a9581
Author: Robert Butts <ro...@gmail.com>
Authored: Wed Nov 2 15:17:34 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 traffic_monitor/experimental/traffic_monitor/cache/cache.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/25e80eb7/traffic_monitor/experimental/traffic_monitor/cache/cache.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/cache/cache.go b/traffic_monitor/experimental/traffic_monitor/cache/cache.go
index 52230d2..33792a9 100644
--- a/traffic_monitor/experimental/traffic_monitor/cache/cache.go
+++ b/traffic_monitor/experimental/traffic_monitor/cache/cache.go
@@ -128,7 +128,7 @@ func StatsMarshall(statHistory map[enum.CacheName][]Result, filter Filter, param
 					stats.Caches[id] = map[string][]Stat{}
 				}
 
-				stats.Caches[id][stat] = append(stats.Caches[id][stat], s)
+				stats.Caches[id][stat] = append(stats.Caches[id][stat], Stat{Time: s.Time, Value: fmt.Sprintf("%v", s.Value)}) // convert stats to strings, for the TM1.0 /publish/CacheStats API
 			}
 		}
 	}


[15/21] incubator-trafficcontrol git commit: Fix TM2 invalid enum strings to be unique

Posted by ne...@apache.org.
Fix TM2 invalid enum strings to be unique


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

Branch: refs/heads/master
Commit: 3a73422b60fa5cf0de9541016c02a9efe90b39d5
Parents: fdb6dfb
Author: Robert Butts <ro...@gmail.com>
Authored: Thu Nov 3 09:24:36 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 traffic_monitor/experimental/traffic_monitor/enum/enum.go | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/3a73422b/traffic_monitor/experimental/traffic_monitor/enum/enum.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/enum/enum.go b/traffic_monitor/experimental/traffic_monitor/enum/enum.go
index c8389b9..05be348 100644
--- a/traffic_monitor/experimental/traffic_monitor/enum/enum.go
+++ b/traffic_monitor/experimental/traffic_monitor/enum/enum.go
@@ -38,7 +38,7 @@ func (t CacheType) String() string {
 	case CacheTypeMid:
 		return "MID"
 	default:
-		return "INVALID"
+		return "INVALIDCACHETYPE"
 	}
 }
 
@@ -75,7 +75,7 @@ func (t DSType) String() string {
 	case DSTypeDNS:
 		return "DNS"
 	default:
-		return "INVALID"
+		return "INVALIDDSTYPE"
 	}
 }
 
@@ -120,7 +120,7 @@ func (t CacheStatus) String() string {
 	case CacheStatusReported:
 		return string(t)
 	default:
-		return "INVALID"
+		return "INVALIDCACHESTATUS"
 	}
 }
 


[08/21] incubator-trafficcontrol git commit: Fix TM2 kbps threshold to subtract from capacity

Posted by ne...@apache.org.
Fix TM2 kbps threshold to subtract from capacity

Fixes Traffic Monitor 2.0's available bandwidth threshold to subtract
the parameter value from the capacity. It was incorrectly comparing
the value itself.


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

Branch: refs/heads/master
Commit: b29a5d5a8a908856c7498c2762e42142f8c4cabf
Parents: cc2eae5
Author: Robert Butts <ro...@gmail.com>
Authored: Mon Oct 31 10:28:39 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 7 12:29:08 2016 -0700

----------------------------------------------------------------------
 .../experimental/traffic_monitor/health/cache_health.go       | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/b29a5d5a/traffic_monitor/experimental/traffic_monitor/health/cache_health.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/health/cache_health.go b/traffic_monitor/experimental/traffic_monitor/health/cache_health.go
index 1106f62..d4c7639 100644
--- a/traffic_monitor/experimental/traffic_monitor/health/cache_health.go
+++ b/traffic_monitor/experimental/traffic_monitor/health/cache_health.go
@@ -98,6 +98,11 @@ func getQueryThreshold(threshInt int64) time.Duration {
 	return time.Duration(threshInt) * time.Millisecond
 }
 
+func cacheCapacityKbps(result cache.Result) int64 {
+	kbpsInMbps := int64(1000)
+	return int64(result.Astats.System.InfSpeed) * kbpsInMbps
+}
+
 // EvalCache returns whether the given cache should be marked available, and a string describing why
 func EvalCache(result cache.Result, mc *traffic_ops.TrafficMonitorConfigMap) (bool, string) {
 	toServer := mc.TrafficServer[string(result.ID)]
@@ -114,7 +119,7 @@ func EvalCache(result cache.Result, mc *traffic_ops.TrafficMonitorConfigMap) (bo
 		return false, fmt.Sprintf("error: %v", result.Error)
 	case result.Vitals.LoadAvg > params.HealthThresholdLoadAvg:
 		return false, fmt.Sprintf("load average %f exceeds threshold %f", result.Vitals.LoadAvg, params.HealthThresholdLoadAvg)
-	case result.Vitals.KbpsOut >= getKbpsThreshold(params.HealthThresholdAvailableBandwidthInKbps):
+	case result.Vitals.KbpsOut > cacheCapacityKbps(result)-getKbpsThreshold(params.HealthThresholdAvailableBandwidthInKbps):
 		return false, fmt.Sprintf("%dkbps exceeds max %dkbps", result.Vitals.KbpsOut, getKbpsThreshold(params.HealthThresholdAvailableBandwidthInKbps))
 	case result.RequestTime > getQueryThreshold(int64(params.HealthThresholdQueryTime)):
 		return false, fmt.Sprintf("request time %v exceeds max %v", result.RequestTime, getQueryThreshold(int64(params.HealthThresholdQueryTime)))