This is an automated email from the ASF dual-hosted git repository.

rawlin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 14e07d7  Fix TM panic on startup (#4813)
14e07d7 is described below

commit 14e07d7f4928cc3ad110ec7b7de69582fc61c87b
Author: Steve Hamrick <[email protected]>
AuthorDate: Tue Jun 23 10:33:29 2020 -0600

    Fix TM panic on startup (#4813)
    
    * Fix panic and add test
    
    * Add comment
---
 traffic_monitor/health/cache.go      | 8 ++++----
 traffic_monitor/health/cache_test.go | 7 +++++++
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/traffic_monitor/health/cache.go b/traffic_monitor/health/cache.go
index 830818c..d713023 100644
--- a/traffic_monitor/health/cache.go
+++ b/traffic_monitor/health/cache.go
@@ -188,6 +188,10 @@ func CalcAvailability(results []cache.Result, pollerName 
string, statResultHisto
                        log.Errorf("Cache %v missing from from Traffic Ops 
Monitor Config - treating as OFFLINE\n", result.ID)
                }
 
+               if _, ok := localCacheStatuses[tc.CacheName(result.ID)]; !ok {
+                       localCacheStatuses[tc.CacheName(result.ID)] = 
make(map[string]cache.AvailableStatus)
+               }
+
                resultInfo := cache.ToInfo(result)
                for interfaceName, _ := range result.Interfaces() {
                        if statResultsVal != nil {
@@ -225,10 +229,6 @@ func CalcAvailability(results []cache.Result, pollerName 
string, statResultHisto
 
                        newAvailableState := 
processAvailableTuple(availableTuple, serverInfo)
 
-                       if _, ok := 
localCacheStatuses[tc.CacheName(result.ID)]; !ok {
-                               localCacheStatuses[tc.CacheName(result.ID)] = 
make(map[string]cache.AvailableStatus)
-                       }
-
                        
localCacheStatuses[tc.CacheName(result.ID)][interfaceName] = 
cache.AvailableStatus{
                                Available:          availableTuple,
                                ProcessedAvailable: newAvailableState,
diff --git a/traffic_monitor/health/cache_test.go 
b/traffic_monitor/health/cache_test.go
index 4451e69..c32574d 100644
--- a/traffic_monitor/health/cache_test.go
+++ b/traffic_monitor/health/cache_test.go
@@ -116,6 +116,13 @@ func TestCalcAvailabilityThresholds(t *testing.T) {
 
        pollerName := "stat"
        results := []cache.Result{result}
+
+       // Ensure that if the interfaces haven't been reported yet that 
CalcAvailability doesn't panic
+       original := results[0].Statistics.Interfaces
+       results[0].Statistics.Interfaces = make(map[string]cache.Interface)
+       CalcAvailability(results, pollerName, statResultHistory, mc, toData, 
localCacheStatusThreadsafe, localStates, events, config.Both)
+       results[0].Statistics.Interfaces = original
+
        CalcAvailability(results, pollerName, statResultHistory, mc, toData, 
localCacheStatusThreadsafe, localStates, events, config.Both)
 
        localCacheStatuses := localCacheStatusThreadsafe.Get()

Reply via email to