-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathinterval_aggregation_merge.go
72 lines (62 loc) · 1.85 KB
/
interval_aggregation_merge.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package health
// Merge merges intAgg into ia, mutating ia.
// Requires that ia and intAgg are a fully valid with no nil maps.
func (ia *IntervalAggregation) Merge(intAgg *IntervalAggregation) {
ia.aggregationMaps.merge(&intAgg.aggregationMaps)
for k, v := range intAgg.Jobs {
if existingJob, ok := ia.Jobs[k]; ok {
existingJob.merge(v)
} else {
ia.Jobs[k] = v.Clone()
}
}
ia.SerialNumber++
}
func (intoJob *JobAggregation) merge(fromJob *JobAggregation) {
intoJob.aggregationMaps.merge(&fromJob.aggregationMaps)
intoJob.TimerAggregation.merge(&fromJob.TimerAggregation)
intoJob.CountSuccess += fromJob.CountSuccess
intoJob.CountValidationError += fromJob.CountValidationError
intoJob.CountPanic += fromJob.CountPanic
intoJob.CountError += fromJob.CountError
intoJob.CountJunk += fromJob.CountJunk
}
func (intoTa *TimerAggregation) merge(fromTa *TimerAggregation) {
intoTa.Count += fromTa.Count
intoTa.NanosSum += fromTa.NanosSum
intoTa.NanosSumSquares += fromTa.NanosSumSquares
if fromTa.NanosMin < intoTa.NanosMin {
intoTa.NanosMin = fromTa.NanosMin
}
if fromTa.NanosMax > intoTa.NanosMax {
intoTa.NanosMax = fromTa.NanosMax
}
}
func (intoAm *aggregationMaps) merge(fromAm *aggregationMaps) {
for k, v := range fromAm.Events {
intoAm.Events[k] += v
}
for k, v := range fromAm.Gauges {
intoAm.Gauges[k] = v
}
for k, v := range fromAm.Timers {
if existingTimer, ok := intoAm.Timers[k]; ok {
existingTimer.merge(v)
} else {
intoAm.Timers[k] = v.Clone()
}
}
for k, v := range fromAm.EventErrs {
if existingErrCounter, ok := intoAm.EventErrs[k]; ok {
existingErrCounter.Count += v.Count
// merging two ring buffers given our shitty implementation is problematic.
for _, err := range v.errorSamples {
if err != nil {
existingErrCounter.addError(err)
}
}
} else {
intoAm.EventErrs[k] = v.Clone()
}
}
}