You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ne...@apache.org on 2017/08/01 19:17:29 UTC
[1/2] incubator-trafficcontrol git commit: Fix TM2 crashing with
malformed astats
Repository: incubator-trafficcontrol
Updated Branches:
refs/heads/master 770266486 -> 68ce4a2a3
Fix TM2 crashing with malformed astats
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/d97c1547
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/d97c1547
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/d97c1547
Branch: refs/heads/master
Commit: d97c1547beec4e4a23e3514330532ab55ad6bc73
Parents: 7702664
Author: Robert Butts <ro...@gmail.com>
Authored: Mon Jul 31 08:10:42 2017 -0600
Committer: David Neuman <da...@gmail.com>
Committed: Tue Aug 1 13:16:51 2017 -0600
----------------------------------------------------------------------
.../traffic_monitor/cache/data.go | 35 ++++++++++++++++++--
.../traffic_monitor/manager/stat.go | 4 ++-
2 files changed, 36 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d97c1547/traffic_monitor_golang/traffic_monitor/cache/data.go
----------------------------------------------------------------------
diff --git a/traffic_monitor_golang/traffic_monitor/cache/data.go b/traffic_monitor_golang/traffic_monitor/cache/data.go
index 746d828..6067767 100644
--- a/traffic_monitor_golang/traffic_monitor/cache/data.go
+++ b/traffic_monitor_golang/traffic_monitor/cache/data.go
@@ -21,6 +21,7 @@ package cache
import (
"encoding/json"
+ "errors"
"fmt"
"time"
@@ -128,11 +129,36 @@ func pruneStats(history []ResultStatVal, limit uint64) []ResultStatVal {
return history
}
-func (a ResultStatHistory) Add(r Result, limit uint64) {
+// newStatEqual Returns whether the given stat is equal to the latest stat in history. If len(history)==0, this returns false without error. If the given stat is not a JSON primitive (string, number, bool), this returns an error. We explicitly refuse to compare arrays and objects, for performance.
+func newStatEqual(history []ResultStatVal, stat interface{}) (bool, error) {
+ if len(history) == 0 {
+ return false, nil // if there's no history, it's "not equal", i.e. store this new history
+ }
+ switch stat.(type) {
+ case string:
+ case float64:
+ case bool:
+ default:
+ return false, fmt.Errorf("incomparable stat type %T", stat)
+ }
+ switch history[0].Val.(type) {
+ case string:
+ case float64:
+ case bool:
+ default:
+ return false, fmt.Errorf("incomparable history stat type %T", stat)
+ }
+ return stat == history[0].Val, nil
+}
+
+func (a ResultStatHistory) Add(r Result, limit uint64) error {
+ errStrs := ""
for statName, statVal := range r.Astats.Ats {
statHistory := a[r.ID][statName]
// If the new stat value is the same as the last, update the time and increment the span. Span is the number of polls the latest value has been the same, and hence the length of time it's been the same is span*pollInterval.
- if len(statHistory) > 0 && statHistory[0].Val == statVal {
+ if ok, err := newStatEqual(statHistory, statVal); err != nil {
+ errStrs += "cannot add stat " + statName + ": " + err.Error() + "; "
+ } else if ok {
statHistory[0].Time = r.Time
statHistory[0].Span++
} else {
@@ -148,6 +174,11 @@ func (a ResultStatHistory) Add(r Result, limit uint64) {
}
a[r.ID][statName] = statHistory // TODO determine if necessary for the first conditional
}
+
+ if errStrs != "" {
+ return errors.New("some stats could not be added: " + errStrs[:len(errStrs)-2])
+ }
+ return nil
}
// TODO determine if anything ever needs more than the latest, and if not, change ResultInfo to not be a slice.
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/d97c1547/traffic_monitor_golang/traffic_monitor/manager/stat.go
----------------------------------------------------------------------
diff --git a/traffic_monitor_golang/traffic_monitor/manager/stat.go b/traffic_monitor_golang/traffic_monitor/manager/stat.go
index 6c000d5..6280e67 100644
--- a/traffic_monitor_golang/traffic_monitor/manager/stat.go
+++ b/traffic_monitor_golang/traffic_monitor/manager/stat.go
@@ -180,7 +180,9 @@ func processStatResults(
}
}
statInfoHistory.Add(result, maxStats)
- statResultHistory.Add(result, maxStats)
+ if err := statResultHistory.Add(result, maxStats); err != nil {
+ log.Errorf("Adding result from %v: %v\n", result.ID, err)
+ }
// Don't add errored maxes or precomputed DSStats
if result.Error == nil {
// max and precomputed always contain the latest result from each cache
[2/2] incubator-trafficcontrol git commit: This closes #769
Posted by ne...@apache.org.
This closes #769
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/68ce4a2a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/68ce4a2a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/68ce4a2a
Branch: refs/heads/master
Commit: 68ce4a2a3fd814e1074ac1d2ade46a8cc3635379
Parents: d97c154
Author: David Neuman <da...@gmail.com>
Authored: Tue Aug 1 13:17:06 2017 -0600
Committer: David Neuman <da...@gmail.com>
Committed: Tue Aug 1 13:17:06 2017 -0600
----------------------------------------------------------------------
----------------------------------------------------------------------