Skip to content

Commit

Permalink
Merge pull request #561 from mreiferson/panic_561
Browse files Browse the repository at this point in the history
quantile: nil deref
  • Loading branch information
jehiah committed Mar 24, 2015
2 parents 48bb782 + 10a396a commit 7085a8f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
12 changes: 8 additions & 4 deletions internal/lookupd/types.go
Expand Up @@ -60,7 +60,6 @@ type TopicStats struct {
Paused bool

E2eProcessingLatency *quantile.E2eProcessingLatencyAggregate
numAggregates int
}

func (t *TopicStats) Add(a *TopicStats) {
Expand All @@ -76,8 +75,10 @@ func (t *TopicStats) Add(a *TopicStats) {
if a.Paused {
t.Paused = a.Paused
}
t.numAggregates++
t.E2eProcessingLatency = t.E2eProcessingLatency.Add(a.E2eProcessingLatency, t.numAggregates)
if t.E2eProcessingLatency == nil {
t.E2eProcessingLatency = &quantile.E2eProcessingLatencyAggregate{}
}
t.E2eProcessingLatency.Add(a.E2eProcessingLatency)
}

func (t *TopicStats) Target(key string) ([]string, string) {
Expand Down Expand Up @@ -132,7 +133,10 @@ func (c *ChannelStats) Add(a *ChannelStats) {
c.Paused = a.Paused
}
c.HostStats = append(c.HostStats, a)
c.E2eProcessingLatency = c.E2eProcessingLatency.Add(a.E2eProcessingLatency, len(c.HostStats))
if c.E2eProcessingLatency == nil {
c.E2eProcessingLatency = &quantile.E2eProcessingLatencyAggregate{}
}
c.E2eProcessingLatency.Add(a.E2eProcessingLatency)
sort.Sort(ChannelStatsByHost{c.HostStats})
}

Expand Down
52 changes: 24 additions & 28 deletions internal/quantile/aggregate.go
Expand Up @@ -74,36 +74,32 @@ func (e *E2eProcessingLatencyAggregate) Less(i, j int) bool {
return e.Percentiles[i]["percentile"] > e.Percentiles[j]["percentile"]
}

func (e *E2eProcessingLatencyAggregate) Add(e2 *E2eProcessingLatencyAggregate, N int) *E2eProcessingLatencyAggregate {
if e == nil {
*e = *e2
} else {
p := e.Percentiles
e.Count += e2.Count
for _, value := range e2.Percentiles {
i := -1
for j, v := range p {
if value["quantile"] == v["quantile"] {
i = j
break
}
}
if i == -1 {
i = len(p)
e.Percentiles = append(p, make(map[string]float64))
p = e.Percentiles
p[i]["quantile"] = value["quantile"]
// Add merges e2 into e by averaging the percentiles
func (e *E2eProcessingLatencyAggregate) Add(e2 *E2eProcessingLatencyAggregate) {
e.Addr = "*"
p := e.Percentiles
e.Count += e2.Count
for _, value := range e2.Percentiles {
i := -1
for j, v := range p {
if value["quantile"] == v["quantile"] {
i = j
break
}
p[i]["max"] = math.Max(value["max"], p[i]["max"])
p[i]["min"] = math.Min(value["max"], p[i]["max"])

p[i]["count"] += value["count"]
delta := value["average"] - p[i]["average"]
R := delta * value["count"] / p[i]["count"]
p[i]["average"] = p[i]["average"] + R
}
if i == -1 {
i = len(p)
e.Percentiles = append(p, make(map[string]float64))
p = e.Percentiles
p[i]["quantile"] = value["quantile"]
}
p[i]["max"] = math.Max(value["max"], p[i]["max"])
p[i]["min"] = math.Min(value["max"], p[i]["max"])

p[i]["count"] += value["count"]
delta := value["average"] - p[i]["average"]
R := delta * value["count"] / p[i]["count"]
p[i]["average"] = p[i]["average"] + R
}
sort.Sort(e)
e.Addr = "*"
return e
}

0 comments on commit 7085a8f

Please sign in to comment.