Add TM2 availability poller to /api/cache-statuses

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

Branch: refs/heads/master
Commit: 34863edd4108b96dae4d1fd26d16d19fd033ca1b
Parents: 40d5bcb
Author: Robert Butts <robert.o.bu...@gmail.com>
Authored: Fri Jan 20 16:00:54 2017 -0700
Committer: Dave Neuman <neu...@apache.org>
Committed: Wed Jan 25 10:29:46 2017 -0700

----------------------------------------------------------------------
 .../experimental/traffic_monitor/cache/cache.go        | 12 ++++++++++++
 .../experimental/traffic_monitor/cache/data.go         |  2 ++
 .../traffic_monitor/manager/datarequest.go             | 10 +++++++---
 .../traffic_monitor/manager/healthresult.go            | 13 -------------
 .../traffic_monitor/manager/stathistory.go             |  8 ++++----
 5 files changed, 25 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/34863edd/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 541edaa..95aab84 100644
--- a/traffic_monitor/experimental/traffic_monitor/cache/cache.go
+++ b/traffic_monitor/experimental/traffic_monitor/cache/cache.go
@@ -87,6 +87,18 @@ type Result struct {
        Available       bool
 }
 
+// HasStat returns whether the given stat is in the Result.
+func (result *Result) HasStat(stat string) bool {
+       computedStats := ComputedStats()
+       if _, ok := computedStats[stat]; ok {
+               return true // health poll has all computed stats
+       }
+       if _, ok := result.Astats.Ats[stat]; ok {
+               return true
+       }
+       return false
+}
+
 // Vitals is the vitals data returned from a cache.
 type Vitals struct {
        LoadAvg    float64

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/34863edd/traffic_monitor/experimental/traffic_monitor/cache/data.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/cache/data.go 
b/traffic_monitor/experimental/traffic_monitor/cache/data.go
index ee21907..bad75a0 100644
--- a/traffic_monitor/experimental/traffic_monitor/cache/data.go
+++ b/traffic_monitor/experimental/traffic_monitor/cache/data.go
@@ -38,6 +38,8 @@ type AvailableStatus struct {
        Why       string
        // UnavailableStat is the stat whose threshold made the cache 
unavailable. If this is the empty string, the cache is unavailable for a 
non-threshold reason. This exists so a poller (health, stat) won't mark an 
unavailable cache as available if the stat whose threshold was reached isn't 
available on that poller.
        UnavailableStat string
+       // Poller is the name of the poller which set this available status
+       Poller string
 }
 
 // CacheAvailableStatuses is the available status of each cache.

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/34863edd/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 2f42d74..2dffb41 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
@@ -63,9 +63,10 @@ type APIPeerStates struct {
 // CacheStatus contains summary stat data about the given cache.
 // TODO make fields nullable, so error fields can be omitted, letting API 
callers still get updates for unerrored fields
 type CacheStatus struct {
-       Type        *string  `json:"type,omitempty"`
-       Status      *string  `json:"status,omitempty"`
-       LoadAverage *float64 `json:"load_average,omitempty"`
+       Type         *string  `json:"type,omitempty"`
+       Status       *string  `json:"status,omitempty"`
+       StatusPoller *string  `json:"status_poller,omitempty"`
+       LoadAverage  *float64 `json:"load_average,omitempty"`
        // QueryTimeMilliseconds is the time it took this app to perform a 
complete query and process the data, end-to-end, for the latest health query.
        QueryTimeMilliseconds *int64 `json:"query_time_ms,omitempty"`
        // HealthTimeMilliseconds is the time it took to make the HTTP request 
and get back the full response, for the latest health query.
@@ -971,6 +972,7 @@ func createCacheStatuses(
                }
 
                var status *string
+               var statusPoller *string
                statusVal, ok := localCacheStatus[cacheName]
                if !ok {
                        log.Warnf("cache not in statuses %s\n", cacheName)
@@ -987,6 +989,7 @@ func createCacheStatuses(
                        }
 
                        status = &statusString
+                       statusPoller = &statusVal.Poller
                }
 
                cacheTypeStr := string(cacheType)
@@ -1002,6 +1005,7 @@ func createCacheStatuses(
                        BandwidthCapacityKbps:  maxKbps,
                        ConnectionCount:        connections,
                        Status:                 status,
+                       StatusPoller:           statusPoller,
                }
        }
        return statii

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/34863edd/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 110f083..63248e8 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go
@@ -245,19 +245,6 @@ func processHealthResult(
        lastHealthDurationsThreadsafe.Set(lastHealthDurations)
 }
 
-// resultHasStat returns whether the given stat is in the Result.
-// TODO move to cache?
-func resultHasStat(stat string, result cache.Result) bool {
-       computedStats := cache.ComputedStats()
-       if _, ok := computedStats[stat]; ok {
-               return true // health poll has all computed stats
-       }
-       if _, ok := result.Astats.Ats[stat]; ok {
-               return true
-       }
-       return false
-}
-
 // calculateDeliveryServiceState calculates the state of delivery services 
from the new cache state data `cacheState` and the CRConfig data 
`deliveryServiceServers` and puts the calculated state in the outparam 
`deliveryServiceStates`
 func CalculateDeliveryServiceState(deliveryServiceServers 
map[enum.DeliveryServiceName][]enum.CacheName, states peer.CRStatesThreadsafe) {
        deliveryServices := states.GetDeliveryServices()

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/34863edd/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 b44f357..c63584e 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go
@@ -238,11 +238,10 @@ func calcAvailability(results []cache.Result, pollerName 
string, statResultHisto
                }
 
                isAvailable, whyAvailable, unavailableStat := 
health.EvalCache(cache.ToInfo(result), statResults, &mc)
-               whyAvailable += " (" + pollerName + ")" // TODO move to field 
in AvailableStatus
 
                // if the cache is now Available, and was previously 
unavailable due to a threshold, make sure this poller contains the stat which 
exceeded the threshold.
                if previousStatus, hasPreviousStatus := 
localCacheStatuses[result.ID]; isAvailable && hasPreviousStatus && 
!previousStatus.Available && previousStatus.UnavailableStat != "" {
-                       if !resultHasStat(previousStatus.UnavailableStat, 
result) {
+                       if !result.HasStat(previousStatus.UnavailableStat) {
                                return
                        }
                }
@@ -251,11 +250,12 @@ func calcAvailability(results []cache.Result, pollerName 
string, statResultHisto
                        Status:          
mc.TrafficServer[string(result.ID)].Status,
                        Why:             whyAvailable,
                        UnavailableStat: unavailableStat,
+                       Poller:          pollerName,
                } // TODO move within localStates?
 
                if available, ok := localStates.GetCache(result.ID); !ok || 
available.IsAvailable != isAvailable {
-                       log.Infof("Changing state for %s was: %t now: %t 
because %s error: %v", result.ID, available.IsAvailable, isAvailable, 
whyAvailable, result.Error)
-                       events.Add(cache.Event{Time: time.Now().Unix(), 
Description: whyAvailable, Name: result.ID, Hostname: result.ID, Type: 
toData.ServerTypes[result.ID].String(), Available: isAvailable})
+                       log.Infof("Changing state for %s was: %t now: %t 
because %s poller: %v error: %v", result.ID, available.IsAvailable, 
isAvailable, whyAvailable, pollerName, result.Error)
+                       events.Add(cache.Event{Time: time.Now().Unix(), 
Description: whyAvailable + " (" + pollerName + ")", Name: result.ID, Hostname: 
result.ID, Type: toData.ServerTypes[result.ID].String(), Available: 
isAvailable})
                }
 
                localStates.SetCache(result.ID, peer.IsAvailable{IsAvailable: 
isAvailable})

Reply via email to