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/12/08 18:46:07 UTC

[05/20] incubator-trafficcontrol git commit: Fix statHistory to be newest-first

Fix statHistory to be newest-first

Fixes statHistory to be newest-first, and fixes readers to expect the
same. It was oldest-first, with inconsistent reader expectations.

Fixes total bandwidth to include mids, which appears to match TM 1.0.

Fixes a result error check to check the real Error, instead of
PrecomputedData's Errors, and fixes the Result PrecomptuedData
member to not be anonymous, requiring explicit access, to prevent
this kind of accident again.

Fixes srvhttp to include the proper content type header for files.


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

Branch: refs/heads/master
Commit: 12f48d327e41bc4273be6c392c6d2399d545d55e
Parents: f25489d
Author: Robert Butts <ro...@gmail.com>
Authored: Mon Nov 21 10:41:30 2016 -0700
Committer: Dave Neuman <ne...@apache.org>
Committed: Thu Dec 8 11:44:33 2016 -0700

----------------------------------------------------------------------
 .../experimental/traffic_monitor/cache/cache.go | 25 ++++++++++----------
 .../traffic_monitor/deliveryservice/stat.go     |  7 +++---
 .../traffic_monitor/manager/datarequest.go      | 17 +++++++------
 .../traffic_monitor/manager/polledcaches.go     |  8 +++----
 .../traffic_monitor/manager/stathistory.go      |  9 ++++---
 .../traffic_monitor/srvhttp/srvhttp.go          | 11 +++++----
 6 files changed, 37 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/12f48d32/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 bcc3449..8d973d5 100644
--- a/traffic_monitor/experimental/traffic_monitor/cache/cache.go
+++ b/traffic_monitor/experimental/traffic_monitor/cache/cache.go
@@ -8,9 +8,9 @@ package cache
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,7 +19,6 @@ package cache
  * under the License.
  */
 
-
 import (
 	"encoding/json"
 	"fmt"
@@ -73,16 +72,16 @@ type PrecomputedData struct {
 
 // Result is the data result returned by a cache.
 type Result struct {
-	ID           enum.CacheName
-	Error        error
-	Astats       Astats
-	Time         time.Time
-	RequestTime  time.Duration
-	Vitals       Vitals
-	PollID       uint64
-	PollFinished chan<- uint64
-	PrecomputedData
-	Available bool
+	ID              enum.CacheName
+	Error           error
+	Astats          Astats
+	Time            time.Time
+	RequestTime     time.Duration
+	Vitals          Vitals
+	PollID          uint64
+	PollFinished    chan<- uint64
+	PrecomputedData PrecomputedData
+	Available       bool
 }
 
 // Vitals is the vitals data returned from a cache.

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/12f48d32/traffic_monitor/experimental/traffic_monitor/deliveryservice/stat.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/deliveryservice/stat.go b/traffic_monitor/experimental/traffic_monitor/deliveryservice/stat.go
index ebd883f..d47350e 100644
--- a/traffic_monitor/experimental/traffic_monitor/deliveryservice/stat.go
+++ b/traffic_monitor/experimental/traffic_monitor/deliveryservice/stat.go
@@ -8,9 +8,9 @@ package deliveryservice
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,7 +19,6 @@ package deliveryservice
  * under the License.
  */
 
-
 import (
 	"fmt"
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/common/log"
@@ -437,7 +436,7 @@ func CreateStats(statHistory map[enum.CacheName][]cache.Result, toData todata.TO
 			log.Warnf("server %s not in CRConfig, skipping\n", server)
 			continue
 		}
-		result := history[len(history)-1]
+		result := history[0]
 
 		// TODO check result.PrecomputedData.Errors
 		for ds, resultStat := range result.PrecomputedData.DeliveryServiceStats {

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/12f48d32/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 750264a..f4e993f 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go
@@ -8,9 +8,9 @@ package manager
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,7 +19,6 @@ package manager
  * under the License.
  */
 
-
 import (
 	"encoding/json"
 	"fmt"
@@ -611,13 +610,13 @@ func srvAPICacheStates(toData todata.TODataThreadsafe, statHistory StatHistoryTh
 }
 
 func srvAPIBandwidthKbps(toData todata.TODataThreadsafe, lastStats LastStatsThreadsafe) []byte {
-	serverTypes := toData.Get().ServerTypes
+	// serverTypes := toData.Get().ServerTypes
 	kbpsStats := lastStats.Get()
 	sum := float64(0.0)
-	for cache, data := range kbpsStats.Caches {
-		if serverTypes[cache] != enum.CacheTypeEdge {
-			continue
-		}
+	for _, data := range kbpsStats.Caches {
+		// if serverTypes[cache] != enum.CacheTypeEdge {
+		// 	continue
+		// }
 		sum += data.Bytes.PerSec / ds.BytesPerKilobit
 	}
 	return []byte(fmt.Sprintf("%f", sum))
@@ -629,7 +628,7 @@ func srvAPIBandwidthCapacityKbps(statHistoryThs StatHistoryThreadsafe) []byte {
 		if len(results) == 0 {
 			continue
 		}
-		cap += results[0].MaxKbps
+		cap += results[0].PrecomputedData.MaxKbps
 	}
 	return []byte(fmt.Sprintf("%d", cap))
 }

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/12f48d32/traffic_monitor/experimental/traffic_monitor/manager/polledcaches.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/manager/polledcaches.go b/traffic_monitor/experimental/traffic_monitor/manager/polledcaches.go
index 3f353c4..6613a04 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/polledcaches.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/polledcaches.go
@@ -8,9 +8,9 @@ package manager
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,7 +19,6 @@ package manager
  * under the License.
  */
 
-
 import (
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/common/log"
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/cache"
@@ -118,7 +117,8 @@ func (t *UnpolledCachesThreadsafe) SetPolled(results []cache.Result, lastStatsTh
 			if result.ID != cache {
 				continue
 			}
-			if !result.Available || len(result.Errors) > 0 {
+
+			if !result.Available || result.Error != nil {
 				log.Infof("polled %v\n", cache)
 				delete(unpolledCaches, cache)
 				break innerLoop

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/12f48d32/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 c938974..57c942b 100644
--- a/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go
+++ b/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go
@@ -8,9 +8,9 @@ package manager
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,7 +19,6 @@ package manager
  * under the License.
  */
 
-
 import (
 	"sync"
 	"time"
@@ -82,7 +81,7 @@ func (h *StatHistoryThreadsafe) Set(v StatHistory) {
 
 func pruneHistory(history []cache.Result, limit uint64) []cache.Result {
 	if uint64(len(history)) > limit {
-		history = history[1:]
+		history = history[:limit-1]
 	}
 	return history
 }
@@ -172,7 +171,7 @@ func processStatResults(
 	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)
+		statHistory[result.ID] = pruneHistory(append([]cache.Result{result}, statHistory[result.ID]...), maxStats)
 	}
 	statHistoryThreadsafe.Set(statHistory)
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/12f48d32/traffic_monitor/experimental/traffic_monitor/srvhttp/srvhttp.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/traffic_monitor/srvhttp/srvhttp.go b/traffic_monitor/experimental/traffic_monitor/srvhttp/srvhttp.go
index 84fdf78..0b9e261 100644
--- a/traffic_monitor/experimental/traffic_monitor/srvhttp/srvhttp.go
+++ b/traffic_monitor/experimental/traffic_monitor/srvhttp/srvhttp.go
@@ -8,9 +8,9 @@ package srvhttp
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,7 +19,6 @@ package srvhttp
  * under the License.
  */
 
-
 import (
 	"fmt"
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/common/log"
@@ -149,11 +148,13 @@ func (s Server) handleSortableFunc() (http.HandlerFunc, error) {
 }
 
 func (s Server) handleFile(name string) (http.HandlerFunc, error) {
-	index, err := ioutil.ReadFile(name)
+	bytes, err := ioutil.ReadFile(name)
 	if err != nil {
 		return nil, err
 	}
+	contentType := http.DetectContentType(bytes)
 	return func(w http.ResponseWriter, req *http.Request) {
-		fmt.Fprintf(w, "%s", index)
+		w.Header().Set("Content-Type", contentType)
+		fmt.Fprintf(w, "%s", bytes)
 	}, nil
 }